MCPcopy Create free account
hub / github.com/F-Stack/f-stack / faultin

Function faultin

freebsd/vm/vm_swapout.c:591–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591void
592faultin(struct proc *p)
593{
594 struct thread *td;
595 int oom_alloc;
596
597 PROC_LOCK_ASSERT(p, MA_OWNED);
598
599 /*
600 * If another process is swapping in this process,
601 * just wait until it finishes.
602 */
603 if (p->p_flag & P_SWAPPINGIN) {
604 while (p->p_flag & P_SWAPPINGIN)
605 msleep(&p->p_flag, &p->p_mtx, PVM, "faultin", 0);
606 return;
607 }
608
609 if ((p->p_flag & P_INMEM) == 0) {
610 oom_alloc = (p->p_flag & P_WKILLED) != 0 ? VM_ALLOC_SYSTEM :
611 VM_ALLOC_NORMAL;
612
613 /*
614 * Don't let another thread swap process p out while we are
615 * busy swapping it in.
616 */
617 ++p->p_lock;
618 p->p_flag |= P_SWAPPINGIN;
619 PROC_UNLOCK(p);
620 sx_xlock(&allproc_lock);
621 MPASS(swapped_cnt > 0);
622 swapped_cnt--;
623 if (curthread != &thread0)
624 swap_inprogress++;
625 sx_xunlock(&allproc_lock);
626
627 /*
628 * We hold no lock here because the list of threads
629 * can not change while all threads in the process are
630 * swapped out.
631 */
632 FOREACH_THREAD_IN_PROC(p, td)
633 vm_thread_swapin(td, oom_alloc);
634
635 if (curthread != &thread0) {
636 sx_xlock(&allproc_lock);
637 MPASS(swap_inprogress > 0);
638 swap_inprogress--;
639 last_swapin = ticks;
640 sx_xunlock(&allproc_lock);
641 }
642 PROC_LOCK(p);
643 swapclear(p);
644 p->p_swtick = ticks;
645
646 /* Allow other threads to swap p out now. */
647 wakeup(&p->p_flag);
648 --p->p_lock;

Callers 1

swapperFunction · 0.70

Calls 3

vm_thread_swapinFunction · 0.85
swapclearFunction · 0.85
wakeupFunction · 0.50

Tested by

no test coverage detected