2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from: @(#)vm_glue.c 8.6 (Berkeley) 1/5/94
35 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
36 * All rights reserved.
38 * Permission to use, copy, modify and distribute this software and
39 * its documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
59 #include <sys/cdefs.h>
60 __FBSDID("$FreeBSD$");
63 #include "opt_kstack_pages.h"
64 #include "opt_kstack_max_pages.h"
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/limits.h>
70 #include <sys/mutex.h>
72 #include <sys/resourcevar.h>
74 #include <sys/vmmeter.h>
76 #include <sys/sysctl.h>
78 #include <sys/kernel.h>
80 #include <sys/unistd.h>
83 #include <vm/vm_param.h>
85 #include <vm/vm_map.h>
86 #include <vm/vm_page.h>
87 #include <vm/vm_pageout.h>
88 #include <vm/vm_object.h>
89 #include <vm/vm_kern.h>
90 #include <vm/vm_extern.h>
91 #include <vm/vm_pager.h>
92 #include <vm/swap_pager.h>
97 * System initialization
99 * Note: proc0 from proc.h
101 static void vm_init_limits(void *);
102 SYSINIT(vm_limits, SI_SUB_VM_CONF, SI_ORDER_FIRST, vm_init_limits, &proc0)
105 * THIS MUST BE THE LAST INITIALIZATION ITEM!!!
107 * Note: run scheduling should be divorced from the vm system.
109 static void scheduler(void *);
110 SYSINIT(scheduler, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, scheduler, NULL)
113 static void swapout(struct proc *);
119 * WARNING! This code calls vm_map_check_protection() which only checks
120 * the associated vm_map_entry range. It does not determine whether the
121 * contents of the memory is actually readable or writable. In most cases
122 * just checking the vm_map_entry is sufficient within the kernel's address
126 kernacc(addr, len, rw)
131 vm_offset_t saddr, eaddr;
134 KASSERT((rw & ~VM_PROT_ALL) == 0,
135 ("illegal ``rw'' argument to kernacc (%x)\n", rw));
137 if ((vm_offset_t)addr + len > kernel_map->max_offset ||
138 (vm_offset_t)addr + len < (vm_offset_t)addr)
142 saddr = trunc_page((vm_offset_t)addr);
143 eaddr = round_page((vm_offset_t)addr + len);
144 vm_map_lock_read(kernel_map);
145 rv = vm_map_check_protection(kernel_map, saddr, eaddr, prot);
146 vm_map_unlock_read(kernel_map);
153 * WARNING! This code calls vm_map_check_protection() which only checks
154 * the associated vm_map_entry range. It does not determine whether the
155 * contents of the memory is actually readable or writable. vmapbuf(),
156 * vm_fault_quick(), or copyin()/copout()/su*()/fu*() functions should be
157 * used in conjuction with this call.
160 useracc(addr, len, rw)
168 KASSERT((rw & ~VM_PROT_ALL) == 0,
169 ("illegal ``rw'' argument to useracc (%x)\n", rw));
171 map = &curproc->p_vmspace->vm_map;
172 if ((vm_offset_t)addr + len > vm_map_max(map) ||
173 (vm_offset_t)addr + len < (vm_offset_t)addr) {
176 vm_map_lock_read(map);
177 rv = vm_map_check_protection(map, trunc_page((vm_offset_t)addr),
178 round_page((vm_offset_t)addr + len), prot);
179 vm_map_unlock_read(map);
184 vslock(void *addr, size_t len)
186 vm_offset_t end, last, start;
190 last = (vm_offset_t)addr + len;
191 start = trunc_page((vm_offset_t)addr);
192 end = round_page(last);
193 if (last < (vm_offset_t)addr || end < (vm_offset_t)addr)
195 npages = atop(end - start);
196 if (npages > vm_page_max_wired)
200 pmap_wired_count(vm_map_pmap(&curproc->p_vmspace->vm_map))) >
201 lim_cur(curproc, RLIMIT_MEMLOCK)) {
202 PROC_UNLOCK(curproc);
205 PROC_UNLOCK(curproc);
210 * The limit for transient usage of wired pages should be
211 * larger than for "permanent" wired pages (mlock()).
213 * Also, the sysctl code, which is the only present user
214 * of vslock(), does a hard loop on EAGAIN.
216 if (npages + cnt.v_wire_count > vm_page_max_wired)
219 error = vm_map_wire(&curproc->p_vmspace->vm_map, start, end,
220 VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
222 * Return EFAULT on error to match copy{in,out}() behaviour
223 * rather than returning ENOMEM like mlock() would.
225 return (error == KERN_SUCCESS ? 0 : EFAULT);
229 vsunlock(void *addr, size_t len)
232 /* Rely on the parameter sanity checks performed by vslock(). */
233 (void)vm_map_unwire(&curproc->p_vmspace->vm_map,
234 trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len),
235 VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
238 #ifndef KSTACK_MAX_PAGES
239 #define KSTACK_MAX_PAGES 32
243 * Create the kernel stack (including pcb for i386) for a new thread.
244 * This routine directly affects the fork perf for a process and
245 * create performance for a thread.
248 vm_thread_new(struct thread *td, int pages)
252 vm_page_t m, ma[KSTACK_MAX_PAGES];
257 pages = KSTACK_PAGES;
258 else if (pages > KSTACK_MAX_PAGES)
259 pages = KSTACK_MAX_PAGES;
261 * Allocate an object for the kstack.
263 ksobj = vm_object_allocate(OBJT_DEFAULT, pages);
264 td->td_kstack_obj = ksobj;
266 * Get a kernel virtual address for this thread's kstack.
268 ks = kmem_alloc_nofault(kernel_map,
269 (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
271 panic("vm_thread_new: kstack allocation failed");
272 if (KSTACK_GUARD_PAGES != 0) {
273 pmap_qremove(ks, KSTACK_GUARD_PAGES);
274 ks += KSTACK_GUARD_PAGES * PAGE_SIZE;
278 * Knowing the number of pages allocated is useful when you
279 * want to deallocate them.
281 td->td_kstack_pages = pages;
283 * For the length of the stack, link in a real page of ram for each
286 VM_OBJECT_LOCK(ksobj);
287 for (i = 0; i < pages; i++) {
289 * Get a kernel stack page.
291 m = vm_page_grab(ksobj, i, VM_ALLOC_NOBUSY |
292 VM_ALLOC_NORMAL | VM_ALLOC_RETRY | VM_ALLOC_WIRED);
294 m->valid = VM_PAGE_BITS_ALL;
296 VM_OBJECT_UNLOCK(ksobj);
297 pmap_qenter(ks, ma, pages);
301 * Dispose of a thread's kernel stack.
304 vm_thread_dispose(struct thread *td)
311 pages = td->td_kstack_pages;
312 ksobj = td->td_kstack_obj;
314 pmap_qremove(ks, pages);
315 VM_OBJECT_LOCK(ksobj);
316 for (i = 0; i < pages; i++) {
317 m = vm_page_lookup(ksobj, i);
319 panic("vm_thread_dispose: kstack already missing?");
320 vm_page_lock_queues();
321 vm_page_unwire(m, 0);
323 vm_page_unlock_queues();
325 VM_OBJECT_UNLOCK(ksobj);
326 vm_object_deallocate(ksobj);
327 kmem_free(kernel_map, ks - (KSTACK_GUARD_PAGES * PAGE_SIZE),
328 (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
332 * Allow a thread's kernel stack to be paged out.
335 vm_thread_swapout(struct thread *td)
341 cpu_thread_swapout(td);
342 pages = td->td_kstack_pages;
343 ksobj = td->td_kstack_obj;
344 pmap_qremove(td->td_kstack, pages);
345 VM_OBJECT_LOCK(ksobj);
346 for (i = 0; i < pages; i++) {
347 m = vm_page_lookup(ksobj, i);
349 panic("vm_thread_swapout: kstack already missing?");
350 vm_page_lock_queues();
352 vm_page_unwire(m, 0);
353 vm_page_unlock_queues();
355 VM_OBJECT_UNLOCK(ksobj);
359 * Bring the kernel stack for a specified thread back in.
362 vm_thread_swapin(struct thread *td)
365 vm_page_t m, ma[KSTACK_MAX_PAGES];
368 pages = td->td_kstack_pages;
369 ksobj = td->td_kstack_obj;
370 VM_OBJECT_LOCK(ksobj);
371 for (i = 0; i < pages; i++) {
372 m = vm_page_grab(ksobj, i, VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
373 if (m->valid != VM_PAGE_BITS_ALL) {
374 rv = vm_pager_get_pages(ksobj, &m, 1, 0);
375 if (rv != VM_PAGER_OK)
376 panic("vm_thread_swapin: cannot get kstack for proc: %d", td->td_proc->p_pid);
377 m = vm_page_lookup(ksobj, i);
378 m->valid = VM_PAGE_BITS_ALL;
381 vm_page_lock_queues();
384 vm_page_unlock_queues();
386 VM_OBJECT_UNLOCK(ksobj);
387 pmap_qenter(td->td_kstack, ma, pages);
388 cpu_thread_swapin(td);
392 * Set up a variable-sized alternate kstack.
395 vm_thread_new_altkstack(struct thread *td, int pages)
398 td->td_altkstack = td->td_kstack;
399 td->td_altkstack_obj = td->td_kstack_obj;
400 td->td_altkstack_pages = td->td_kstack_pages;
402 vm_thread_new(td, pages);
406 * Restore the original kstack.
409 vm_thread_dispose_altkstack(struct thread *td)
412 vm_thread_dispose(td);
414 td->td_kstack = td->td_altkstack;
415 td->td_kstack_obj = td->td_altkstack_obj;
416 td->td_kstack_pages = td->td_altkstack_pages;
417 td->td_altkstack = 0;
418 td->td_altkstack_obj = NULL;
419 td->td_altkstack_pages = 0;
423 * Implement fork's actions on an address space.
424 * Here we arrange for the address space to be copied or referenced,
425 * allocate a user struct (pcb and kernel stack), then call the
426 * machine-dependent layer to fill those in and make the new process
427 * ready to run. The new process is set up so that it returns directly
428 * to user mode to avoid stack copying and relocation problems.
431 vm_forkproc(td, p2, td2, flags)
437 struct proc *p1 = td->td_proc;
439 if ((flags & RFPROC) == 0) {
441 * Divorce the memory, if it is shared, essentially
442 * this changes shared memory amongst threads, into
445 if ((flags & RFMEM) == 0) {
446 if (p1->p_vmspace->vm_refcnt > 1) {
450 cpu_fork(td, p2, td2, flags);
455 p2->p_vmspace = p1->p_vmspace;
456 atomic_add_int(&p1->p_vmspace->vm_refcnt, 1);
459 while (vm_page_count_severe()) {
463 if ((flags & RFMEM) == 0) {
464 p2->p_vmspace = vmspace_fork(p1->p_vmspace);
465 if (p1->p_vmspace->vm_shm)
470 * cpu_fork will copy and update the pcb, set up the kernel stack,
471 * and make the child ready to run.
473 cpu_fork(td, p2, td2, flags);
477 * Called after process has been wait(2)'ed apon and is being reaped.
478 * The idea is to reclaim resources that we could not reclaim while
479 * the process was still executing.
486 vmspace_exitfree(p); /* and clean-out the vmspace */
490 * Set default limits for VM system.
491 * Called for proc 0, and then inherited by all others.
493 * XXX should probably act directly on proc0.
496 vm_init_limits(udata)
499 struct proc *p = udata;
504 * Set up the initial limits on process VM. Set the maximum resident
505 * set size to be half of (reasonably) available memory. Since this
506 * is a soft limit, it comes into effect only when the system is out
507 * of memory - half of main memory helps to favor smaller processes,
508 * and reduces thrashing of the object cache.
511 limp->pl_rlimit[RLIMIT_STACK].rlim_cur = dflssiz;
512 limp->pl_rlimit[RLIMIT_STACK].rlim_max = maxssiz;
513 limp->pl_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz;
514 limp->pl_rlimit[RLIMIT_DATA].rlim_max = maxdsiz;
515 /* limit the limit to no less than 2MB */
516 rss_limit = max(cnt.v_free_count, 512);
517 limp->pl_rlimit[RLIMIT_RSS].rlim_cur = ptoa(rss_limit);
518 limp->pl_rlimit[RLIMIT_RSS].rlim_max = RLIM_INFINITY;
527 PROC_LOCK_ASSERT(p, MA_OWNED);
528 if ((p->p_sflag & PS_INMEM) == 0)
529 panic("faultin: proc swapped out with NO_SWAPPING!");
530 #else /* !NO_SWAPPING */
534 PROC_LOCK_ASSERT(p, MA_OWNED);
536 * If another process is swapping in this process,
537 * just wait until it finishes.
539 if (p->p_sflag & PS_SWAPPINGIN)
540 msleep(&p->p_sflag, &p->p_mtx, PVM, "faultin", 0);
541 else if ((p->p_sflag & PS_INMEM) == 0) {
543 * Don't let another thread swap process p out while we are
544 * busy swapping it in.
547 mtx_lock_spin(&sched_lock);
548 p->p_sflag |= PS_SWAPPINGIN;
549 mtx_unlock_spin(&sched_lock);
552 FOREACH_THREAD_IN_PROC(p, td)
553 vm_thread_swapin(td);
556 mtx_lock_spin(&sched_lock);
557 p->p_sflag &= ~PS_SWAPPINGIN;
558 p->p_sflag |= PS_INMEM;
559 FOREACH_THREAD_IN_PROC(p, td) {
564 mtx_unlock_spin(&sched_lock);
568 /* Allow other threads to swap p out now. */
571 #endif /* NO_SWAPPING */
575 * This swapin algorithm attempts to swap-in processes only if there
576 * is enough space for them. Of course, if a process waits for a long
577 * time, it will be swapped in anyway.
579 * XXXKSE - process with the thread with highest priority counts..
581 * Giant is still held at this point, to be released in tsleep.
594 mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED);
598 if (vm_page_count_min()) {
605 sx_slock(&allproc_lock);
606 FOREACH_PROC_IN_SYSTEM(p) {
608 if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) {
611 mtx_lock_spin(&sched_lock);
612 FOREACH_THREAD_IN_PROC(p, td) {
614 * An otherwise runnable thread of a process
615 * swapped out has only the TDI_SWAPPED bit set.
618 if (td->td_inhibitors == TDI_SWAPPED) {
620 pri = p->p_swtime + kg->kg_slptime;
621 if ((p->p_sflag & PS_SWAPINREQ) == 0) {
622 pri -= p->p_nice * 8;
626 * if this ksegrp is higher priority
627 * and there is enough space, then select
628 * this process instead of the previous
637 mtx_unlock_spin(&sched_lock);
639 sx_sunlock(&allproc_lock);
642 * Nothing to do, back to sleep.
644 if ((p = pp) == NULL) {
645 tsleep(&proc0, PVM, "sched", maxslp * hz / 2);
651 * Another process may be bringing or may have already
652 * brought this process in while we traverse all threads.
653 * Or, this process may even be being swapped out again.
655 if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) {
660 mtx_lock_spin(&sched_lock);
661 p->p_sflag &= ~PS_SWAPINREQ;
662 mtx_unlock_spin(&sched_lock);
665 * We would like to bring someone in. (only if there is space).
666 * [What checks the space? ]
670 mtx_lock_spin(&sched_lock);
672 mtx_unlock_spin(&sched_lock);
679 * Swap_idle_threshold1 is the guaranteed swapped in time for a process
681 static int swap_idle_threshold1 = 2;
682 SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold1, CTLFLAG_RW,
683 &swap_idle_threshold1, 0, "Guaranteed swapped in time for a process");
686 * Swap_idle_threshold2 is the time that a process can be idle before
687 * it will be swapped out, if idle swapping is enabled.
689 static int swap_idle_threshold2 = 10;
690 SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold2, CTLFLAG_RW,
691 &swap_idle_threshold2, 0, "Time before a process will be swapped out");
694 * Swapout is driven by the pageout daemon. Very simple, we find eligible
695 * procs and unwire their u-areas. We try to always "swap" at least one
696 * process in case we need the room for a swapin.
697 * If any procs have been sleeping/stopped for at least maxslp seconds,
698 * they are swapped. Else, we swap the longest-sleeping or stopped process,
699 * if any, otherwise the longest-resident process.
702 swapout_procs(action)
711 sx_slock(&allproc_lock);
712 FOREACH_PROC_IN_SYSTEM(p) {
714 int minslptime = 100000;
717 * Watch out for a process in
718 * creation. It may have no
719 * address space or lock yet.
721 mtx_lock_spin(&sched_lock);
722 if (p->p_state == PRS_NEW) {
723 mtx_unlock_spin(&sched_lock);
726 mtx_unlock_spin(&sched_lock);
729 * An aio daemon switches its
730 * address space while running.
731 * Perform a quick check whether
732 * a process has P_SYSTEM.
734 if ((p->p_flag & P_SYSTEM) != 0)
738 * Do not swapout a process that
739 * is waiting for VM data
740 * structures as there is a possible
741 * deadlock. Test this first as
744 * Lock the map until swapout
745 * finishes, or a thread of this
746 * process may attempt to alter
752 ("swapout_procs: a process has no address space"));
753 atomic_add_int(&vm->vm_refcnt, 1);
755 if (!vm_map_trylock(&vm->vm_map))
759 if (p->p_lock != 0 ||
760 (p->p_flag & (P_STOPPED_SINGLE|P_TRACED|P_SYSTEM|P_WEXIT)
765 * only aiod changes vmspace, however it will be
766 * skipped because of the if statement above checking
769 if ((p->p_sflag & (PS_INMEM|PS_SWAPPINGOUT|PS_SWAPPINGIN)) != PS_INMEM)
772 switch (p->p_state) {
774 /* Don't swap out processes in any sort
775 * of 'special' state. */
779 mtx_lock_spin(&sched_lock);
781 * do not swapout a realtime process
782 * Check all the thread groups..
784 FOREACH_KSEGRP_IN_PROC(p, kg) {
785 if (PRI_IS_REALTIME(kg->kg_pri_class))
789 * Guarantee swap_idle_threshold1
792 if (kg->kg_slptime < swap_idle_threshold1)
796 * Do not swapout a process if it is
797 * waiting on a critical event of some
798 * kind or there is a thread whose
799 * pageable memory may be accessed.
801 * This could be refined to support
802 * swapping out a thread.
804 FOREACH_THREAD_IN_GROUP(kg, td) {
805 if ((td->td_priority) < PSOCK ||
806 !thread_safetoswapout(td))
810 * If the system is under memory stress,
811 * or if we are swapping
812 * idle processes >= swap_idle_threshold2,
813 * then swap the process out.
815 if (((action & VM_SWAP_NORMAL) == 0) &&
816 (((action & VM_SWAP_IDLE) == 0) ||
817 (kg->kg_slptime < swap_idle_threshold2)))
820 if (minslptime > kg->kg_slptime)
821 minslptime = kg->kg_slptime;
825 * If the pageout daemon didn't free enough pages,
826 * or if this process is idle and the system is
827 * configured to swap proactively, swap it out.
829 if ((action & VM_SWAP_NORMAL) ||
830 ((action & VM_SWAP_IDLE) &&
831 (minslptime > swap_idle_threshold2))) {
834 mtx_unlock_spin(&sched_lock);
836 vm_map_unlock(&vm->vm_map);
838 sx_sunlock(&allproc_lock);
842 mtx_unlock_spin(&sched_lock);
846 vm_map_unlock(&vm->vm_map);
851 sx_sunlock(&allproc_lock);
853 * If we swapped something out, and another process needed memory,
854 * then wakeup the sched process.
866 PROC_LOCK_ASSERT(p, MA_OWNED);
867 mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED);
868 #if defined(SWAP_DEBUG)
869 printf("swapping out %d\n", p->p_pid);
873 * The states of this process and its threads may have changed
874 * by now. Assuming that there is only one pageout daemon thread,
875 * this process should still be in memory.
877 KASSERT((p->p_sflag & (PS_INMEM|PS_SWAPPINGOUT|PS_SWAPPINGIN)) == PS_INMEM,
878 ("swapout: lost a swapout race?"));
880 #if defined(INVARIANTS)
882 * Make sure that all threads are safe to be swapped out.
884 * Alternatively, we could swap out only safe threads.
886 FOREACH_THREAD_IN_PROC(p, td) {
887 KASSERT(thread_safetoswapout(td),
888 ("swapout: there is a thread not safe for swapout"));
890 #endif /* INVARIANTS */
892 ++p->p_stats->p_ru.ru_nswap;
894 * remember the process resident count
896 p->p_vmspace->vm_swrss = vmspace_resident_count(p->p_vmspace);
898 p->p_sflag &= ~PS_INMEM;
899 p->p_sflag |= PS_SWAPPINGOUT;
901 FOREACH_THREAD_IN_PROC(p, td)
903 mtx_unlock_spin(&sched_lock);
905 FOREACH_THREAD_IN_PROC(p, td)
906 vm_thread_swapout(td);
909 mtx_lock_spin(&sched_lock);
910 p->p_sflag &= ~PS_SWAPPINGOUT;
913 #endif /* !NO_SWAPPING */