git: 0dd7789512a1 - main - vm: Remove kernel stack swapping support, part 2
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 29 Jul 2024 01:49:53 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0dd7789512a11019bc958efaaedfeada434dea8f commit 0dd7789512a11019bc958efaaedfeada434dea8f Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2024-07-29 01:38:39 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-07-29 01:38:39 +0000 vm: Remove kernel stack swapping support, part 2 After mi_startup() finishes, thread0 becomes the "swapper", whose responsibility is to swap threads back in on demand. Now that threads can't be swapped out, there is no use for this thread. Just sleep forever once sysinits are finished; thread_exit() doesn't work because thread0 is allocated statically. The thread could be repurposed if that would be useful. Tested by: pho Reviewed by: alc, imp, kib Differential Revision: https://reviews.freebsd.org/D46113 --- sys/kern/init_main.c | 9 ++-- sys/vm/vm.h | 1 - sys/vm/vm_glue.c | 5 +- sys/vm/vm_swapout.c | 120 ---------------------------------------------- sys/vm/vm_swapout_dummy.c | 8 ---- 5 files changed, 8 insertions(+), 135 deletions(-) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 3e4f19d655e6..7386a0729835 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -256,7 +256,6 @@ symbol_name(vm_offset_t va, db_strategy_t strategy) void mi_startup(void) { - struct sysinit *sip; int last; #if defined(VERBOSE_SYSINIT) @@ -339,10 +338,12 @@ mi_startup(void) mtx_unlock(&Giant); /* - * Now hand over this thread to swapper. + * We can't free our thread structure since it is statically allocated. + * Just sleep forever. This thread could be repurposed for something if + * the need arises. */ - swapper(); - /* NOTREACHED*/ + for (;;) + tsleep(__builtin_frame_address(0), PNOLOCK, "parked", 0); } static void diff --git a/sys/vm/vm.h b/sys/vm/vm.h index b7d149a2fca2..d28c84dd1c95 100644 --- a/sys/vm/vm.h +++ b/sys/vm/vm.h @@ -170,7 +170,6 @@ bool swap_reserve_by_cred(vm_ooffset_t incr, struct ucred *cred); void swap_reserve_force(vm_ooffset_t incr); void swap_release(vm_ooffset_t decr); void swap_release_by_cred(vm_ooffset_t decr, struct ucred *cred); -void swapper(void); extern struct kva_md_info kmi; #define VA_IS_CLEANMAP(va) \ diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c index 4f8121fa1064..63417687a1a5 100644 --- a/sys/vm/vm_glue.c +++ b/sys/vm/vm_glue.c @@ -834,9 +834,10 @@ vm_waitproc(struct proc *p) vmspace_exitfree(p); /* and clean-out the vmspace */ } +/* + * This used to kick the thread which faults in threads. + */ void kick_proc0(void) { - - wakeup(&proc0); } diff --git a/sys/vm/vm_swapout.c b/sys/vm/vm_swapout.c index 85708d61d849..b97f6904ab5a 100644 --- a/sys/vm/vm_swapout.c +++ b/sys/vm/vm_swapout.c @@ -564,126 +564,6 @@ faultin(struct proc *p) } } -/* - * This swapin algorithm attempts to swap-in processes only if there - * is enough space for them. Of course, if a process waits for a long - * time, it will be swapped in anyway. - */ - -static struct proc * -swapper_selector(bool wkilled_only) -{ - struct proc *p, *res; - struct thread *td; - int ppri, pri, slptime, swtime; - - sx_assert(&allproc_lock, SA_SLOCKED); - if (swapped_cnt == 0) - return (NULL); - res = NULL; - ppri = INT_MIN; - FOREACH_PROC_IN_SYSTEM(p) { - PROC_LOCK(p); - if (p->p_state == PRS_NEW || (p->p_flag & (P_SWAPPINGOUT | - P_SWAPPINGIN | P_INMEM)) != 0) { - PROC_UNLOCK(p); - continue; - } - if (p->p_state == PRS_NORMAL && (p->p_flag & P_WKILLED) != 0) { - /* - * A swapped-out process might have mapped a - * large portion of the system's pages as - * anonymous memory. There is no other way to - * release the memory other than to kill the - * process, for which we need to swap it in. - */ - return (p); - } - if (wkilled_only) { - PROC_UNLOCK(p); - continue; - } - swtime = (ticks - p->p_swtick) / hz; - FOREACH_THREAD_IN_PROC(p, td) { - /* - * An otherwise runnable thread of a process - * swapped out has only the TDI_SWAPPED bit set. - */ - thread_lock(td); - if (td->td_inhibitors == TDI_SWAPPED) { - slptime = (ticks - td->td_slptick) / hz; - pri = swtime + slptime; - if ((td->td_flags & TDF_SWAPINREQ) == 0) - pri -= p->p_nice * 8; - /* - * if this thread is higher priority - * and there is enough space, then select - * this process instead of the previous - * selection. - */ - if (pri > ppri) { - res = p; - ppri = pri; - } - } - thread_unlock(td); - } - PROC_UNLOCK(p); - } - - if (res != NULL) - PROC_LOCK(res); - return (res); -} - -#define SWAPIN_INTERVAL (MAXSLP * hz / 2) - -/* - * Limit swapper to swap in one non-WKILLED process in MAXSLP/2 - * interval, assuming that there is: - * - at least one domain that is not suffering from a shortage of free memory; - * - no parallel swap-ins; - * - no other swap-ins in the current SWAPIN_INTERVAL. - */ -static bool -swapper_wkilled_only(void) -{ - - return (vm_page_count_min_set(&all_domains) || swap_inprogress > 0 || - (u_int)(ticks - last_swapin) < SWAPIN_INTERVAL); -} - -void -swapper(void) -{ - struct proc *p; - - for (;;) { - sx_slock(&allproc_lock); - p = swapper_selector(swapper_wkilled_only()); - sx_sunlock(&allproc_lock); - - if (p == NULL) { - tsleep(&proc0, PVM, "swapin", SWAPIN_INTERVAL); - } else { - PROC_LOCK_ASSERT(p, MA_OWNED); - - /* - * Another process may be bringing or may have - * already brought this process in while we - * traverse all threads. Or, this process may - * have exited or even being swapped out - * again. - */ - if (p->p_state == PRS_NORMAL && (p->p_flag & (P_INMEM | - P_SWAPPINGOUT | P_SWAPPINGIN)) == 0) { - faultin(p); - } - PROC_UNLOCK(p); - } - } -} - static void swapclear(struct proc *p) { diff --git a/sys/vm/vm_swapout_dummy.c b/sys/vm/vm_swapout_dummy.c index 0e0a268c8c46..7697a86f9d0b 100644 --- a/sys/vm/vm_swapout_dummy.c +++ b/sys/vm/vm_swapout_dummy.c @@ -99,11 +99,3 @@ faultin(struct proc *p) if ((p->p_flag & P_INMEM) == 0) panic("faultin: proc %p swapped out with NO_SWAPPING", p); } - -void -swapper(void) -{ - - for (;;) - tsleep(&proc0, PVM, "swapin", MAXSLP * hz); -}