⬢ DragonFlyBSD Kernel Audit
DF-2840 / fix.diff
← back to finding ↓ download raw
--- sys/vm/vm_swapcache.c	2026-06-29 12:51:19.000000000 +0000
+++ /tmp/opencode/v26/fixtree/sys/vm/vm_swapcache.c	2026-10-24 16:33:07.789715562 +0000
@@ -152,8 +152,14 @@
 SYSCTL_QUAD(_vm_swapcache, OID_AUTO, cleanperobj,
 	CTLFLAG_RW, &vm_swapcache_cleanperobj, 0, "");
 
+/*
+ * DF-2840: clamp the administrator-settable percentage at consumption;
+ * a negative maxswappct made SWAPMAX negative and permanently wedged the
+ * daemon in SWAPC_CLEANING.
+ */
 #define SWAPMAX(adj)	\
-	((int64_t)vm_swap_max * (vm_swapcache_maxswappct + (adj)) / 100)
+	((int64_t)vm_swap_max * \
+	 (imax(0, imin(100, vm_swapcache_maxswappct)) + (adj)) / 100)
 
 /*
  * When shutting down the machine we want to stop swapcache operation
@@ -269,9 +275,15 @@
 		 * for the initial load-in.
 		 */
 		if (vm_swapcache_curburst < vm_swapcache_maxburst) {
-			vm_swapcache_curburst += vm_swapcache_accrate / 10;
+			int64_t accrate = vm_swapcache_accrate;
+
+			if (accrate < 0)	/* DF-2840 */
+				accrate = 0;
+			vm_swapcache_curburst += accrate / 10;
 			if (vm_swapcache_curburst > vm_swapcache_maxburst)
 				vm_swapcache_curburst = vm_swapcache_maxburst;
+			if (vm_swapcache_curburst < 0)
+				vm_swapcache_curburst = 0;
 		}
 
 		/*