git: 55b343f4f9bc - main - vm_pageout: Add a chicken switch for multithreaded PQ_INACTIVE scanning

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 09 Jan 2025 14:56:20 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=55b343f4f9bc586eba5e26a2524a35f04dd60c65

commit 55b343f4f9bc586eba5e26a2524a35f04dd60c65
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-01-09 14:54:10 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-01-09 14:54:10 +0000

    vm_pageout: Add a chicken switch for multithreaded PQ_INACTIVE scanning
    
    Right now we have the vm.pageout_cpus_per_thread tunable which controls
    the number of threads to start up per CPU per NUMA domain, but after
    booting, it's not possible to disable multi-threaded scanning.
    
    There is at least one workload where this mechanism doesn't work well;
    let's make it possible to disable it without a reboot, to simplify
    troubleshooting.
    
    Reviewed by:    dougm, kib
    MFC after:      2 weeks
    Sponsored by:   Klara, Inc.
    Sponsored by:   Modirum MDPay
    Differential Revision:  https://reviews.freebsd.org/D48377
---
 sys/vm/vm_page.c      | 1 +
 sys/vm/vm_pageout.c   | 9 +++++++--
 sys/vm/vm_pagequeue.h | 5 +++--
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
index f042d4767b36..ba22c7f97f2f 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -461,6 +461,7 @@ vm_page_domain_init(int domain)
 	vmd->vmd_free_count = 0;
 	vmd->vmd_segs = 0;
 	vmd->vmd_oom = false;
+	vmd->vmd_helper_threads_enabled = true;
 	for (i = 0; i < PQ_COUNT; i++) {
 		pq = &vmd->vmd_pagequeues[i];
 		TAILQ_INIT(&pq->pq_pl);
diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c
index d26e04f60c00..e2efa11842b5 100644
--- a/sys/vm/vm_pageout.c
+++ b/sys/vm/vm_pageout.c
@@ -1644,8 +1644,9 @@ vm_pageout_inactive_dispatch(struct vm_domain *vmd, int shortage)
 	 * If we have more work than we can do in a quarter of our interval, we
 	 * fire off multiple threads to process it.
 	 */
-	threads = vmd->vmd_inactive_threads;
-	if (threads > 1 && vmd->vmd_inactive_pps != 0 &&
+	if ((threads = vmd->vmd_inactive_threads) > 1 &&
+	    vmd->vmd_helper_threads_enabled &&
+	    vmd->vmd_inactive_pps != 0 &&
 	    shortage > vmd->vmd_inactive_pps / VM_INACT_SCAN_RATE / 4) {
 		vmd->vmd_inactive_shortage /= threads;
 		slop = shortage % threads;
@@ -2269,6 +2270,10 @@ vm_pageout_init_domain(int domain)
 	pidctrl_init_sysctl(&vmd->vmd_pid, SYSCTL_CHILDREN(oid));
 
 	vmd->vmd_inactive_threads = get_pageout_threads_per_domain(vmd);
+	SYSCTL_ADD_BOOL(NULL, SYSCTL_CHILDREN(vmd->vmd_oid), OID_AUTO,
+	    "pageout_helper_threads_enabled", CTLFLAG_RWTUN,
+	    &vmd->vmd_helper_threads_enabled, 0,
+	    "Enable multi-threaded inactive queue scanning");
 }
 
 static void
diff --git a/sys/vm/vm_pagequeue.h b/sys/vm/vm_pagequeue.h
index 23a3ea96d80c..72fd1bb47318 100644
--- a/sys/vm/vm_pagequeue.h
+++ b/sys/vm/vm_pagequeue.h
@@ -257,8 +257,9 @@ struct vm_domain {
 
 	/* Paging control variables, used within single threaded page daemon. */
 	struct pidctrl vmd_pid;		/* Pageout controller. */
-	bool vmd_oom;
-	u_int vmd_inactive_threads;
+	bool vmd_oom;			/* An OOM kill was requested. */
+	bool vmd_helper_threads_enabled;/* Use multiple threads to scan. */
+	u_int vmd_inactive_threads;	/* Number of extra helper threads. */
 	u_int vmd_inactive_shortage;		/* Per-thread shortage. */
 	blockcount_t vmd_inactive_running;	/* Number of inactive threads. */
 	blockcount_t vmd_inactive_starting;	/* Number of threads started. */