Skip to contentSkip to conversation

Btrfs: introduce qgroup_ulist to avoid frequently allocating/freeing ulist

PATCH New Wang Shilong 1 participant 1 message May 6, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: introduce qgroup_ulist to avoid frequently allocating/freeing ulist

When doing qgroup accounting, we call ulist_alloc()/ulist_free() every time when we want to walk qgroup tree.

By introducing 'qgroup_ulist', we only need to call ulist_alloc()/ulist_free() once. This reduce some sys time to allocate memory, see the measurements below

fsstress -p 4 -n 10000 -d $dir

With this patch:

real    0m50.153s
user    0m0.081s
sys     0m6.294s
real    0m51.113s
user    0m0.092s
sys     0m6.220s
real    0m52.610s
user    0m0.096s
sys     0m6.125s	avg 6.213

-----------------------------------------------------
Without the patch:

real    0m54.825s
user    0m0.061s
sys     0m10.665s
real    1m6.401s
user    0m0.089s
sys     0m11.218s
real    1m13.768s
user    0m0.087s
sys     0m10.665s       avg 10.849

we can see the sys time reduce ~43%.

---
 fs/btrfs/ctree.h   |    6 ++++
 fs/btrfs/disk-io.c |    1 +
 fs/btrfs/qgroup.c  |   70 ++++++++++++++++++++++++++-------------------------
 3 files changed, 43 insertions(+), 34 deletions(-)
fs/btrfs/ctree.h +6 -0
index 63c328a..3ccb829 100644
@@ -1594,6 +1594,12 @@ struct btrfs_fs_info {
 	struct rb_root qgroup_tree;
 	spinlock_t qgroup_lock;
 
+	/*
+	 * used to avoid frequently calling ulist_alloc()/ulist_free()
+	 * when doing qgroup accounting, it must be protected by qgroup_lock.
+	 */
+	struct ulist *qgroup_ulist;
+
 	/* protect user change for quota operations */
 	struct mutex qgroup_ioctl_lock;
 
fs/btrfs/disk-io.c +1 -0
index 2223494..ee8ce33 100644
@@ -2267,6 +2267,7 @@ int open_ctree(struct super_block *sb,
 	fs_info->qgroup_seq = 1;
 	fs_info->quota_enabled = 0;
 	fs_info->pending_quota_state = 0;
+	fs_info->qgroup_ulist = NULL;
 	mutex_init(&fs_info->qgroup_rescan_lock);
 
 	btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
fs/btrfs/qgroup.c +36 -34

195 lines not on this page · raw message

Signature · 1 line
1.7.7.6