2 * SPDX-License-Identifier: (BSD-4-Clause AND MIT-CMU)
4 * Copyright (c) 1991 Regents of the University of California.
6 * Copyright (c) 1994 John S. Dyson
8 * Copyright (c) 1994 David Greenman
10 * Copyright (c) 2005 Yahoo! Technologies Norway AS
11 * All rights reserved.
13 * This code is derived from software contributed to Berkeley by
14 * The Mach Operating System project at Carnegie-Mellon University.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * from: @(#)vm_pageout.c 7.4 (Berkeley) 5/7/91
47 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
48 * All rights reserved.
50 * Authors: Avadis Tevanian, Jr., Michael Wayne Young
52 * Permission to use, copy, modify and distribute this software and
53 * its documentation is hereby granted, provided that both the copyright
54 * notice and this permission notice appear in all copies of the
55 * software, derivative works or modified versions, and any portions
56 * thereof, and that both notices appear in supporting documentation.
58 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
59 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
60 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
62 * Carnegie Mellon requests users of this software to return to
64 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
65 * School of Computer Science
66 * Carnegie Mellon University
67 * Pittsburgh PA 15213-3890
69 * any improvements or extensions that they make and grant Carnegie the
70 * rights to redistribute these changes.
73 #include <sys/cdefs.h>
74 __FBSDID("$FreeBSD$");
76 #include "opt_kstack_pages.h"
77 #include "opt_kstack_max_pages.h"
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/limits.h>
83 #include <sys/kernel.h>
84 #include <sys/eventhandler.h>
86 #include <sys/mutex.h>
88 #include <sys/kthread.h>
90 #include <sys/mount.h>
91 #include <sys/racct.h>
92 #include <sys/resourcevar.h>
93 #include <sys/sched.h>
95 #include <sys/signalvar.h>
98 #include <sys/vnode.h>
99 #include <sys/vmmeter.h>
100 #include <sys/rwlock.h>
102 #include <sys/sysctl.h>
105 #include <vm/vm_param.h>
106 #include <vm/vm_object.h>
107 #include <vm/vm_page.h>
108 #include <vm/vm_map.h>
109 #include <vm/vm_pageout.h>
110 #include <vm/vm_pager.h>
111 #include <vm/vm_phys.h>
112 #include <vm/swap_pager.h>
113 #include <vm/vm_extern.h>
116 /* the kernel process "vm_daemon" */
117 static void vm_daemon(void);
118 static struct proc *vmproc;
120 static struct kproc_desc vm_kp = {
125 SYSINIT(vmdaemon, SI_SUB_KTHREAD_VM, SI_ORDER_FIRST, kproc_start, &vm_kp);
127 static int vm_swap_enabled = 1;
128 static int vm_swap_idle_enabled = 0;
130 SYSCTL_INT(_vm, VM_SWAPPING_ENABLED, swap_enabled, CTLFLAG_RW,
132 "Enable entire process swapout");
133 SYSCTL_INT(_vm, OID_AUTO, swap_idle_enabled, CTLFLAG_RW,
134 &vm_swap_idle_enabled, 0,
135 "Allow swapout on idle criteria");
138 * Swap_idle_threshold1 is the guaranteed swapped in time for a process
140 static int swap_idle_threshold1 = 2;
141 SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold1, CTLFLAG_RW,
142 &swap_idle_threshold1, 0,
143 "Guaranteed swapped in time for a process");
146 * Swap_idle_threshold2 is the time that a process can be idle before
147 * it will be swapped out, if idle swapping is enabled.
149 static int swap_idle_threshold2 = 10;
150 SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold2, CTLFLAG_RW,
151 &swap_idle_threshold2, 0,
152 "Time before a process will be swapped out");
154 static int vm_pageout_req_swapout; /* XXX */
155 static int vm_daemon_needed;
156 static struct mtx vm_daemon_mtx;
157 /* Allow for use by vm_pageout before vm_daemon is initialized. */
158 MTX_SYSINIT(vm_daemon, &vm_daemon_mtx, "vm daemon", MTX_DEF);
160 static int swapped_cnt;
161 static int swap_inprogress; /* Pending swap-ins done outside swapper. */
162 static int last_swapin;
164 static void swapclear(struct proc *);
165 static int swapout(struct proc *);
166 static void vm_swapout_map_deactivate_pages(vm_map_t, long);
167 static void vm_swapout_object_deactivate_pages(pmap_t, vm_object_t, long);
168 static void swapout_procs(int action);
169 static void vm_req_vmdaemon(int req);
170 static void vm_thread_swapout(struct thread *td);
173 * vm_swapout_object_deactivate_pages
175 * Deactivate enough pages to satisfy the inactive target
178 * The object and map must be locked.
181 vm_swapout_object_deactivate_pages(pmap_t pmap, vm_object_t first_object,
184 vm_object_t backing_object, object;
186 int act_delta, remove_mode;
188 VM_OBJECT_ASSERT_LOCKED(first_object);
189 if ((first_object->flags & OBJ_FICTITIOUS) != 0)
191 for (object = first_object;; object = backing_object) {
192 if (pmap_resident_count(pmap) <= desired)
194 VM_OBJECT_ASSERT_LOCKED(object);
195 if ((object->flags & OBJ_UNMANAGED) != 0 ||
196 object->paging_in_progress != 0)
200 if (object->shadow_count > 1)
203 * Scan the object's entire memory queue.
205 TAILQ_FOREACH(p, &object->memq, listq) {
206 if (pmap_resident_count(pmap) <= desired)
210 if (vm_page_busied(p))
212 VM_CNT_INC(v_pdpages);
214 if (vm_page_wired(p) ||
215 !pmap_page_exists_quick(pmap, p)) {
219 act_delta = pmap_ts_referenced(p);
220 if ((p->aflags & PGA_REFERENCED) != 0) {
223 vm_page_aflag_clear(p, PGA_REFERENCED);
225 if (!vm_page_active(p) && act_delta != 0) {
227 p->act_count += act_delta;
228 } else if (vm_page_active(p)) {
229 if (act_delta == 0) {
230 p->act_count -= min(p->act_count,
232 if (!remove_mode && p->act_count == 0) {
234 vm_page_deactivate(p);
239 if (p->act_count < ACT_MAX -
241 p->act_count += ACT_ADVANCE;
244 } else if (vm_page_inactive(p))
248 if ((backing_object = object->backing_object) == NULL)
250 VM_OBJECT_RLOCK(backing_object);
251 if (object != first_object)
252 VM_OBJECT_RUNLOCK(object);
255 if (object != first_object)
256 VM_OBJECT_RUNLOCK(object);
260 * deactivate some number of pages in a map, try to do it fairly, but
261 * that is really hard to do.
264 vm_swapout_map_deactivate_pages(vm_map_t map, long desired)
267 vm_object_t obj, bigobj;
270 if (!vm_map_trylock_read(map))
277 * first, search out the biggest object, and try to free pages from
280 tmpe = map->header.next;
281 while (tmpe != &map->header) {
282 if ((tmpe->eflags & MAP_ENTRY_IS_SUB_MAP) == 0) {
283 obj = tmpe->object.vm_object;
284 if (obj != NULL && VM_OBJECT_TRYRLOCK(obj)) {
285 if (obj->shadow_count <= 1 &&
287 bigobj->resident_page_count <
288 obj->resident_page_count)) {
290 VM_OBJECT_RUNLOCK(bigobj);
293 VM_OBJECT_RUNLOCK(obj);
296 if (tmpe->wired_count > 0)
297 nothingwired = FALSE;
301 if (bigobj != NULL) {
302 vm_swapout_object_deactivate_pages(map->pmap, bigobj, desired);
303 VM_OBJECT_RUNLOCK(bigobj);
306 * Next, hunt around for other pages to deactivate. We actually
307 * do this search sort of wrong -- .text first is not the best idea.
309 tmpe = map->header.next;
310 while (tmpe != &map->header) {
311 if (pmap_resident_count(vm_map_pmap(map)) <= desired)
313 if ((tmpe->eflags & MAP_ENTRY_IS_SUB_MAP) == 0) {
314 obj = tmpe->object.vm_object;
316 VM_OBJECT_RLOCK(obj);
317 vm_swapout_object_deactivate_pages(map->pmap,
319 VM_OBJECT_RUNLOCK(obj);
326 * Remove all mappings if a process is swapped out, this will free page
329 if (desired == 0 && nothingwired) {
330 pmap_remove(vm_map_pmap(map), vm_map_min(map),
334 vm_map_unlock_read(map);
340 #define VM_SWAP_NORMAL 1
341 #define VM_SWAP_IDLE 2
348 vm_req_vmdaemon(VM_SWAP_NORMAL);
352 * Idle process swapout -- run once per second when pagedaemons are
356 vm_swapout_run_idle(void)
360 if (!vm_swap_idle_enabled || time_second == lsec)
362 vm_req_vmdaemon(VM_SWAP_IDLE);
367 vm_req_vmdaemon(int req)
369 static int lastrun = 0;
371 mtx_lock(&vm_daemon_mtx);
372 vm_pageout_req_swapout |= req;
373 if ((ticks > (lastrun + hz)) || (ticks < lastrun)) {
374 wakeup(&vm_daemon_needed);
377 mtx_unlock(&vm_daemon_mtx);
383 struct rlimit rsslim;
387 int breakout, swapout_flags, tryagain, attempts;
389 uint64_t rsize, ravailable;
393 mtx_lock(&vm_daemon_mtx);
394 msleep(&vm_daemon_needed, &vm_daemon_mtx, PPAUSE, "psleep",
396 racct_enable ? hz : 0
401 swapout_flags = vm_pageout_req_swapout;
402 vm_pageout_req_swapout = 0;
403 mtx_unlock(&vm_daemon_mtx);
404 if (swapout_flags != 0) {
406 * Drain the per-CPU page queue batches as a deadlock
409 if ((swapout_flags & VM_SWAP_NORMAL) != 0)
410 vm_page_drain_pqbatch();
411 swapout_procs(swapout_flags);
415 * scan the processes for exceeding their rlimits or if
416 * process is swapped out -- deactivate pages
422 sx_slock(&allproc_lock);
423 FOREACH_PROC_IN_SYSTEM(p) {
424 vm_pindex_t limit, size;
427 * if this is a system process or if we have already
428 * looked at this process, skip it.
431 if (p->p_state != PRS_NORMAL ||
432 p->p_flag & (P_INEXEC | P_SYSTEM | P_WEXIT)) {
437 * if the process is in a non-running type state,
441 FOREACH_THREAD_IN_PROC(p, td) {
443 if (!TD_ON_RUNQ(td) &&
444 !TD_IS_RUNNING(td) &&
445 !TD_IS_SLEEPING(td) &&
446 !TD_IS_SUSPENDED(td)) {
460 lim_rlimit_proc(p, RLIMIT_RSS, &rsslim);
462 qmin(rsslim.rlim_cur, rsslim.rlim_max));
465 * let processes that are swapped out really be
466 * swapped out set the limit to nothing (will force a
469 if ((p->p_flag & P_INMEM) == 0)
471 vm = vmspace_acquire_ref(p);
478 sx_sunlock(&allproc_lock);
480 size = vmspace_resident_count(vm);
482 vm_swapout_map_deactivate_pages(
484 size = vmspace_resident_count(vm);
488 rsize = IDX_TO_OFF(size);
490 if (p->p_state == PRS_NORMAL)
491 racct_set(p, RACCT_RSS, rsize);
492 ravailable = racct_get_available(p, RACCT_RSS);
494 if (rsize > ravailable) {
496 * Don't be overly aggressive; this
497 * might be an innocent process,
498 * and the limit could've been exceeded
499 * by some memory hog. Don't try
500 * to deactivate more than 1/4th
501 * of process' resident set size.
504 if (ravailable < rsize -
510 vm_swapout_map_deactivate_pages(
512 OFF_TO_IDX(ravailable));
513 /* Update RSS usage after paging out. */
514 size = vmspace_resident_count(vm);
515 rsize = IDX_TO_OFF(size);
517 if (p->p_state == PRS_NORMAL)
518 racct_set(p, RACCT_RSS, rsize);
520 if (rsize > ravailable)
526 sx_slock(&allproc_lock);
529 sx_sunlock(&allproc_lock);
530 if (tryagain != 0 && attempts <= 10) {
538 * Allow a thread's kernel stack to be paged out.
541 vm_thread_swapout(struct thread *td)
547 cpu_thread_swapout(td);
548 pages = td->td_kstack_pages;
549 ksobj = td->td_kstack_obj;
550 pmap_qremove(td->td_kstack, pages);
551 VM_OBJECT_WLOCK(ksobj);
552 for (i = 0; i < pages; i++) {
553 m = vm_page_lookup(ksobj, i);
555 panic("vm_thread_swapout: kstack already missing?");
558 vm_page_unwire(m, PQ_LAUNDRY);
561 VM_OBJECT_WUNLOCK(ksobj);
565 * Bring the kernel stack for a specified thread back in.
568 vm_thread_swapin(struct thread *td, int oom_alloc)
571 vm_page_t ma[KSTACK_MAX_PAGES];
572 int a, count, i, j, pages, rv;
574 pages = td->td_kstack_pages;
575 ksobj = td->td_kstack_obj;
576 VM_OBJECT_WLOCK(ksobj);
577 (void)vm_page_grab_pages(ksobj, 0, oom_alloc | VM_ALLOC_WIRED, ma,
579 for (i = 0; i < pages;) {
580 vm_page_assert_xbusied(ma[i]);
581 if (ma[i]->valid == VM_PAGE_BITS_ALL) {
582 vm_page_xunbusy(ma[i]);
586 vm_object_pip_add(ksobj, 1);
587 for (j = i + 1; j < pages; j++)
588 if (ma[j]->valid == VM_PAGE_BITS_ALL)
590 rv = vm_pager_has_page(ksobj, ma[i]->pindex, NULL, &a);
591 KASSERT(rv == 1, ("%s: missing page %p", __func__, ma[i]));
592 count = min(a + 1, j - i);
593 rv = vm_pager_get_pages(ksobj, ma + i, count, NULL, NULL);
594 KASSERT(rv == VM_PAGER_OK, ("%s: cannot get kstack for proc %d",
595 __func__, td->td_proc->p_pid));
596 vm_object_pip_wakeup(ksobj);
597 for (j = i; j < i + count; j++)
598 vm_page_xunbusy(ma[j]);
601 VM_OBJECT_WUNLOCK(ksobj);
602 pmap_qenter(td->td_kstack, ma, pages);
603 cpu_thread_swapin(td);
607 faultin(struct proc *p)
612 PROC_LOCK_ASSERT(p, MA_OWNED);
615 * If another process is swapping in this process,
616 * just wait until it finishes.
618 if (p->p_flag & P_SWAPPINGIN) {
619 while (p->p_flag & P_SWAPPINGIN)
620 msleep(&p->p_flag, &p->p_mtx, PVM, "faultin", 0);
624 if ((p->p_flag & P_INMEM) == 0) {
625 oom_alloc = (p->p_flag & P_WKILLED) != 0 ? VM_ALLOC_SYSTEM :
629 * Don't let another thread swap process p out while we are
630 * busy swapping it in.
633 p->p_flag |= P_SWAPPINGIN;
635 sx_xlock(&allproc_lock);
636 MPASS(swapped_cnt > 0);
638 if (curthread != &thread0)
640 sx_xunlock(&allproc_lock);
643 * We hold no lock here because the list of threads
644 * can not change while all threads in the process are
647 FOREACH_THREAD_IN_PROC(p, td)
648 vm_thread_swapin(td, oom_alloc);
650 if (curthread != &thread0) {
651 sx_xlock(&allproc_lock);
652 MPASS(swap_inprogress > 0);
655 sx_xunlock(&allproc_lock);
661 /* Allow other threads to swap p out now. */
668 * This swapin algorithm attempts to swap-in processes only if there
669 * is enough space for them. Of course, if a process waits for a long
670 * time, it will be swapped in anyway.
674 swapper_selector(bool wkilled_only)
676 struct proc *p, *res;
678 int ppri, pri, slptime, swtime;
680 sx_assert(&allproc_lock, SA_SLOCKED);
681 if (swapped_cnt == 0)
685 FOREACH_PROC_IN_SYSTEM(p) {
687 if (p->p_state == PRS_NEW || (p->p_flag & (P_SWAPPINGOUT |
688 P_SWAPPINGIN | P_INMEM)) != 0) {
692 if (p->p_state == PRS_NORMAL && (p->p_flag & P_WKILLED) != 0) {
694 * A swapped-out process might have mapped a
695 * large portion of the system's pages as
696 * anonymous memory. There is no other way to
697 * release the memory other than to kill the
698 * process, for which we need to swap it in.
706 swtime = (ticks - p->p_swtick) / hz;
707 FOREACH_THREAD_IN_PROC(p, td) {
709 * An otherwise runnable thread of a process
710 * swapped out has only the TDI_SWAPPED bit set.
713 if (td->td_inhibitors == TDI_SWAPPED) {
714 slptime = (ticks - td->td_slptick) / hz;
715 pri = swtime + slptime;
716 if ((td->td_flags & TDF_SWAPINREQ) == 0)
717 pri -= p->p_nice * 8;
719 * if this thread is higher priority
720 * and there is enough space, then select
721 * this process instead of the previous
739 #define SWAPIN_INTERVAL (MAXSLP * hz / 2)
742 * Limit swapper to swap in one non-WKILLED process in MAXSLP/2
743 * interval, assuming that there is:
744 * - at least one domain that is not suffering from a shortage of free memory;
745 * - no parallel swap-ins;
746 * - no other swap-ins in the current SWAPIN_INTERVAL.
749 swapper_wkilled_only(void)
752 return (vm_page_count_min_set(&all_domains) || swap_inprogress > 0 ||
753 (u_int)(ticks - last_swapin) < SWAPIN_INTERVAL);
762 sx_slock(&allproc_lock);
763 p = swapper_selector(swapper_wkilled_only());
764 sx_sunlock(&allproc_lock);
767 tsleep(&proc0, PVM, "swapin", SWAPIN_INTERVAL);
769 PROC_LOCK_ASSERT(p, MA_OWNED);
772 * Another process may be bringing or may have
773 * already brought this process in while we
774 * traverse all threads. Or, this process may
775 * have exited or even being swapped out
778 if (p->p_state == PRS_NORMAL && (p->p_flag & (P_INMEM |
779 P_SWAPPINGOUT | P_SWAPPINGIN)) == 0) {
788 * First, if any processes have been sleeping or stopped for at least
789 * "swap_idle_threshold1" seconds, they are swapped out. If, however,
790 * no such processes exist, then the longest-sleeping or stopped
791 * process is swapped out. Finally, and only as a last resort, if
792 * there are no sleeping or stopped processes, the longest-resident
793 * process is swapped out.
796 swapout_procs(int action)
801 bool didswap, doswap;
803 MPASS((action & (VM_SWAP_NORMAL | VM_SWAP_IDLE)) != 0);
806 sx_slock(&allproc_lock);
807 FOREACH_PROC_IN_SYSTEM(p) {
809 * Filter out not yet fully constructed processes. Do
810 * not swap out held processes. Avoid processes which
811 * are system, exiting, execing, traced, already swapped
812 * out or are in the process of being swapped in or out.
815 if (p->p_state != PRS_NORMAL || p->p_lock != 0 || (p->p_flag &
816 (P_SYSTEM | P_WEXIT | P_INEXEC | P_STOPPED_SINGLE |
817 P_TRACED | P_SWAPPINGOUT | P_SWAPPINGIN | P_INMEM)) !=
824 * Further consideration of this process for swap out
825 * requires iterating over its threads. We release
826 * allproc_lock here so that process creation and
827 * destruction are not blocked while we iterate.
829 * To later reacquire allproc_lock and resume
830 * iteration over the allproc list, we will first have
831 * to release the lock on the process. We place a
832 * hold on the process so that it remains in the
833 * allproc list while it is unlocked.
836 sx_sunlock(&allproc_lock);
839 * Do not swapout a realtime process.
840 * Guarantee swap_idle_threshold1 time in memory.
841 * If the system is under memory stress, or if we are
842 * swapping idle processes >= swap_idle_threshold2,
843 * then swap the process out.
846 FOREACH_THREAD_IN_PROC(p, td) {
848 slptime = (ticks - td->td_slptick) / hz;
849 if (PRI_IS_REALTIME(td->td_pri_class) ||
850 slptime < swap_idle_threshold1 ||
851 !thread_safetoswapout(td) ||
852 ((action & VM_SWAP_NORMAL) == 0 &&
853 slptime < swap_idle_threshold2))
859 if (doswap && swapout(p) == 0)
864 sx_xlock(&allproc_lock);
866 sx_downgrade(&allproc_lock);
868 sx_slock(&allproc_lock);
871 sx_sunlock(&allproc_lock);
874 * If we swapped something out, and another process needed memory,
875 * then wakeup the sched process.
882 swapclear(struct proc *p)
886 PROC_LOCK_ASSERT(p, MA_OWNED);
888 FOREACH_THREAD_IN_PROC(p, td) {
890 td->td_flags |= TDF_INMEM;
891 td->td_flags &= ~TDF_SWAPINREQ;
894 if (setrunnable(td)) {
897 * XXX: We just cleared TDI_SWAPPED
898 * above and set TDF_INMEM, so this
899 * should never happen.
901 panic("not waking up swapper");
906 p->p_flag &= ~(P_SWAPPINGIN | P_SWAPPINGOUT);
907 p->p_flag |= P_INMEM;
911 swapout(struct proc *p)
915 PROC_LOCK_ASSERT(p, MA_OWNED);
918 * The states of this process and its threads may have changed
919 * by now. Assuming that there is only one pageout daemon thread,
920 * this process should still be in memory.
922 KASSERT((p->p_flag & (P_INMEM | P_SWAPPINGOUT | P_SWAPPINGIN)) ==
923 P_INMEM, ("swapout: lost a swapout race?"));
926 * Remember the resident count.
928 p->p_vmspace->vm_swrss = vmspace_resident_count(p->p_vmspace);
931 * Check and mark all threads before we proceed.
933 p->p_flag &= ~P_INMEM;
934 p->p_flag |= P_SWAPPINGOUT;
935 FOREACH_THREAD_IN_PROC(p, td) {
937 if (!thread_safetoswapout(td)) {
942 td->td_flags &= ~TDF_INMEM;
946 td = FIRST_THREAD_IN_PROC(p);
947 ++td->td_ru.ru_nswap;
951 * This list is stable because all threads are now prevented from
952 * running. The list is only modified in the context of a running
953 * thread in this process.
955 FOREACH_THREAD_IN_PROC(p, td)
956 vm_thread_swapout(td);
959 p->p_flag &= ~P_SWAPPINGOUT;