diff options
author | Wang Shilong <wangsl-fnst@cn.fujitsu.com> | 2013-04-12 08:12:17 -0400 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-05-06 15:54:44 -0400 |
commit | f7f82b81d2c297a5864dcfd0a205917d3e753aba (patch) | |
tree | d5208b93d07ce88b5b66e646da7241fff45ce143 /fs/btrfs/ulist.h | |
parent | c2c71324ecb471c932bc1ff59e46ffcf82f274fc (diff) |
Btrfs: add a rb_tree to improve performance of ulist search
Walking backref tree and btrfs quota rely on ulist very much.
This patch tries to use rb_tree to speed up search time.
The original code always checks whether an element
exists before adding a new element, however it costs O(n).
I try to add a rb_tree in the ulist,this is only used to speed up
search. I also do some measurements with quota enabled.
fsstress -p 4 -n 10000
Without this path:
real 0m51.058s 2m4.745s 1m28.222s 1m5.137s
user 0m0.035s 0m0.041s 0m0.105s 0m0.100s
sys 0m12.009s 0m11.246s 0m10.901s 0m10.999s 0m11.287s
With this path:
real 0m55.295s 0m50.960s 1m2.214s 0m48.273s
user 0m0.053s 0m0.095s 0m0.135s 0m0.107s
sys 0m7.766s 0m6.013s 0m6.319s 0m6.030s 0m6.532s
After applying the patch,the execute time is down by ~42%.(11.287s->6.532s)
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/ulist.h')
-rw-r--r-- | fs/btrfs/ulist.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/btrfs/ulist.h b/fs/btrfs/ulist.h index 21a1963439c3..fb36731074b5 100644 --- a/fs/btrfs/ulist.h +++ b/fs/btrfs/ulist.h | |||
@@ -8,6 +8,9 @@ | |||
8 | #ifndef __ULIST__ | 8 | #ifndef __ULIST__ |
9 | #define __ULIST__ | 9 | #define __ULIST__ |
10 | 10 | ||
11 | #include <linux/list.h> | ||
12 | #include <linux/rbtree.h> | ||
13 | |||
11 | /* | 14 | /* |
12 | * ulist is a generic data structure to hold a collection of unique u64 | 15 | * ulist is a generic data structure to hold a collection of unique u64 |
13 | * values. The only operations it supports is adding to the list and | 16 | * values. The only operations it supports is adding to the list and |
@@ -34,6 +37,7 @@ struct ulist_iterator { | |||
34 | struct ulist_node { | 37 | struct ulist_node { |
35 | u64 val; /* value to store */ | 38 | u64 val; /* value to store */ |
36 | u64 aux; /* auxiliary value saved along with the val */ | 39 | u64 aux; /* auxiliary value saved along with the val */ |
40 | struct rb_node rb_node; /* used to speed up search */ | ||
37 | }; | 41 | }; |
38 | 42 | ||
39 | struct ulist { | 43 | struct ulist { |
@@ -54,6 +58,8 @@ struct ulist { | |||
54 | */ | 58 | */ |
55 | struct ulist_node *nodes; | 59 | struct ulist_node *nodes; |
56 | 60 | ||
61 | struct rb_root root; | ||
62 | |||
57 | /* | 63 | /* |
58 | * inline storage space for the first ULIST_SIZE entries | 64 | * inline storage space for the first ULIST_SIZE entries |
59 | */ | 65 | */ |