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 @@ -1851,9 +1851,6 @@ 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 @@ */ 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); } diff --git a/sys/vm/vm_radix.h b/sys/vm/vm_radix.h --- a/sys/vm/vm_radix.h +++ b/sys/vm/vm_radix.h @@ -69,6 +69,26 @@ 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. *