git: 7458fac87831 - main - pctrie: simplify lookup_node
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 14 Jun 2025 19:33:07 UTC
The branch main has been updated by dougm:
URL: https://cgit.FreeBSD.org/src/commit/?id=7458fac87831d922c25b981097bfc428f6256faa
commit 7458fac87831d922c25b981097bfc428f6256faa
Author: Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2025-06-14 19:32:08 +0000
Commit: Doug Moore <dougm@FreeBSD.org>
CommitDate: 2025-06-14 19:32:08 +0000
pctrie: simplify lookup_node
Change _pctrie_lookup_node to simplify it, avoiding lookup up the root
node when it's already been traversed.
Reviewed by: alc
Differential Revision: https://reviews.freebsd.org/D50750
---
sys/kern/subr_pctrie.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c
index cb813cfbd847..e8098c6052e3 100644
--- a/sys/kern/subr_pctrie.c
+++ b/sys/kern/subr_pctrie.c
@@ -489,29 +489,28 @@ _pctrie_lookup_node(struct pctrie *ptree, struct pctrie_node *node,
struct pctrie_node *parent;
int slot;
+ parent = node;
+ if (parent == NULL)
+ node = pctrie_root_load(ptree, smr, access);
+
/*
* Climb the search path to find the lowest node from which to start the
* search for a value matching 'index'.
*/
- while (node != NULL) {
- KASSERT(access == PCTRIE_SMR || !powerof2(node->pn_popmap),
+ while (parent != NULL) {
+ KASSERT(access == PCTRIE_SMR || !powerof2(parent->pn_popmap),
("%s: freed node in iter path", __func__));
+ node = parent;
if (!pctrie_keybarr(node, index, &slot))
break;
- node = pctrie_parent(node);
- }
-
- if (node == NULL) {
- parent = NULL;
- node = pctrie_root_load(ptree, smr, access);
- } else {
- parent = node;
- node = pctrie_node_load(&node->pn_child[slot], smr, access);
+ parent = pctrie_parent(node);
}
/* Seek a node that matches index. */
while (!pctrie_isleaf(node) && !pctrie_keybarr(node, index, &slot)) {
parent = node;
+ KASSERT(access == PCTRIE_SMR || !powerof2(parent->pn_popmap),
+ ("%s: freed node in iter path", __func__));
node = pctrie_node_load(&node->pn_child[slot], smr, access);
}
*parent_out = parent;
@@ -527,9 +526,9 @@ pctrie_iter_lookup(struct pctrie_iter *it, uint64_t index)
{
struct pctrie_node *node;
- it->index = index;
node = _pctrie_lookup_node(it->ptree, it->node, index, &it->node,
NULL, PCTRIE_LOCKED);
+ it->index = index;
return (pctrie_match_value(node, index));
}
@@ -543,9 +542,9 @@ pctrie_iter_insert_lookup(struct pctrie_iter *it, uint64_t *val)
{
struct pctrie_node *node;
- it->index = *val;
node = _pctrie_lookup_node(it->ptree, it->node, *val, &it->node,
NULL, PCTRIE_LOCKED);
+ it->index = *val;
if (node == PCTRIE_NULL) {
if (it->node == NULL)
pctrie_node_store(pctrie_root(it->ptree),