Index: vm/vm_pageout.h =================================================================== --- vm/vm_pageout.h +++ vm/vm_pageout.h @@ -76,7 +76,6 @@ extern int vm_page_max_wired; extern int vm_pageout_deficit; extern int vm_pageout_page_count; -extern bool vm_pageout_wanted; extern bool vm_pages_needed; #define VM_OOM_MEM 1 Index: vm/vm_pageout.c =================================================================== --- vm/vm_pageout.c +++ vm/vm_pageout.c @@ -150,7 +150,7 @@ int vm_pageout_deficit; /* Estimated number of pages deficit */ u_int vm_pageout_wakeup_thresh; static int vm_pageout_oom_seq = 12; -bool vm_pageout_wanted; /* Event on which pageout daemon sleeps */ +static bool vm_pageout_wanted; /* Event on which pageout daemon sleeps */ bool vm_pages_needed; /* Are threads waiting for free pages? */ /* Pending request for dirty page laundering. */ @@ -1806,13 +1806,11 @@ * target. Otherwise, we may be awakened over and over again, * wasting CPU time. */ - if (vm_pageout_wanted && target_met) - vm_pageout_wanted = false; /* * Might the page daemon receive a wakeup call? */ - if (vm_pageout_wanted) { + if (!target_met) { /* * No. Either vm_pageout_wanted was set by another * thread during the previous scan, which must have @@ -1824,10 +1822,10 @@ * try again later. */ mtx_unlock(&vm_page_queue_free_mtx); - if (pass >= 1) - pause("pwait", hz / VM_INACT_SCAN_RATE); - pass++; - } else { + pause("pwait", hz / VM_INACT_SCAN_RATE); + MPASS(pass == 1); + } else if ((pass == 0 && vm_pageout_wanted) || + vm_pages_needed) { /* * Yes. If threads are still sleeping in VM_WAIT * then we immediately start a new scan. Otherwise, @@ -1834,11 +1832,11 @@ * sleep until the next wakeup or until pages need to * have their reference stats updated. */ - if (vm_pages_needed) { - mtx_unlock(&vm_page_queue_free_mtx); - if (pass == 0) - pass++; - } else if (mtx_sleep(&vm_pageout_wanted, + mtx_unlock(&vm_page_queue_free_mtx); + pass = 1; + } else { + vm_pageout_wanted = false; + if (mtx_sleep(&vm_pageout_wanted, &vm_page_queue_free_mtx, PDROP | PVM, "psleep", hz) == 0) { VM_CNT_INC(v_pdwakeups); @@ -1955,8 +1953,12 @@ mtx_assert(&vm_page_queue_free_mtx, MA_NOTOWNED); if (!vm_pageout_wanted && curthread->td_proc != pageproc) { - vm_pageout_wanted = true; - wakeup(&vm_pageout_wanted); + mtx_lock(&vm_page_queue_free_mtx); + if (!vm_pageout_wanted) { + vm_pageout_wanted = true; + wakeup(&vm_pageout_wanted); + } + mtx_unlock(&vm_page_queue_free_mtx); } } @@ -1977,7 +1979,7 @@ * Thus, deliver a potentially spurious wakeup to ensure that the page * daemon has been notified of the shortage. */ - if (!vm_pageout_wanted || !vm_pages_needed) { + if (!vm_pageout_wanted) { vm_pageout_wanted = true; wakeup(&vm_pageout_wanted); }