If the fast path unbusy in vm_page_replace() fails, slow path needs to

acquire the page lock, which recurses.  Avoid the recursion by reusing
the code from vm_page_remove() in a new helper
vm_page_xunbusy_maybelocked().

Reviewed by:	alc
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Konstantin Belousov 2016-06-01 20:39:00 +00:00
parent d1900df6cc
commit e5f0191f20

View File

@ -759,6 +759,22 @@ vm_page_trysbusy(vm_page_t m)
}
}
static void
vm_page_xunbusy_maybelocked(vm_page_t m)
{
bool lockacq;
vm_page_assert_xbusied(m);
lockacq = !mtx_owned(vm_page_lockptr(m));
if (lockacq)
vm_page_lock(m);
vm_page_flash(m);
atomic_store_rel_int(&m->busy_lock, VPB_UNBUSIED);
if (lockacq)
vm_page_unlock(m);
}
/*
* vm_page_xunbusy_hard:
*
@ -1197,25 +1213,14 @@ void
vm_page_remove(vm_page_t m)
{
vm_object_t object;
boolean_t lockacq;
if ((m->oflags & VPO_UNMANAGED) == 0)
vm_page_lock_assert(m, MA_OWNED);
vm_page_assert_locked(m);
if ((object = m->object) == NULL)
return;
VM_OBJECT_ASSERT_WLOCKED(object);
if (vm_page_xbusied(m)) {
lockacq = FALSE;
if ((m->oflags & VPO_UNMANAGED) != 0 &&
!mtx_owned(vm_page_lockptr(m))) {
lockacq = TRUE;
vm_page_lock(m);
}
vm_page_flash(m);
atomic_store_rel_int(&m->busy_lock, VPB_UNBUSIED);
if (lockacq)
vm_page_unlock(m);
}
if (vm_page_xbusied(m))
vm_page_xunbusy_maybelocked(m);
/*
* Now remove from the object's list of backed pages.
@ -1340,7 +1345,7 @@ vm_page_replace(vm_page_t mnew, vm_object_t object, vm_pindex_t pindex)
TAILQ_REMOVE(&object->memq, mold, listq);
mold->object = NULL;
vm_page_xunbusy(mold);
vm_page_xunbusy_maybelocked(mold);
/*
* The object's resident_page_count does not change because we have