From nobody Mon Jul 29 01:49:53 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WXLry3Sptz5S7DN; Mon, 29 Jul 2024 01:49:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WXLry2QZkz4nbk; Mon, 29 Jul 2024 01:49:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722217794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0XYrNv9/qpqPeTQSiuriwYtL15TDbXk9tBTPhchm1dA=; b=birQhZtmCnEFfGYMx7hS0qU8bYq6x2zcBrEUi3vMxLGitvt/1VctFQcuYAjlTeaooVRiy8 IFKhhyHhphnCWPCSG3G/Hs0ZaYYCZXcRYnWX1fAIivDX7+btYaMo+I40p3mGYUcGO1epsL 5BAEjL6T9GobQI0kzyE26aThO1q7Rgn4aAvi5NHTVl7w0VWARNHhoTn+2QBx1I2weOwKmB zRYGvkHz3OxyEd4zu5Wszaz7jcuuZImoe3qvU9flOfU9qh8g1zo7N8lkwWfSBvDdp8ilNZ l0ISlCO+x4FCIt+H6uvnhLNo5mSr+Zl/Z+i2vHHHfTJ40qqUvezLyoZ0ri3FHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722217794; a=rsa-sha256; cv=none; b=vU3TbfJfRUXKY8eEUtw/Q9CwvWLrV6yFyp+WJ1jXmOLaEuHQr2yaxW8DOKoEPNeHrl1H+K I9Pb72qw36IR5rsEQ/xuUxVTYenSNKwiG0aMpHLbzraygFw1OoaSKFzlri8ZBO4uYUecxF uqUbFLhLqzkbtIh97brBxDwUUcx10YqNMNJyHQhiVMPX6fqs4+AqlDTAKObDEhrryQHBhL KfbeAAtF/H0xJWs2ArpgVqWsU1AFK1D0H2lj89ejdKtgXPGl7epDf3C8Gn7l/C4v2ticvG GIOtPg+s01f6vmDE+tsqQ0d+z4YM9OPJa07NGQJ8m8iVjnfxLfBfW7w6nH5xFQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722217794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0XYrNv9/qpqPeTQSiuriwYtL15TDbXk9tBTPhchm1dA=; b=u+Bw2pLwCx1lPrQaCsfmKfDdSdJb4KbWrkO3ykMFPP4RoKmxCNPGt4M1Wezma9oAMfmC6e uP4RjqeIaBjkyx+Dv9z/Rz9NUmPqEzI3bAf0hUYrdcTFLFwB8AVOr4M99gmTeDqTcn2ieY I4FsWBRFYyG+Bod+s6Y1dJ4ipiMnLhXaTqJcP5sKuPY1EYxt8HJm6CTU8Mzpp08xbLzAcV V06z06yfnZAR5SgZ8DDDJsq62UoydpjawbFTzCMfsT/DJWlgpGestewb1Xd2Fhf+ohHnRv /szK5ll8CqPMQWZywBCvNBCT8tdzAS+K7+92RUV8hK5qgE5rtmA3zDwJjw0Rsg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WXLry0GCVzFJ6; Mon, 29 Jul 2024 01:49:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46T1nr4J091669; Mon, 29 Jul 2024 01:49:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46T1nrRg091666; Mon, 29 Jul 2024 01:49:53 GMT (envelope-from git) Date: Mon, 29 Jul 2024 01:49:53 GMT Message-Id: <202407290149.46T1nrRg091666@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 0dd7789512a1 - main - vm: Remove kernel stack swapping support, part 2 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0dd7789512a11019bc958efaaedfeada434dea8f Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0dd7789512a11019bc958efaaedfeada434dea8f commit 0dd7789512a11019bc958efaaedfeada434dea8f Author: Mark Johnston AuthorDate: 2024-07-29 01:38:39 +0000 Commit: Mark Johnston 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); -}