From 855a310fcbc1c2052b2b705e2f67b16cb91fc876 Mon Sep 17 00:00:00 2001 From: Jeff Roberson Date: Thu, 21 Nov 2002 09:17:56 +0000 Subject: [PATCH] - Add an event that is triggered when the system is low on memory. This is intended to be used by significant memory consumers so that they may drain some of their caches. Inspired by: phk Approved by: re Tested on: x86, alpha --- sys/sys/eventhandler.h | 4 ++++ sys/vm/vm_pageout.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h index 59b1fc2cff9..13782179d73 100644 --- a/sys/sys/eventhandler.h +++ b/sys/sys/eventhandler.h @@ -179,5 +179,9 @@ typedef void (*idle_eventhandler_t)(void *, int); #define IDLE_PRI_LAST 20000 EVENTHANDLER_FAST_DECLARE(idle_event, idle_eventhandler_t); +/* Low memory event */ +typedef void (*vm_lowmem_handler_t)(void *, int); +#define LOWMEM_PRI_DEFAULT 0 +EVENTHANDLER_DECLARE(vm_lowmem, vm_lowmem_handler_t); #endif /* SYS_EVENTHANDLER_H */ diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 1f024e7cf83..ec43082a238 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -677,11 +678,18 @@ vm_pageout_scan(int pass) struct thread *td; GIANT_REQUIRED; + /* + * Decrease registered cache sizes. + */ + EVENTHANDLER_INVOKE(vm_lowmem, 0); + /* + * We do this explicitly after the caches have been drained above. + */ + uma_reclaim(); /* * Do whatever cleanup that the pmap code can. */ vm_pageout_pmap_collect(); - uma_reclaim(); addl_page_shortage_init = vm_pageout_deficit; vm_pageout_deficit = 0;