From 497524bf7280284244d1206da3aabb105ee3b926 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 5 Apr 2011 21:36:12 -0700 Subject: [PATCH] kernel - Add shutdown method for vm.swapcache * Add shutdown methods for the swapcache to stop operations during a shutdown. If not stopped swapcache operations can extend beyond the device shutdown and cause a crash. --- sys/sys/eventhandler.h | 2 ++ sys/vm/vm_swapcache.c | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h index c334310f74..147c6fcaba 100644 --- a/sys/sys/eventhandler.h +++ b/sys/sys/eventhandler.h @@ -171,6 +171,8 @@ struct proc; typedef void (*shutdown_fn) (void *, int); #define SHUTDOWN_PRI_FIRST EVENTHANDLER_PRI_FIRST +#define SHUTDOWN_PRI_SECOND (EVENTHANDLER_PRI_FIRST + 1) +#define SHUTDOWN_PRI_THIRD (EVENTHANDLER_PRI_FIRST + 2) #define SHUTDOWN_PRI_DEFAULT EVENTHANDLER_PRI_ANY #define SHUTDOWN_PRI_DRIVER (EVENTHANDLER_PRI_ANY + 5000) #define SHUTDOWN_PRI_LAST EVENTHANDLER_PRI_LAST diff --git a/sys/vm/vm_swapcache.c b/sys/vm/vm_swapcache.c index e0e8a8afc4..f29164571a 100644 --- a/sys/vm/vm_swapcache.c +++ b/sys/vm/vm_swapcache.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include @@ -136,6 +137,19 @@ SYSCTL_QUAD(_vm_swapcache, OID_AUTO, write_count, #define SWAPMAX(adj) \ ((int64_t)vm_swap_max * (vm_swapcache_maxswappct + (adj)) / 100) +/* + * When shutting down the machine we want to stop swapcache operation + * immediately so swap is not accessed after devices have been shuttered. + */ +static void +shutdown_swapcache(void *arg __unused) +{ + vm_swapcache_read_enable = 0; + vm_swapcache_data_enable = 0; + vm_swapcache_meta_enable = 0; + wakeup(&vm_swapcache_sleep); /* shortcut 5-second wait */ +} + /* * vm_swapcached is the high level pageout daemon. * @@ -153,7 +167,10 @@ vm_swapcached_thread(void) * Thread setup */ curthread->td_flags |= TDF_SYSTHREAD; - + EVENTHANDLER_REGISTER(shutdown_pre_sync, shutdown_kproc, + swapcached_thread, SHUTDOWN_PRI_FIRST); + EVENTHANDLER_REGISTER(shutdown_pre_sync, shutdown_swapcache, + NULL, SHUTDOWN_PRI_SECOND); lwkt_gettoken(&vm_token); crit_enter(); @@ -178,6 +195,11 @@ vm_swapcached_thread(void) lwkt_reltoken(&vmobj_token); for (;;) { + /* + * Handle shutdown + */ + kproc_suspend_loop(); + /* * Check every 5 seconds when not enabled or if no swap * is present. -- 2.41.0