Subject: sysctl to disable swapout
To: None <tech-kern@netbsd.org>
From: Andrew Doran <ad@netbsd.org>
List: tech-kern
Date: 05/28/2007 22:45:46
Hi,

Any comments on the following? I'm suspicious of the way swapout works with
MP systems on the netbsd-4 branch and would like to have a way to disable
it.

Thanks,
Andrew

Index: uvm/uvm.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm.h,v
retrieving revision 1.49
diff -u -r1.49 uvm.h
--- uvm/uvm.h	21 Feb 2007 23:48:16 -0000	1.49
+++ uvm/uvm.h	28 May 2007 21:40:03 -0000
@@ -115,10 +115,10 @@
 	kcondvar_t scheduler_cv;
 	kmutex_t scheduler_mutex;
 	bool scheduler_kicked;
+	int swap_enabled;
 
 	/* kernel object: to support anonymous pageable kernel memory */
 	struct uvm_object *kernel_object;
-
 };
 
 #endif /* _KERNEL */
Index: uvm/uvm_pdaemon.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_pdaemon.c,v
retrieving revision 1.84
diff -u -r1.84 uvm_pdaemon.c
--- uvm/uvm_pdaemon.c	22 Feb 2007 06:05:01 -0000	1.84
+++ uvm/uvm_pdaemon.c	28 May 2007 21:40:04 -0000
@@ -865,7 +865,8 @@
 	 * we need to unlock the page queues for this.
 	 */
 
-	if (uvmexp.free < uvmexp.freetarg && uvmexp.nswapdev != 0) {
+	if (uvmexp.free < uvmexp.freetarg && uvmexp.nswapdev != 0 &&
+	    uvm.swap_enabled) {
 		uvmexp.pdswout++;
 		UVMHIST_LOG(pdhist,"  free %d < target %d: swapout",
 		    uvmexp.free, uvmexp.freetarg, 0, 0);
Index: uvm/uvm_swap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_swap.c,v
retrieving revision 1.124
diff -u -r1.124 uvm_swap.c
--- uvm/uvm_swap.c	22 Apr 2007 08:30:02 -0000	1.124
+++ uvm/uvm_swap.c	28 May 2007 21:40:04 -0000
@@ -59,6 +59,7 @@
 #include <sys/syscallargs.h>
 #include <sys/swap.h>
 #include <sys/kauth.h>
+#include <sys/sysctl.h>
 
 #include <uvm/uvm.h>
 
@@ -285,7 +286,14 @@
 	 * done!
 	 */
 	uvm.swap_running = true;
+	uvm.swap_enabled = 1;
 	UVMHIST_LOG(pdhist, "<- done", 0, 0, 0, 0);
+
+        sysctl_createv(NULL, 0, NULL, NULL,
+            CTLFLAG_READWRITE,
+            CTLTYPE_INT, "swapout",
+            SYSCTL_DESCR("Set 0 to disable swapping of kernel stacks"),
+            NULL, 0, &uvm.swap_enabled, 0, CTL_VM, CTL_CREATE, CTL_EOL);
 }
 
 /*