diff --git a/share/man/man9/EVENTHANDLER.9 b/share/man/man9/EVENTHANDLER.9 index 3ca835d..bf5d259 100644 --- a/share/man/man9/EVENTHANDLER.9 +++ b/share/man/man9/EVENTHANDLER.9 @@ -213,6 +213,8 @@ Callbacks invoked at shutdown time, before file systems are synchronized. Callbacks invoked at shutdown time, after all file systems are synchronized. .It Vt shutdown_final Callbacks invoked just before halting the system. +.It Vt vfs_highdirtybuf +Callbacks invoked when amount of dirty buffers is high. .It Vt vm_lowmem Callbacks invoked when virtual memory is low. .It Vt watchdog_list diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 2a91b2c..18d8497 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -2167,9 +2167,11 @@ SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start, &buf_kp); static int buf_do_flush(struct vnode *vp) { - int flushed; + int flushed = 0; + + EVENTHANDLER_INVOKE(vfs_highdirtybuf, vp, &flushed); - flushed = flushbufqueues(vp, QUEUE_DIRTY, 0); + flushed += flushbufqueues(vp, QUEUE_DIRTY, 0); /* The list empty check here is slightly racy */ if (!TAILQ_EMPTY(&bufqueues[QUEUE_DIRTY_GIANT])) { mtx_lock(&Giant); diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h index 6d07cf6..6ab2bc7 100644 --- a/sys/sys/eventhandler.h +++ b/sys/sys/eventhandler.h @@ -32,6 +32,7 @@ #include #include #include +#include #include struct eventhandler_entry { @@ -183,6 +184,10 @@ typedef void (*power_change_fn)(void *); EVENTHANDLER_DECLARE(power_resume, power_change_fn); EVENTHANDLER_DECLARE(power_suspend, power_change_fn); +/* High dirty buffer event */ +typedef void (*vfs_highdirtybuf_handler_t)(void *, struct vnode *, int *); +EVENTHANDLER_DECLARE(vfs_highdirtybuf, vfs_highdirtybuf_handler_t); + /* Low memory event */ typedef void (*vm_lowmem_handler_t)(void *, int); #define LOWMEM_PRI_DEFAULT EVENTHANDLER_PRI_FIRST