vm_radix: define vm_radix_insert_lookup_lt and use in vm_page_rename

Use the new pctrie combined lookup/insert.  This is an easy application
of the new facility.  There are other places where we do this for pages
that may need more plumbing to use combined lookup/insert.

Reviewed by:	kib (previous version), dougm, markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D45396
This commit is contained in:
Ryan Libby 2024-06-06 10:26:50 -07:00
parent 4472fd66d0
commit 7658d1532c
2 changed files with 21 additions and 4 deletions

View File

@ -1851,9 +1851,6 @@ vm_page_rename(vm_page_t m, vm_object_t new_object, vm_pindex_t new_pindex)
VM_OBJECT_ASSERT_WLOCKED(new_object);
KASSERT(m->ref_count != 0, ("vm_page_rename: page %p has no refs", m));
mpred = vm_radix_lookup_le(&new_object->rtree, new_pindex);
KASSERT(mpred == NULL || mpred->pindex != new_pindex,
("vm_page_rename: pindex already renamed"));
/*
* Create a custom version of vm_page_insert() which does not depend
@ -1862,7 +1859,7 @@ vm_page_rename(vm_page_t m, vm_object_t new_object, vm_pindex_t new_pindex)
*/
opidx = m->pindex;
m->pindex = new_pindex;
if (vm_radix_insert(&new_object->rtree, m)) {
if (vm_radix_insert_lookup_lt(&new_object->rtree, m, &mpred) != 0) {
m->pindex = opidx;
return (1);
}

View File

@ -69,6 +69,26 @@ vm_radix_insert(struct vm_radix *rtree, vm_page_t page)
return (VM_RADIX_PCTRIE_INSERT(&rtree->rt_trie, page));
}
/*
* Insert the page into the vm_radix tree with its pindex as the key. Panic if
* the pindex already exists. Return zero on success or a non-zero error on
* memory allocation failure. Set the out parameter mpred to the previous page
* in the tree as if found by a previous call to vm_radix_lookup_le with the
* new page pindex.
*/
static __inline int
vm_radix_insert_lookup_lt(struct vm_radix *rtree, vm_page_t page,
vm_page_t *mpred)
{
int error;
error = VM_RADIX_PCTRIE_INSERT_LOOKUP_LE(&rtree->rt_trie, page, mpred);
if (__predict_false(error == EEXIST))
panic("vm_radix_insert_lookup_lt: page already present, %p",
*mpred);
return (error);
}
/*
* Returns the value stored at the index assuming there is an external lock.
*