Skip to content

Commit 5edfd9f

Browse files
Qu Wenruokdave
authored andcommitted
btrfs: qgroup: Add quick exit for non-fs extents
Modify btrfs_qgroup_account_extent() to exit quicker for non-fs extents. The quick exit condition is: 1) The extent belongs to a non-fs tree Only fs-tree extents can affect qgroup numbers and is the only case where extent can be shared between different trees. Although strictly speaking extent in data-reloc or tree-reloc tree can be shared, data/tree-reloc root won't appear in the result of btrfs_find_all_roots(), so we can ignore such case. So we can check the first root in old_roots/new_roots ulist. - if we find the 1st root is a not a fs/subvol root, then we can skip the extent - if we find the 1st root is a fs/subvol root, then we must continue calculation OR 2) both 'nr_old_roots' and 'nr_new_roots' are 0 This means either such extent got allocated then freed in current transaction or it's a new reloc tree extent, whose nr_new_roots is 0. Either way it won't affect qgroup accounting and can be skipped safely. Such quick exit can make trace output more quite and less confusing: (example with fs uuid and time stamp removed) Before: ------ add_delayed_tree_ref: bytenr=29556736 num_bytes=16384 action=ADD_DELAYED_REF parent=0(-) ref_root=2(EXTENT_TREE) level=0 type=TREE_BLOCK_REF seq=0 btrfs_qgroup_account_extent: bytenr=29556736 num_bytes=16384 nr_old_roots=0 nr_new_roots=1 ------ Extent tree block will trigger btrfs_qgroup_account_extent() trace point while no qgroup number is changed, as extent tree won't affect qgroup accounting. After: ------ add_delayed_tree_ref: bytenr=29556736 num_bytes=16384 action=ADD_DELAYED_REF parent=0(-) ref_root=2(EXTENT_TREE) level=0 type=TREE_BLOCK_REF seq=0 ------ Now such unrelated extent won't trigger btrfs_qgroup_account_extent() trace point, making the trace less noisy. Signed-off-by: Qu Wenruo <[email protected]> [ changelog and comment adjustments ] Signed-off-by: David Sterba <[email protected]>
1 parent d7eae34 commit 5edfd9f

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

fs/btrfs/qgroup.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,35 @@ static int qgroup_update_counters(struct btrfs_fs_info *fs_info,
19191919
return 0;
19201920
}
19211921

1922+
/*
1923+
* Check if the @roots potentially is a list of fs tree roots
1924+
*
1925+
* Return 0 for definitely not a fs/subvol tree roots ulist
1926+
* Return 1 for possible fs/subvol tree roots in the list (considering an empty
1927+
* one as well)
1928+
*/
1929+
static int maybe_fs_roots(struct ulist *roots)
1930+
{
1931+
struct ulist_node *unode;
1932+
struct ulist_iterator uiter;
1933+
1934+
/* Empty one, still possible for fs roots */
1935+
if (!roots || roots->nnodes == 0)
1936+
return 1;
1937+
1938+
ULIST_ITER_INIT(&uiter);
1939+
unode = ulist_next(roots, &uiter);
1940+
if (!unode)
1941+
return 1;
1942+
1943+
/*
1944+
* If it contains fs tree roots, then it must belong to fs/subvol
1945+
* trees.
1946+
* If it contains a non-fs tree, it won't be shared with fs/subvol trees.
1947+
*/
1948+
return is_fstree(unode->val);
1949+
}
1950+
19221951
int
19231952
btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
19241953
struct btrfs_fs_info *fs_info,
@@ -1935,10 +1964,20 @@ btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
19351964
if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags))
19361965
return 0;
19371966

1938-
if (new_roots)
1967+
if (new_roots) {
1968+
if (!maybe_fs_roots(new_roots))
1969+
goto out_free;
19391970
nr_new_roots = new_roots->nnodes;
1940-
if (old_roots)
1971+
}
1972+
if (old_roots) {
1973+
if (!maybe_fs_roots(old_roots))
1974+
goto out_free;
19411975
nr_old_roots = old_roots->nnodes;
1976+
}
1977+
1978+
/* Quick exit, either not fs tree roots, or won't affect any qgroup */
1979+
if (nr_old_roots == 0 && nr_new_roots == 0)
1980+
goto out_free;
19421981

19431982
BUG_ON(!fs_info->quota_root);
19441983

0 commit comments

Comments
 (0)