radix_trie: pass fewer params to node_get

Let node_get calculate it's own owner value. Don't pass the count
parameter, since it's always 2. Save 16 bytes in insert(). Move,
without modifying, slot and trimkey to handle use-before-declaration
problem.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D40723
This commit is contained in:
Doug Moore 2023-06-27 12:21:11 -05:00
parent 2e1665ff34
commit da72505f9c
2 changed files with 43 additions and 48 deletions

View File

@ -92,13 +92,29 @@ enum pctrie_access { PCTRIE_SMR, PCTRIE_LOCKED, PCTRIE_UNSERIALIZED };
static __inline void pctrie_node_store(smr_pctnode_t *p, void *val,
enum pctrie_access access);
/*
* Return the position in the array for a given level.
*/
static __inline int
pctrie_slot(uint64_t index, uint16_t level)
{
return ((index >> (level * PCTRIE_WIDTH)) & PCTRIE_MASK);
}
/* Computes the key (index) with the low-order 'level' radix-digits zeroed. */
static __inline uint64_t
pctrie_trimkey(uint64_t index, uint16_t level)
{
return (index & -PCTRIE_UNITLEVEL(level));
}
/*
* Allocate a node. Pre-allocation should ensure that the request
* will always be satisfied.
*/
static struct pctrie_node *
pctrie_node_get(struct pctrie *ptree, pctrie_alloc_t allocfn, uint64_t owner,
uint16_t count, uint16_t clevel)
pctrie_node_get(struct pctrie *ptree, pctrie_alloc_t allocfn, uint64_t index,
uint16_t clevel)
{
struct pctrie_node *node;
@ -116,8 +132,8 @@ pctrie_node_get(struct pctrie *ptree, pctrie_alloc_t allocfn, uint64_t owner,
PCTRIE_UNSERIALIZED);
node->pn_last = 0;
}
node->pn_owner = owner;
node->pn_count = count;
node->pn_owner = pctrie_trimkey(index, clevel + 1);
node->pn_count = 2;
node->pn_clev = clevel;
return (node);
}
@ -146,23 +162,6 @@ pctrie_node_put(struct pctrie *ptree, struct pctrie_node *node,
freefn(ptree, node);
}
/*
* Return the position in the array for a given level.
*/
static __inline int
pctrie_slot(uint64_t index, uint16_t level)
{
return ((index >> (level * PCTRIE_WIDTH)) & PCTRIE_MASK);
}
/* Computes the key (index) with the low-order 'level' radix-digits zeroed. */
static __inline uint64_t
pctrie_trimkey(uint64_t index, uint16_t level)
{
return (index & -PCTRIE_UNITLEVEL(level));
}
/*
* Fetch a node pointer from a slot.
*/
@ -376,8 +375,7 @@ pctrie_insert(struct pctrie *ptree, uint64_t *val, pctrie_alloc_t allocfn)
panic("%s: key %jx is already present",
__func__, (uintmax_t)index);
clev = pctrie_keydiff(*m, index);
tmp = pctrie_node_get(ptree, allocfn,
pctrie_trimkey(index, clev + 1), 2, clev);
tmp = pctrie_node_get(ptree, allocfn, index, clev);
if (tmp == NULL)
return (ENOMEM);
/* These writes are not yet visible due to ordering. */
@ -408,8 +406,7 @@ pctrie_insert(struct pctrie *ptree, uint64_t *val, pctrie_alloc_t allocfn)
*/
newind = node->pn_owner;
clev = pctrie_keydiff(newind, index);
tmp = pctrie_node_get(ptree, allocfn,
pctrie_trimkey(index, clev + 1), 2, clev);
tmp = pctrie_node_get(ptree, allocfn, index, clev);
if (tmp == NULL)
return (ENOMEM);
slot = pctrie_slot(newind, clev);

View File

@ -119,11 +119,27 @@ static smr_t vm_radix_smr;
static void vm_radix_node_store(smrnode_t *p, struct vm_radix_node *v,
enum vm_radix_access access);
/*
* Return the position in the array for a given level.
*/
static __inline int
vm_radix_slot(vm_pindex_t index, uint16_t level)
{
return ((index >> (level * VM_RADIX_WIDTH)) & VM_RADIX_MASK);
}
/* Computes the key (index) with the low-order 'level' radix-digits zeroed. */
static __inline vm_pindex_t
vm_radix_trimkey(vm_pindex_t index, uint16_t level)
{
return (index & -VM_RADIX_UNITLEVEL(level));
}
/*
* Allocate a radix node.
*/
static struct vm_radix_node *
vm_radix_node_get(vm_pindex_t owner, uint16_t count, uint16_t clevel)
vm_radix_node_get(vm_pindex_t index, uint16_t clevel)
{
struct vm_radix_node *rnode;
@ -141,8 +157,8 @@ vm_radix_node_get(vm_pindex_t owner, uint16_t count, uint16_t clevel)
NULL, UNSERIALIZED);
rnode->rn_last = 0;
}
rnode->rn_owner = owner;
rnode->rn_count = count;
rnode->rn_owner = vm_radix_trimkey(index, clevel + 1);
rnode->rn_count = 2;
rnode->rn_clev = clevel;
return (rnode);
}
@ -171,23 +187,6 @@ vm_radix_node_put(struct vm_radix_node *rnode, int8_t last)
uma_zfree_smr(vm_radix_node_zone, rnode);
}
/*
* Return the position in the array for a given level.
*/
static __inline int
vm_radix_slot(vm_pindex_t index, uint16_t level)
{
return ((index >> (level * VM_RADIX_WIDTH)) & VM_RADIX_MASK);
}
/* Computes the key (index) with the low-order 'level' radix-digits zeroed. */
static __inline vm_pindex_t
vm_radix_trimkey(vm_pindex_t index, uint16_t level)
{
return (index & -VM_RADIX_UNITLEVEL(level));
}
/*
* Fetch a node pointer from a slot in another node.
*/
@ -416,8 +415,7 @@ vm_radix_insert(struct vm_radix *rtree, vm_page_t page)
panic("%s: key %jx is already present",
__func__, (uintmax_t)index);
clev = vm_radix_keydiff(m->pindex, index);
tmp = vm_radix_node_get(vm_radix_trimkey(index,
clev + 1), 2, clev);
tmp = vm_radix_node_get(index, clev);
if (tmp == NULL)
return (ENOMEM);
/* These writes are not yet visible due to ordering. */
@ -447,7 +445,7 @@ vm_radix_insert(struct vm_radix *rtree, vm_page_t page)
*/
newind = rnode->rn_owner;
clev = vm_radix_keydiff(newind, index);
tmp = vm_radix_node_get(vm_radix_trimkey(index, clev + 1), 2, clev);
tmp = vm_radix_node_get(index, clev);
if (tmp == NULL)
return (ENOMEM);
slot = vm_radix_slot(newind, clev);