git: e8efee297c6d - main - radix_trie: avoid reloading radix node

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Fri, 23 Jun 2023 23:50:11 UTC
The branch main has been updated by dougm:

URL: https://cgit.FreeBSD.org/src/commit/?id=e8efee297c6db8b1adfa7e5a10cd5a340564cb7b

commit e8efee297c6db8b1adfa7e5a10cd5a340564cb7b
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2023-06-23 23:47:23 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2023-06-23 23:47:23 +0000

    radix_trie: avoid reloading radix node
    
    In the vm_radix:remove loop that searches for the last child, load
    that child once, without loading it again after the search is over.
    Change KASSERTS from index check to NULL node check.
    Reviewed by:    alc
    Differential Revision:  https://reviews.freebsd.org/D40721
---
 sys/kern/subr_pctrie.c |  2 +-
 sys/vm/vm_radix.c      | 11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c
index d4262e32be51..043c31ad9501 100644
--- a/sys/kern/subr_pctrie.c
+++ b/sys/kern/subr_pctrie.c
@@ -749,7 +749,7 @@ pctrie_remove(struct pctrie *ptree, uint64_t index, pctrie_free_t freefn)
 				if (tmp != NULL)
 					break;
 			}
-			KASSERT(i != PCTRIE_COUNT,
+			KASSERT(tmp != NULL,
 			    ("%s: invalid node configuration", __func__));
 			if (parent == NULL)
 				pctrie_root_store(ptree, tmp, PCTRIE_LOCKED);
diff --git a/sys/vm/vm_radix.c b/sys/vm/vm_radix.c
index 6848f0b2c30e..cc932a6cc80d 100644
--- a/sys/vm/vm_radix.c
+++ b/sys/vm/vm_radix.c
@@ -773,13 +773,14 @@ vm_radix_remove(struct vm_radix *rtree, vm_pindex_t index)
 			rnode->rn_count--;
 			if (rnode->rn_count > 1)
 				return (m);
-			for (i = 0; i < VM_RADIX_COUNT; i++)
-				if (vm_radix_node_load(&rnode->rn_child[i],
-				    LOCKED) != NULL)
+			for (i = 0; i < VM_RADIX_COUNT; i++) {
+				tmp = vm_radix_node_load(&rnode->rn_child[i],
+				    LOCKED);
+				if (tmp != NULL)
 					break;
-			KASSERT(i != VM_RADIX_COUNT,
+			}
+			KASSERT(tmp != NULL,
 			    ("%s: invalid node configuration", __func__));
-			tmp = vm_radix_node_load(&rnode->rn_child[i], LOCKED);
 			if (parent == NULL)
 				vm_radix_root_store(rtree, tmp, LOCKED);
 			else {