Index: head/sys/vm/device_pager.c =================================================================== --- head/sys/vm/device_pager.c +++ head/sys/vm/device_pager.c @@ -347,8 +347,7 @@ */ page = vm_page_getfake(paddr, memattr); VM_OBJECT_WLOCK(object); - if (vm_page_replace(page, object, (*mres)->pindex) != *mres) - panic("old_dev_pager_fault: invalid page replacement"); + vm_page_replace_checked(page, object, (*mres)->pindex, *mres); vm_page_lock(*mres); vm_page_free(*mres); vm_page_unlock(*mres); Index: head/sys/vm/sg_pager.c =================================================================== --- head/sys/vm/sg_pager.c +++ head/sys/vm/sg_pager.c @@ -188,8 +188,7 @@ page = vm_page_getfake(paddr, memattr); VM_OBJECT_WLOCK(object); TAILQ_INSERT_TAIL(&object->un_pager.sgp.sgp_pglist, page, plinks.q); - if (vm_page_replace(page, object, offset) != m[0]) - panic("sg_pager_getpages: invalid place replacement"); + vm_page_replace_checked(page, object, offset, m[0]); m[0] = page; page->valid = VM_PAGE_BITS_ALL; Index: head/sys/vm/vm_page.h =================================================================== --- head/sys/vm/vm_page.h +++ head/sys/vm/vm_page.h @@ -678,5 +678,20 @@ m->dirty = 0; } +static inline void +vm_page_replace_checked(vm_page_t mnew, vm_object_t object, vm_pindex_t pindex, + vm_page_t mold) +{ + vm_page_t mret; + + mret = vm_page_replace(mnew, object, pindex); + KASSERT(mret == mold, + ("invalid page replacement, mold=%p, mret=%p", mold, mret)); + + /* Unused if !INVARIANTS. */ + (void)mold; + (void)mret; +} + #endif /* _KERNEL */ #endif /* !_VM_PAGE_ */