]> git.baikalelectronics.ru Git - kernel.git/commitdiff
radix-tree: remove a use of root->height from delete_node
authorMatthew Wilcox <willy@linux.intel.com>
Sat, 21 May 2016 00:03:13 +0000 (17:03 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 May 2016 00:58:30 +0000 (17:58 -0700)
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 <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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/radix-tree.c

index 648da90804180db1e5b16f4e2573dafce33cd7d7..75c9e6197b5b1b6bb05cbcb7b2d5740ef52bfda3 100644 (file)
@@ -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;
@@ -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;
 }
 
 /**
@@ -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;
                }