Commit 4dd6c098 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

radix-tree: rename indirect_to_ptr() to entry_to_node()

Mirrors the earlier commit introducing node_to_entry().

Also change the type returned to be a struct radix_tree_node pointer.
That lets us simplify a couple of places in the radix tree shrink &
extend paths where we could convert an entry into a pointer, modify the
node, then convert the pointer back into an entry.
Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a4db4dce
...@@ -442,7 +442,7 @@ radix_tree_chunk_size(struct radix_tree_iter *iter) ...@@ -442,7 +442,7 @@ radix_tree_chunk_size(struct radix_tree_iter *iter)
return (iter->next_index - iter->index) >> iter_shift(iter); return (iter->next_index - iter->index) >> iter_shift(iter);
} }
static inline void *indirect_to_ptr(void *ptr) static inline struct radix_tree_node *entry_to_node(void *ptr)
{ {
return (void *)((unsigned long)ptr & ~RADIX_TREE_INTERNAL_NODE); return (void *)((unsigned long)ptr & ~RADIX_TREE_INTERNAL_NODE);
} }
...@@ -469,7 +469,7 @@ radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags) ...@@ -469,7 +469,7 @@ radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags)
return NULL; return NULL;
while (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) && while (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) &&
radix_tree_is_indirect_ptr(slot[1])) { radix_tree_is_indirect_ptr(slot[1])) {
if (indirect_to_ptr(slot[1]) == canon) { if (entry_to_node(slot[1]) == canon) {
iter->tags >>= 1; iter->tags >>= 1;
iter->index = __radix_tree_iter_add(iter, 1); iter->index = __radix_tree_iter_add(iter, 1);
slot++; slot++;
...@@ -499,13 +499,11 @@ radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags) ...@@ -499,13 +499,11 @@ radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags)
if (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) && if (IS_ENABLED(CONFIG_RADIX_TREE_MULTIORDER) &&
radix_tree_is_indirect_ptr(*slot)) { radix_tree_is_indirect_ptr(*slot)) {
if (indirect_to_ptr(*slot) == canon) if (entry_to_node(*slot) == canon)
continue; continue;
else {
iter->next_index = iter->index; iter->next_index = iter->index;
break; break;
} }
}
if (likely(*slot)) if (likely(*slot))
return slot; return slot;
......
...@@ -230,13 +230,13 @@ static void dump_node(struct radix_tree_node *node, unsigned long index) ...@@ -230,13 +230,13 @@ static void dump_node(struct radix_tree_node *node, unsigned long index)
if (is_sibling_entry(node, entry)) { if (is_sibling_entry(node, entry)) {
pr_debug("radix sblng %p offset %ld val %p indices %ld-%ld\n", pr_debug("radix sblng %p offset %ld val %p indices %ld-%ld\n",
entry, i, entry, i,
*(void **)indirect_to_ptr(entry), *(void **)entry_to_node(entry),
first, last); first, last);
} else if (!radix_tree_is_indirect_ptr(entry)) { } else if (!radix_tree_is_indirect_ptr(entry)) {
pr_debug("radix entry %p offset %ld indices %ld-%ld\n", pr_debug("radix entry %p offset %ld indices %ld-%ld\n",
entry, i, first, last); entry, i, first, last);
} else { } else {
dump_node(indirect_to_ptr(entry), first); dump_node(entry_to_node(entry), first);
} }
} }
} }
...@@ -249,7 +249,7 @@ static void radix_tree_dump(struct radix_tree_root *root) ...@@ -249,7 +249,7 @@ static void radix_tree_dump(struct radix_tree_root *root)
root->gfp_mask >> __GFP_BITS_SHIFT); root->gfp_mask >> __GFP_BITS_SHIFT);
if (!radix_tree_is_indirect_ptr(root->rnode)) if (!radix_tree_is_indirect_ptr(root->rnode))
return; return;
dump_node(indirect_to_ptr(root->rnode), 0); dump_node(entry_to_node(root->rnode), 0);
} }
#endif #endif
...@@ -422,7 +422,7 @@ static unsigned radix_tree_load_root(struct radix_tree_root *root, ...@@ -422,7 +422,7 @@ static unsigned radix_tree_load_root(struct radix_tree_root *root,
*nodep = node; *nodep = node;
if (likely(radix_tree_is_indirect_ptr(node))) { if (likely(radix_tree_is_indirect_ptr(node))) {
node = indirect_to_ptr(node); node = entry_to_node(node);
*maxindex = node_maxindex(node); *maxindex = node_maxindex(node);
return node->shift + RADIX_TREE_MAP_SHIFT; return node->shift + RADIX_TREE_MAP_SHIFT;
} }
...@@ -467,11 +467,8 @@ static int radix_tree_extend(struct radix_tree_root *root, ...@@ -467,11 +467,8 @@ static int radix_tree_extend(struct radix_tree_root *root,
node->offset = 0; node->offset = 0;
node->count = 1; node->count = 1;
node->parent = NULL; node->parent = NULL;
if (radix_tree_is_indirect_ptr(slot)) { if (radix_tree_is_indirect_ptr(slot))
slot = indirect_to_ptr(slot); entry_to_node(slot)->parent = node;
slot->parent = node;
slot = node_to_entry(slot);
}
node->slots[0] = slot; node->slots[0] = slot;
slot = node_to_entry(node); slot = node_to_entry(node);
rcu_assign_pointer(root->rnode, slot); rcu_assign_pointer(root->rnode, slot);
...@@ -542,7 +539,7 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index, ...@@ -542,7 +539,7 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
break; break;
/* Go a level down */ /* Go a level down */
node = indirect_to_ptr(slot); node = entry_to_node(slot);
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
offset = radix_tree_descend(node, &slot, offset); offset = radix_tree_descend(node, &slot, offset);
} }
...@@ -645,7 +642,7 @@ void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index, ...@@ -645,7 +642,7 @@ void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index,
if (node == RADIX_TREE_RETRY) if (node == RADIX_TREE_RETRY)
goto restart; goto restart;
parent = indirect_to_ptr(node); parent = entry_to_node(node);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
offset = radix_tree_descend(parent, &node, offset); offset = radix_tree_descend(parent, &node, offset);
...@@ -729,7 +726,7 @@ void *radix_tree_tag_set(struct radix_tree_root *root, ...@@ -729,7 +726,7 @@ void *radix_tree_tag_set(struct radix_tree_root *root,
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
parent = indirect_to_ptr(node); parent = entry_to_node(node);
offset = radix_tree_descend(parent, &node, offset); offset = radix_tree_descend(parent, &node, offset);
BUG_ON(!node); BUG_ON(!node);
...@@ -777,7 +774,7 @@ void *radix_tree_tag_clear(struct radix_tree_root *root, ...@@ -777,7 +774,7 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
parent = indirect_to_ptr(node); parent = entry_to_node(node);
offset = radix_tree_descend(parent, &node, offset); offset = radix_tree_descend(parent, &node, offset);
} }
...@@ -844,7 +841,7 @@ int radix_tree_tag_get(struct radix_tree_root *root, ...@@ -844,7 +841,7 @@ int radix_tree_tag_get(struct radix_tree_root *root,
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
parent = indirect_to_ptr(node); parent = entry_to_node(node);
offset = radix_tree_descend(parent, &node, offset); offset = radix_tree_descend(parent, &node, offset);
if (!node) if (!node)
...@@ -904,7 +901,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root, ...@@ -904,7 +901,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root,
return NULL; return NULL;
if (radix_tree_is_indirect_ptr(rnode)) { if (radix_tree_is_indirect_ptr(rnode)) {
rnode = indirect_to_ptr(rnode); rnode = entry_to_node(rnode);
} else if (rnode) { } else if (rnode) {
/* Single-slot tree */ /* Single-slot tree */
iter->index = index; iter->index = index;
...@@ -963,7 +960,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root, ...@@ -963,7 +960,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root,
if (!radix_tree_is_indirect_ptr(slot)) if (!radix_tree_is_indirect_ptr(slot))
break; break;
node = indirect_to_ptr(slot); node = entry_to_node(slot);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
} }
...@@ -1048,7 +1045,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root, ...@@ -1048,7 +1045,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
return 1; return 1;
} }
node = indirect_to_ptr(slot); node = entry_to_node(slot);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
for (;;) { for (;;) {
...@@ -1063,7 +1060,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root, ...@@ -1063,7 +1060,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
goto next; goto next;
/* Sibling slots never have tags set on them */ /* Sibling slots never have tags set on them */
if (radix_tree_is_indirect_ptr(slot)) { if (radix_tree_is_indirect_ptr(slot)) {
node = indirect_to_ptr(slot); node = entry_to_node(slot);
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
continue; continue;
} }
...@@ -1322,7 +1319,7 @@ static unsigned long __locate(struct radix_tree_node *slot, void *item, ...@@ -1322,7 +1319,7 @@ static unsigned long __locate(struct radix_tree_node *slot, void *item,
} }
continue; continue;
} }
node = indirect_to_ptr(node); node = entry_to_node(node);
if (is_sibling_entry(slot, node)) if (is_sibling_entry(slot, node))
continue; continue;
slot = node; slot = node;
...@@ -1367,7 +1364,7 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item) ...@@ -1367,7 +1364,7 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item)
break; break;
} }
node = indirect_to_ptr(node); node = entry_to_node(node);
max_index = node_maxindex(node); max_index = node_maxindex(node);
if (cur_index > max_index) { if (cur_index > max_index) {
...@@ -1403,7 +1400,7 @@ static inline bool radix_tree_shrink(struct radix_tree_root *root) ...@@ -1403,7 +1400,7 @@ static inline bool radix_tree_shrink(struct radix_tree_root *root)
if (!radix_tree_is_indirect_ptr(to_free)) if (!radix_tree_is_indirect_ptr(to_free))
break; break;
to_free = indirect_to_ptr(to_free); to_free = entry_to_node(to_free);
/* /*
* The candidate node has more than one child, or its child * The candidate node has more than one child, or its child
...@@ -1418,11 +1415,8 @@ static inline bool radix_tree_shrink(struct radix_tree_root *root) ...@@ -1418,11 +1415,8 @@ static inline bool radix_tree_shrink(struct radix_tree_root *root)
if (!radix_tree_is_indirect_ptr(slot) && to_free->shift) if (!radix_tree_is_indirect_ptr(slot) && to_free->shift)
break; break;
if (radix_tree_is_indirect_ptr(slot)) { if (radix_tree_is_indirect_ptr(slot))
slot = indirect_to_ptr(slot); entry_to_node(slot)->parent = NULL;
slot->parent = NULL;
slot = node_to_entry(slot);
}
/* /*
* We don't need rcu_assign_pointer(), since we are simply * We don't need rcu_assign_pointer(), since we are simply
...@@ -1481,7 +1475,7 @@ bool __radix_tree_delete_node(struct radix_tree_root *root, ...@@ -1481,7 +1475,7 @@ bool __radix_tree_delete_node(struct radix_tree_root *root,
struct radix_tree_node *parent; struct radix_tree_node *parent;
if (node->count) { if (node->count) {
if (node == indirect_to_ptr(root->rnode)) if (node == entry_to_node(root->rnode))
deleted |= radix_tree_shrink(root); deleted |= radix_tree_shrink(root);
return deleted; return deleted;
} }
......
...@@ -149,7 +149,7 @@ static int verify_node(struct radix_tree_node *slot, unsigned int tag, ...@@ -149,7 +149,7 @@ static int verify_node(struct radix_tree_node *slot, unsigned int tag,
int i; int i;
int j; int j;
slot = indirect_to_ptr(slot); slot = entry_to_node(slot);
/* Verify consistency at this level */ /* Verify consistency at this level */
for (i = 0; i < RADIX_TREE_TAG_LONGS; i++) { for (i = 0; i < RADIX_TREE_TAG_LONGS; i++) {
...@@ -227,7 +227,7 @@ void tree_verify_min_height(struct radix_tree_root *root, int maxindex) ...@@ -227,7 +227,7 @@ void tree_verify_min_height(struct radix_tree_root *root, int maxindex)
return; return;
} }
node = indirect_to_ptr(node); node = entry_to_node(node);
assert(maxindex <= node_maxindex(node)); assert(maxindex <= node_maxindex(node));
shift = node->shift; shift = node->shift;
......
...@@ -39,7 +39,6 @@ void verify_tag_consistency(struct radix_tree_root *root, unsigned int tag); ...@@ -39,7 +39,6 @@ void verify_tag_consistency(struct radix_tree_root *root, unsigned int tag);
extern int nr_allocated; extern int nr_allocated;
/* Normally private parts of lib/radix-tree.c */ /* Normally private parts of lib/radix-tree.c */
void *indirect_to_ptr(void *ptr);
void radix_tree_dump(struct radix_tree_root *root); void radix_tree_dump(struct radix_tree_root *root);
int root_tag_get(struct radix_tree_root *root, unsigned int tag); int root_tag_get(struct radix_tree_root *root, unsigned int tag);
unsigned long node_maxindex(struct radix_tree_node *); unsigned long node_maxindex(struct radix_tree_node *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment