diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -1451,7 +1451,19 @@ pq = &vmd->vmd_pagequeues[PQ_INACTIVE]; vm_pagequeue_lock(pq); vm_pageout_init_scan(&ss, pq, marker, NULL, pq->pq_cnt); - while (page_shortage > 0 && (m = vm_pageout_next(&ss, true)) != NULL) { + while (page_shortage > 0) { + /* + * If we need to refill the scan batch queue, release any + * optimistically held object lock. + */ + if (object != NULL && ss.bq.bq_cnt == 0) { + VM_OBJECT_WUNLOCK(object); + object = NULL; + } + + m = vm_pageout_next(&ss, true); + if (m == NULL) + break; KASSERT((m->flags & PG_MARKER) == 0, ("marker page %p was dequeued", m));