btrfs: qgroup: Move half of the qgroup accounting time out of commit trans
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Wed, 15 Feb 2017 02:43:03 +0000 (10:43 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 17 Feb 2017 11:03:55 +0000 (12:03 +0100)
commitfb235dc06fac9eaa4408ade9c8b20d45d63c89b7
tree2bd827b257ac580b31097fa13a98bab3a0162c9e
parent15b34517a6368c607ae7fd51c24cdc69efcd47fc
btrfs: qgroup: Move half of the qgroup accounting time out of commit trans

Just as Filipe pointed out, the most time consuming parts of qgroup are
btrfs_qgroup_account_extents() and
btrfs_qgroup_prepare_account_extents().
Which both call btrfs_find_all_roots() to get old_roots and new_roots
ulist.

What makes things worse is, we're calling that expensive
btrfs_find_all_roots() at transaction committing time with
TRANS_STATE_COMMIT_DOING, which will blocks all incoming transaction.

Such behavior is necessary for @new_roots search as current
btrfs_find_all_roots() can't do it correctly so we do call it just
before switch commit roots.

However for @old_roots search, it's not necessary as such search is
based on commit_root, so it will always be correct and we can move it
out of transaction committing.

This patch moves the @old_roots search part out of
commit_transaction(), so in theory we can half the time qgroup time
consumption at commit_transaction().

But please note that, this won't speedup qgroup overall, the total time
consumption is still the same, just reduce the performance stall.

Cc: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/delayed-ref.c
fs/btrfs/qgroup.c
fs/btrfs/qgroup.h