Skip to content

Commit

Permalink
radix-tree: remove a use of root->height from delete_node
Browse files Browse the repository at this point in the history
If radix_tree_shrink returns whether it managed to shrink, then
__radix_tree_delete_node doesn't ned to query the tree to find out
whether it did any work or not.

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]>
Cc: Ross Zwisler <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox authored and torvalds committed May 21, 2016
1 parent c12e51b commit fb20901
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/radix-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,10 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item)
* radix_tree_shrink - shrink height of a radix tree to minimal
* @root radix tree root
*/
static inline void radix_tree_shrink(struct radix_tree_root *root)
static inline bool radix_tree_shrink(struct radix_tree_root *root)
{
bool shrunk = false;

/* try to shrink tree height */
while (root->height > 0) {
struct radix_tree_node *to_free = root->rnode;
Expand Down Expand Up @@ -1476,7 +1478,10 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
to_free->slots[0] = RADIX_TREE_RETRY;

radix_tree_node_free(to_free);
shrunk = true;
}

return shrunk;
}

/**
Expand All @@ -1499,11 +1504,8 @@ bool __radix_tree_delete_node(struct radix_tree_root *root,
struct radix_tree_node *parent;

if (node->count) {
if (node == indirect_to_ptr(root->rnode)) {
radix_tree_shrink(root);
if (root->height == 0)
deleted = true;
}
if (node == indirect_to_ptr(root->rnode))
deleted |= radix_tree_shrink(root);
return deleted;
}

Expand Down

0 comments on commit fb20901

Please sign in to comment.