Skip to content

Commit

Permalink
radix-tree: rewrite radix_tree_tag_get
Browse files Browse the repository at this point in the history
Use the new multi-order support functions to rewrite
radix_tree_tag_get()

Signed-off-by: Ross Zwisler <[email protected]>
Signed-off-by: Matthew Wilcox <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Cc: Kirill Shutemov <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Neil Brown <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ross Zwisler authored and torvalds committed May 21, 2016
1 parent 00f47b5 commit 4589ba6
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions lib/radix-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,45 +831,37 @@ EXPORT_SYMBOL(radix_tree_tag_clear);
int radix_tree_tag_get(struct radix_tree_root *root,
unsigned long index, unsigned int tag)
{
unsigned int height, shift;
struct radix_tree_node *node;
struct radix_tree_node *node, *parent;
unsigned long maxindex;
unsigned int shift;

/* check the root's tag bit */
if (!root_tag_get(root, tag))
return 0;

node = rcu_dereference_raw(root->rnode);
shift = radix_tree_load_root(root, &node, &maxindex);
if (index > maxindex)
return 0;
if (node == NULL)
return 0;

if (!radix_tree_is_indirect_ptr(node))
return (index == 0);
node = indirect_to_ptr(node);

height = node->path & RADIX_TREE_HEIGHT_MASK;
if (index > radix_tree_maxindex(height))
return 0;
while (radix_tree_is_indirect_ptr(node)) {
int offset;

shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK;

for ( ; ; ) {
int offset;
parent = indirect_to_ptr(node);
offset = radix_tree_descend(parent, &node, offset);

if (node == NULL)
if (!node)
return 0;
node = indirect_to_ptr(node);

offset = (index >> shift) & RADIX_TREE_MAP_MASK;
if (!tag_get(node, tag, offset))
if (!tag_get(parent, tag, offset))
return 0;
if (height == 1)
return 1;
node = rcu_dereference_raw(node->slots[offset]);
if (!radix_tree_is_indirect_ptr(node))
return 1;
shift -= RADIX_TREE_MAP_SHIFT;
height--;
if (node == RADIX_TREE_RETRY)
break;
}

return 1;
}
EXPORT_SYMBOL(radix_tree_tag_get);

Expand Down

0 comments on commit 4589ba6

Please sign in to comment.