Btrfs: optimize to remove unnecessary removal with ulist reallocation
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Fri, 10 Jan 2014 13:25:46 +0000 (21:25 +0800)
committerChris Mason <clm@fb.com>
Tue, 28 Jan 2014 21:20:30 +0000 (13:20 -0800)
Here we are not going to free memory, no need to remove every node
one by one, just init root node here is ok.

Cc: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/ulist.c

index b0a523b2c60ee8e73cd5165382892918ddad269e..35f5de9dd498bcc17d802cda46ffc05248324650 100644 (file)
@@ -207,9 +207,6 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
                void *old = NULL;
                int i;
 
-               for (i = 0; i < ulist->nnodes; i++)
-                       rb_erase(&ulist->nodes[i].rb_node, &ulist->root);
-
                /*
                 * if nodes_alloced == ULIST_SIZE no memory has been allocated
                 * yet, so pass NULL to krealloc
@@ -234,6 +231,7 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
                 * pointers, so we have to do it ourselves.  Otherwise we may
                 * be bitten by crashes.
                 */
+               ulist->root = RB_ROOT;
                for (i = 0; i < ulist->nnodes; i++) {
                        ret = ulist_rbtree_insert(ulist, &ulist->nodes[i]);
                        if (ret < 0)