From nobody Mon Jul 29 01:49:52 2024 X-Original-To: dev-commits-src-main@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 4WXLrx06X4z5S7DK; Mon, 29 Jul 2024 01:49:53 +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 4WXLrw6b5vz4nT3; Mon, 29 Jul 2024 01:49:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722217792; 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=MqDJhLjJ0pzHHRQi0Kt52b9PuzmEtjizkqZor1LNcl0=; b=VzL5mxSGY5mHwE10mZdTmwG+iqO4gThfSfZ0GXkIkzCP0VfwTyJwEwcX4NfUo2INWOVA14 HymCPiVcP4aJFirU0TW7LlGPxQOT4lDRNxvAzisLiO3JYdgCepCqcRc238YB8Fnq1KQWPQ ZYw0t7xNH3QPuWg3vHrJa7pEHSLxZ+gtN8pLWfp7TwR1OSSAv/D/EQi+Yw+VDwmMhfRg7H wd3HjujmYePPhtG4T8MPAk8wCuQM4R4PB7GvttknSn1kmR8YDQsC8CfRvxFtQzkqcn13o1 7weEHayqGXwwc80V/odZ7uGEy+oyKUx0SpwQkkhhCalAfmdsCqzxWn7FL63ZaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722217792; a=rsa-sha256; cv=none; b=D32WjW0HASVEdOcREYLET+e7iWn7oEhzsW/ZFA5L4/2l37QgdQ1CpZTEpzWvkpMOd77cgX b8ipTCmNOH6bXObBc38b3g+e7dZHVVHUoiNbhipm20d+vBB5Hh2Y9ZrAoxOC81khQEdpC2 YRJzqXH3tlIAXAy/l3NjyyWqNIBDhpPs5GukMMJzuoQaSNGIjrXab9Kfu4mFupZfYJwSXk E8emRhb85ANZxzdhDMMERb4CgHIipDksBkgITiISKRPSDEIQCymoftRdfJHugmwyho9JX0 nOOgwI583DS41H7cTlMu1bYIE14nyVgaKFhC4oqKDkigxS+o/pledx562LPocg== 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=1722217792; 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=MqDJhLjJ0pzHHRQi0Kt52b9PuzmEtjizkqZor1LNcl0=; b=WIoWYKXY/ScwxJIkFN72IzIlpT3mLauzV1ouB+lenPCLXjIT2yIrzf0WoKe2Sij2UcDeD8 Xq3XSsMnSJzHlsDbSrNoyBcldUd5ccxO/B/lrPFJe7IaUglOmZm0JhMfN7rPPRJzbM+Pti Im9mc4eOWcR5S1bH8CU+jlkEn59LbVbSqoYbp0bfAIs00MxdcFSvIhGMIL94Kw7Bo6xNO9 vC5Aba2x1Z4IYVXm5vWyW2zH1AUx2L4e2iIGxAlnNGfG5iMLwEIA3UJsh6AArH0J2AgnaM TM7K13hSl/azLfFqhYedkt+QHSeyq/2itIxuUMUkef41uWu5ebTskEWUV/n/xw== 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 4WXLrw65bczFLV; Mon, 29 Jul 2024 01:49:52 +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 46T1nqgN091618; Mon, 29 Jul 2024 01:49:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46T1nqvV091615; Mon, 29 Jul 2024 01:49:52 GMT (envelope-from git) Date: Mon, 29 Jul 2024 01:49:52 GMT Message-Id: <202407290149.46T1nqvV091615@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: 13a1129d700c - main - vm: Remove kernel stack swapping support, part 1 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 13a1129d700cee67107c1a146f9c6e8bea372644 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=13a1129d700cee67107c1a146f9c6e8bea372644 commit 13a1129d700cee67107c1a146f9c6e8bea372644 Author: Mark Johnston AuthorDate: 2024-07-29 01:38:21 +0000 Commit: Mark Johnston CommitDate: 2024-07-29 01:38:21 +0000 vm: Remove kernel stack swapping support, part 1 - Disconnect the swapout daemon from the page daemon. - Remove swapout() and swapout_procs(). Tested by: pho Reviewed by: alc, imp, kib Differential Revision: https://reviews.freebsd.org/D46112 --- sys/vm/vm_pageout.c | 12 --- sys/vm/vm_pageout.h | 3 - sys/vm/vm_swapout.c | 239 +--------------------------------------------- sys/vm/vm_swapout_dummy.c | 10 -- 4 files changed, 1 insertion(+), 263 deletions(-) diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 61f02eeb2f11..cdc97637bbef 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -1764,24 +1764,12 @@ vm_pageout_inactive(struct vm_domain *vmd, int shortage, int *addl_shortage) vm_pagequeue_unlock(pq); } - /* - * Wakeup the swapout daemon if we didn't free the targeted number of - * pages. - */ - if (page_shortage > 0) - vm_swapout_run(); - /* * If the inactive queue scan fails repeatedly to meet its * target, kill the largest process. */ vm_pageout_mightbe_oom(vmd, page_shortage, starting_page_shortage); - /* - * Reclaim pages by swapping out idle processes, if configured to do so. - */ - vm_swapout_run_idle(); - /* * See the description of addl_page_shortage above. */ diff --git a/sys/vm/vm_pageout.h b/sys/vm/vm_pageout.h index cc6c718affb1..a6cdfafe743b 100644 --- a/sys/vm/vm_pageout.h +++ b/sys/vm/vm_pageout.h @@ -103,8 +103,5 @@ void vm_wait_severe(void); int vm_pageout_flush(vm_page_t *, int, int, int, int *, boolean_t *); void vm_pageout_oom(int shortage); -void vm_swapout_run(void); -void vm_swapout_run_idle(void); - #endif /* _KERNEL */ #endif /* _VM_VM_PAGEOUT_H_ */ diff --git a/sys/vm/vm_swapout.c b/sys/vm/vm_swapout.c index 20b975f252e9..85708d61d849 100644 --- a/sys/vm/vm_swapout.c +++ b/sys/vm/vm_swapout.c @@ -154,7 +154,6 @@ SYSCTL_INT(_vm, OID_AUTO, vmdaemon_timeout, CTLFLAG_RW, &vm_daemon_timeout, 0, "Time between vmdaemon runs"); -static int vm_pageout_req_swapout; /* XXX */ static int vm_daemon_needed; static struct mtx vm_daemon_mtx; /* Allow for use by vm_pageout before vm_daemon is initialized. */ @@ -165,12 +164,8 @@ static int swap_inprogress; /* Pending swap-ins done outside swapper. */ static int last_swapin; static void swapclear(struct proc *); -static int swapout(struct proc *); static void vm_swapout_map_deactivate_pages(vm_map_t, long); static void vm_swapout_object_deactivate(pmap_t, vm_object_t, long); -static void swapout_procs(int action); -static void vm_req_vmdaemon(int req); -static void vm_thread_swapout(struct thread *td); static void vm_swapout_object_deactivate_page(pmap_t pmap, vm_page_t m, bool unmap) @@ -322,49 +317,6 @@ vm_swapout_map_deactivate_pages(vm_map_t map, long desired) vm_map_unlock_read(map); } -/* - * Swap out requests - */ -#define VM_SWAP_NORMAL 1 -#define VM_SWAP_IDLE 2 - -void -vm_swapout_run(void) -{ - - if (vm_swap_enabled) - vm_req_vmdaemon(VM_SWAP_NORMAL); -} - -/* - * Idle process swapout -- run once per second when pagedaemons are - * reclaiming pages. - */ -void -vm_swapout_run_idle(void) -{ - static long lsec; - - if (!vm_swap_idle_enabled || time_second == lsec) - return; - vm_req_vmdaemon(VM_SWAP_IDLE); - lsec = time_second; -} - -static void -vm_req_vmdaemon(int req) -{ - static int lastrun = 0; - - mtx_lock(&vm_daemon_mtx); - vm_pageout_req_swapout |= req; - if ((ticks > (lastrun + hz)) || (ticks < lastrun)) { - wakeup(&vm_daemon_needed); - lastrun = ticks; - } - mtx_unlock(&vm_daemon_mtx); -} - static void vm_daemon(void) { @@ -372,7 +324,7 @@ vm_daemon(void) struct proc *p; struct thread *td; struct vmspace *vm; - int breakout, swapout_flags, tryagain, attempts; + int breakout, tryagain, attempts; #ifdef RACCT uint64_t rsize, ravailable; @@ -384,18 +336,7 @@ vm_daemon(void) mtx_lock(&vm_daemon_mtx); msleep(&vm_daemon_needed, &vm_daemon_mtx, PPAUSE, "psleep", vm_daemon_timeout); - swapout_flags = vm_pageout_req_swapout; - vm_pageout_req_swapout = 0; mtx_unlock(&vm_daemon_mtx); - if (swapout_flags != 0) { - /* - * Drain the per-CPU page queue batches as a deadlock - * avoidance measure. - */ - if ((swapout_flags & VM_SWAP_NORMAL) != 0) - vm_page_pqbatch_drain(); - swapout_procs(swapout_flags); - } /* * scan the processes for exceeding their rlimits or if @@ -520,36 +461,6 @@ again: } } -/* - * Allow a thread's kernel stack to be paged out. - */ -static void -vm_thread_swapout(struct thread *td) -{ - vm_page_t m; - vm_offset_t kaddr; - vm_pindex_t pindex; - int i, pages; - vm_object_t obj; - - cpu_thread_swapout(td); - kaddr = td->td_kstack; - pages = td->td_kstack_pages; - obj = vm_thread_kstack_size_to_obj(pages); - pindex = vm_kstack_pindex(kaddr, pages); - pmap_qremove(kaddr, pages); - VM_OBJECT_WLOCK(obj); - for (i = 0; i < pages; i++) { - m = vm_page_lookup(obj, pindex + i); - if (m == NULL) - panic("vm_thread_swapout: kstack already missing?"); - vm_page_dirty(m); - vm_page_xunbusy_unchecked(m); - vm_page_unwire(m, PQ_LAUNDRY); - } - VM_OBJECT_WUNLOCK(obj); -} - /* * Bring the kernel stack for a specified thread back in. */ @@ -773,100 +684,6 @@ swapper(void) } } -/* - * First, if any processes have been sleeping or stopped for at least - * "swap_idle_threshold1" seconds, they are swapped out. If, however, - * no such processes exist, then the longest-sleeping or stopped - * process is swapped out. Finally, and only as a last resort, if - * there are no sleeping or stopped processes, the longest-resident - * process is swapped out. - */ -static void -swapout_procs(int action) -{ - struct proc *p; - struct thread *td; - int slptime; - bool didswap, doswap; - - MPASS((action & (VM_SWAP_NORMAL | VM_SWAP_IDLE)) != 0); - - didswap = false; - sx_slock(&allproc_lock); - FOREACH_PROC_IN_SYSTEM(p) { - /* - * Filter out not yet fully constructed processes. Do - * not swap out held processes. Avoid processes which - * are system, exiting, execing, traced, already swapped - * out or are in the process of being swapped in or out. - */ - PROC_LOCK(p); - if (p->p_state != PRS_NORMAL || p->p_lock != 0 || (p->p_flag & - (P_SYSTEM | P_WEXIT | P_INEXEC | P_STOPPED_SINGLE | - P_TRACED | P_SWAPPINGOUT | P_SWAPPINGIN | P_INMEM)) != - P_INMEM) { - PROC_UNLOCK(p); - continue; - } - - /* - * Further consideration of this process for swap out - * requires iterating over its threads. We release - * allproc_lock here so that process creation and - * destruction are not blocked while we iterate. - * - * To later reacquire allproc_lock and resume - * iteration over the allproc list, we will first have - * to release the lock on the process. We place a - * hold on the process so that it remains in the - * allproc list while it is unlocked. - */ - _PHOLD_LITE(p); - sx_sunlock(&allproc_lock); - - /* - * Do not swapout a realtime process. - * Guarantee swap_idle_threshold1 time in memory. - * If the system is under memory stress, or if we are - * swapping idle processes >= swap_idle_threshold2, - * then swap the process out. - */ - doswap = true; - FOREACH_THREAD_IN_PROC(p, td) { - thread_lock(td); - slptime = (ticks - td->td_slptick) / hz; - if (PRI_IS_REALTIME(td->td_pri_class) || - slptime < swap_idle_threshold1 || - !thread_safetoswapout(td) || - ((action & VM_SWAP_NORMAL) == 0 && - slptime < swap_idle_threshold2)) - doswap = false; - thread_unlock(td); - if (!doswap) - break; - } - if (doswap && swapout(p) == 0) - didswap = true; - - PROC_UNLOCK(p); - if (didswap) { - sx_xlock(&allproc_lock); - swapped_cnt++; - sx_downgrade(&allproc_lock); - } else - sx_slock(&allproc_lock); - PRELE(p); - } - sx_sunlock(&allproc_lock); - - /* - * If we swapped something out, and another process needed memory, - * then wakeup the sched process. - */ - if (didswap) - wakeup(&proc0); -} - static void swapclear(struct proc *p) { @@ -896,57 +713,3 @@ swapclear(struct proc *p) p->p_flag &= ~(P_SWAPPINGIN | P_SWAPPINGOUT); p->p_flag |= P_INMEM; } - -static int -swapout(struct proc *p) -{ - struct thread *td; - - PROC_LOCK_ASSERT(p, MA_OWNED); - - /* - * The states of this process and its threads may have changed - * by now. Assuming that there is only one pageout daemon thread, - * this process should still be in memory. - */ - KASSERT((p->p_flag & (P_INMEM | P_SWAPPINGOUT | P_SWAPPINGIN)) == - P_INMEM, ("swapout: lost a swapout race?")); - - /* - * Remember the resident count. - */ - p->p_vmspace->vm_swrss = vmspace_resident_count(p->p_vmspace); - - /* - * Check and mark all threads before we proceed. - */ - p->p_flag &= ~P_INMEM; - p->p_flag |= P_SWAPPINGOUT; - FOREACH_THREAD_IN_PROC(p, td) { - thread_lock(td); - if (!thread_safetoswapout(td)) { - thread_unlock(td); - swapclear(p); - return (EBUSY); - } - td->td_flags &= ~TDF_INMEM; - TD_SET_SWAPPED(td); - thread_unlock(td); - } - td = FIRST_THREAD_IN_PROC(p); - ++td->td_ru.ru_nswap; - PROC_UNLOCK(p); - - /* - * This list is stable because all threads are now prevented from - * running. The list is only modified in the context of a running - * thread in this process. - */ - FOREACH_THREAD_IN_PROC(p, td) - vm_thread_swapout(td); - - PROC_LOCK(p); - p->p_flag &= ~P_SWAPPINGOUT; - p->p_swtick = ticks; - return (0); -} diff --git a/sys/vm/vm_swapout_dummy.c b/sys/vm/vm_swapout_dummy.c index bf0fd7b5aa5d..0e0a268c8c46 100644 --- a/sys/vm/vm_swapout_dummy.c +++ b/sys/vm/vm_swapout_dummy.c @@ -91,16 +91,6 @@ SYSCTL_INT(_vm, OID_AUTO, swap_idle_enabled, CTLFLAG_RD, &vm_swap_idle_enabled, 0, "Allow swapout on idle criteria"); -void -vm_swapout_run(void) -{ -} - -void -vm_swapout_run_idle(void) -{ -} - void faultin(struct proc *p) {