Index: vm/vm_pageout.c =================================================================== --- vm/vm_pageout.c (revision 236313) +++ vm/vm_pageout.c (working copy) @@ -116,6 +116,7 @@ static void vm_pageout_scan(int pass); struct proc *pageproc; +static struct thread *pagethread; static struct kproc_desc page_kp = { "pagedaemon", @@ -1558,6 +1559,7 @@ if (vm_pageout_full_stats_interval == 0) vm_pageout_full_stats_interval = vm_pageout_stats_interval * 4; + pagethread = curthread; swap_pager_swap_init(); pass = 0; /* @@ -1574,7 +1576,13 @@ if (vm_pages_needed && !vm_page_count_min()) { if (!vm_paging_needed()) vm_pages_needed = 0; + critical_enter(); + thread_lock(pagethread); + if (pagethread->td_flags & TDF_BORROWING) + sched_unlend_prio(pagethread, PRI_MAX); + thread_unlock(pagethread); wakeup(&cnt.v_free_count); + critical_exit(); } if (vm_pages_needed) { /* @@ -1614,6 +1622,22 @@ } /* + * Called by threads blocking on pagedaemon to lend their priority to + * pagedaemon while waiting for it to free pages. + */ +void +pagedaemon_lendprio(void) +{ + + if (curthread != pagethread) { + thread_lock(pagethread); + if (pagethread->td_priority > curthread->td_priority) + sched_lend_prio(pagethread, curthread->td_priority); + thread_unlock(pagethread); + } +} + +/* * Unless the free page queue lock is held by the caller, this function * should be regarded as advisory. Specifically, the caller should * not msleep() on &cnt.v_free_count following this function unless Index: vm/vm_pageout.h =================================================================== --- vm/vm_pageout.h (revision 236313) +++ vm/vm_pageout.h (working copy) @@ -94,6 +94,7 @@ * Signal pageout-daemon and wait for it. */ +void pagedaemon_lendprio(void); extern void pagedaemon_wakeup(void); #define VM_WAIT vm_wait() #define VM_WAITPFAULT vm_waitpfault() Index: vm/vm_page.c =================================================================== --- vm/vm_page.c (revision 236313) +++ vm/vm_page.c (working copy) @@ -1863,6 +1863,7 @@ vm_pages_needed = 1; wakeup(&vm_pages_needed); } + pagedaemon_lendprio(); msleep(&cnt.v_free_count, &vm_page_queue_free_mtx, PDROP | PVM, "vmwait", 0); } @@ -1887,6 +1888,7 @@ vm_pages_needed = 1; wakeup(&vm_pages_needed); } + pagedaemon_lendprio(); msleep(&cnt.v_free_count, &vm_page_queue_free_mtx, PDROP | PUSER, "pfault", 0); }