diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -64,7 +64,6 @@ * Resident memory management module. */ -#include #include "opt_vm.h" #include @@ -2110,6 +2109,13 @@ if (vm_object_reserv(object) && (m = vm_reserv_alloc_page(object, pindex, domain, req, pages)) != NULL) { + /* + * The page may already have been allocated from and freed to + * this reservation without taking a trip through the physical + * memory allocator, so we potentially need to remove it from + * the page queues. + */ + vm_page_dequeue(m); goto found; } #endif @@ -2118,6 +2124,7 @@ m = uma_zalloc(vmd->vmd_pgcache[VM_FREEPOOL_DEFAULT].zone, M_NOWAIT | M_NOVM); if (m != NULL) { + vm_page_dequeue(m); flags |= PG_PCPU_CACHE; goto found; } @@ -2151,7 +2158,6 @@ * At this point we had better have found a good page. */ found: - vm_page_dequeue(m); vm_page_alloc_check(m); /* @@ -2473,7 +2479,6 @@ } found: - vm_page_dequeue(m); vm_page_alloc_check(m); /* @@ -2645,7 +2650,6 @@ if ((req & VM_ALLOC_WIRED) != 0) vm_wire_add(npages); for (m = m_ret; m < &m_ret[npages]; m++) { - vm_page_dequeue(m); vm_page_alloc_check(m); /* @@ -2738,6 +2742,8 @@ vm_domain_free_lock(vmd); for (i = 0; i < cnt; i++) { m = (vm_page_t)store[i]; + if (pgcache->pool == VM_FREEPOOL_DEFAULT) + vm_page_dequeue(m); vm_phys_free_pages(m, pgcache->pool, 0); } vm_domain_free_unlock(vmd); @@ -4130,6 +4136,7 @@ uma_zfree(zone, m); return; } + vm_page_dequeue(m); vm_domain_free_lock(vmd); vm_phys_free_pages(m, m->pool, 0); vm_domain_free_unlock(vmd); diff --git a/sys/vm/vm_reserv.c b/sys/vm/vm_reserv.c --- a/sys/vm/vm_reserv.c +++ b/sys/vm/vm_reserv.c @@ -478,7 +478,11 @@ } vmd = VM_DOMAIN(rv->domain); if (rv->popcnt == 0) { + vm_page_t m; + vm_reserv_remove(rv); + for (m = rv->pages; m < rv->pages + VM_LEVEL_0_NPAGES; m++) + vm_page_dequeue(m); vm_domain_free_lock(vmd); vm_phys_free_pages(rv->pages, VM_FREEPOOL_DEFAULT, VM_LEVEL_0_ORDER); @@ -952,6 +956,8 @@ } /* Free unused pages from pos0 to pos. */ pos1 = pos; + for (int i = pos0; i < pos1; i++) + vm_page_dequeue(&rv->pages[i]); vm_domain_free_lock(VM_DOMAIN(rv->domain)); vm_phys_enqueue_contig(&rv->pages[pos0], VM_FREEPOOL_DEFAULT, pos1 - pos0);