Commit 437490fe authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: tracepoints: output proper root owner for trace_find_free_extent()

The current trace event always output result like this:

 find_free_extent: root=2(EXTENT_TREE) len=16384 empty_size=0 flags=4(METADATA)
 find_free_extent: root=2(EXTENT_TREE) len=16384 empty_size=0 flags=4(METADATA)
 find_free_extent: root=2(EXTENT_TREE) len=8192 empty_size=0 flags=1(DATA)
 find_free_extent: root=2(EXTENT_TREE) len=8192 empty_size=0 flags=1(DATA)
 find_free_extent: root=2(EXTENT_TREE) len=4096 empty_size=0 flags=1(DATA)
 find_free_extent: root=2(EXTENT_TREE) len=4096 empty_size=0 flags=1(DATA)

T's saying we're allocating data extent for EXTENT tree, which is not
even possible.

It's because we always use EXTENT tree as the owner for
trace_find_free_extent() without using the @root from
btrfs_reserve_extent().

This patch will change the parameter to use proper @root for
trace_find_free_extent():

Now it looks much better:

 find_free_extent: root=5(FS_TREE) len=16384 empty_size=0 flags=36(METADATA|DUP)
 find_free_extent: root=5(FS_TREE) len=8192 empty_size=0 flags=1(DATA)
 find_free_extent: root=5(FS_TREE) len=16384 empty_size=0 flags=1(DATA)
 find_free_extent: root=5(FS_TREE) len=4096 empty_size=0 flags=1(DATA)
 find_free_extent: root=5(FS_TREE) len=8192 empty_size=0 flags=1(DATA)
 find_free_extent: root=5(FS_TREE) len=16384 empty_size=0 flags=36(METADATA|DUP)
 find_free_extent: root=7(CSUM_TREE) len=16384 empty_size=0 flags=36(METADATA|DUP)
 find_free_extent: root=2(EXTENT_TREE) len=16384 empty_size=0 flags=36(METADATA|DUP)
 find_free_extent: root=1(ROOT_TREE) len=16384 empty_size=0 flags=36(METADATA|DUP)
Reported-by: default avatarHans van Kranenburg <hans@knorrie.org>
CC: stable@vger.kernel.org # 5.4+
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 549738f1
...@@ -3918,11 +3918,12 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info, ...@@ -3918,11 +3918,12 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info,
* |- Push harder to find free extents * |- Push harder to find free extents
* |- If not found, re-iterate all block groups * |- If not found, re-iterate all block groups
*/ */
static noinline int find_free_extent(struct btrfs_fs_info *fs_info, static noinline int find_free_extent(struct btrfs_root *root,
u64 ram_bytes, u64 num_bytes, u64 empty_size, u64 ram_bytes, u64 num_bytes, u64 empty_size,
u64 hint_byte_orig, struct btrfs_key *ins, u64 hint_byte_orig, struct btrfs_key *ins,
u64 flags, int delalloc) u64 flags, int delalloc)
{ {
struct btrfs_fs_info *fs_info = root->fs_info;
int ret = 0; int ret = 0;
int cache_block_group_error = 0; int cache_block_group_error = 0;
struct btrfs_block_group *block_group = NULL; struct btrfs_block_group *block_group = NULL;
...@@ -3954,7 +3955,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, ...@@ -3954,7 +3955,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info,
ins->objectid = 0; ins->objectid = 0;
ins->offset = 0; ins->offset = 0;
trace_find_free_extent(fs_info, num_bytes, empty_size, flags); trace_find_free_extent(root, num_bytes, empty_size, flags);
space_info = btrfs_find_space_info(fs_info, flags); space_info = btrfs_find_space_info(fs_info, flags);
if (!space_info) { if (!space_info) {
...@@ -4203,7 +4204,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, ...@@ -4203,7 +4204,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes,
flags = get_alloc_profile_by_root(root, is_data); flags = get_alloc_profile_by_root(root, is_data);
again: again:
WARN_ON(num_bytes < fs_info->sectorsize); WARN_ON(num_bytes < fs_info->sectorsize);
ret = find_free_extent(fs_info, ram_bytes, num_bytes, empty_size, ret = find_free_extent(root, ram_bytes, num_bytes, empty_size,
hint_byte, ins, flags, delalloc); hint_byte, ins, flags, delalloc);
if (!ret && !is_data) { if (!ret && !is_data) {
btrfs_dec_block_group_reservations(fs_info, ins->objectid); btrfs_dec_block_group_reservations(fs_info, ins->objectid);
......
...@@ -1176,25 +1176,27 @@ DEFINE_EVENT(btrfs__reserved_extent, btrfs_reserved_extent_free, ...@@ -1176,25 +1176,27 @@ DEFINE_EVENT(btrfs__reserved_extent, btrfs_reserved_extent_free,
TRACE_EVENT(find_free_extent, TRACE_EVENT(find_free_extent,
TP_PROTO(const struct btrfs_fs_info *fs_info, u64 num_bytes, TP_PROTO(const struct btrfs_root *root, u64 num_bytes,
u64 empty_size, u64 data), u64 empty_size, u64 data),
TP_ARGS(fs_info, num_bytes, empty_size, data), TP_ARGS(root, num_bytes, empty_size, data),
TP_STRUCT__entry_btrfs( TP_STRUCT__entry_btrfs(
__field( u64, root_objectid )
__field( u64, num_bytes ) __field( u64, num_bytes )
__field( u64, empty_size ) __field( u64, empty_size )
__field( u64, data ) __field( u64, data )
), ),
TP_fast_assign_btrfs(fs_info, TP_fast_assign_btrfs(root->fs_info,
__entry->root_objectid = root->root_key.objectid;
__entry->num_bytes = num_bytes; __entry->num_bytes = num_bytes;
__entry->empty_size = empty_size; __entry->empty_size = empty_size;
__entry->data = data; __entry->data = data;
), ),
TP_printk_btrfs("root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s)", TP_printk_btrfs("root=%llu(%s) len=%llu empty_size=%llu flags=%llu(%s)",
show_root_type(BTRFS_EXTENT_TREE_OBJECTID), show_root_type(__entry->root_objectid),
__entry->num_bytes, __entry->empty_size, __entry->data, __entry->num_bytes, __entry->empty_size, __entry->data,
__print_flags((unsigned long)__entry->data, "|", __print_flags((unsigned long)__entry->data, "|",
BTRFS_GROUP_FLAGS)) BTRFS_GROUP_FLAGS))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment