]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
btrfs: trace: Add trace points for unused block groups
authorQu Wenruo <wqu@suse.com>
Thu, 26 Apr 2018 09:17:20 +0000 (17:17 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 May 2018 16:07:28 +0000 (18:07 +0200)
This patch will add the following trace events:
1) btrfs_remove_block_group
   For btrfs_remove_block_group() function.
   Triggered when a block group is really removed.

2) btrfs_add_unused_block_group
   Triggered which block group is added to unused_bgs list.

3) btrfs_skip_unused_block_group
   Triggered which unused block group is not deleted.

These trace events is pretty handy to debug case related to block group
auto remove.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c
fs/btrfs/scrub.c
include/trace/events/btrfs.h

index 295f8298fd9e6ea5adf4c2a806d79986e289d51e..888a47894c30f5878b2f46259e3b91a57cd9b06e 100644 (file)
@@ -6358,6 +6358,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
                        spin_lock(&info->unused_bgs_lock);
                        if (list_empty(&cache->bg_list)) {
                                btrfs_get_block_group(cache);
+                               trace_btrfs_add_unused_block_group(cache);
                                list_add_tail(&cache->bg_list,
                                              &info->unused_bgs);
                        }
@@ -10192,6 +10193,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
                        /* Should always be true but just in case. */
                        if (list_empty(&cache->bg_list)) {
                                btrfs_get_block_group(cache);
+                               trace_btrfs_add_unused_block_group(cache);
                                list_add_tail(&cache->bg_list,
                                              &info->unused_bgs);
                        }
@@ -10379,6 +10381,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
        BUG_ON(!block_group);
        BUG_ON(!block_group->ro);
 
+       trace_btrfs_remove_block_group(block_group);
        /*
         * Free the reserved super bytes from this block group before
         * remove it.
@@ -10743,6 +10746,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
                         * the ro check in case balance is currently acting on
                         * this block group.
                         */
+                       trace_btrfs_skip_unused_block_group(block_group);
                        spin_unlock(&block_group->lock);
                        up_write(&space_info->groups_sem);
                        goto next;
index 52b39a0924e9f8ebcbc118b5a7f869b7a2b6f042..a5900586201056f0c7429a35ad1b2255c917f40a 100644 (file)
@@ -3984,6 +3984,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
                        spin_lock(&fs_info->unused_bgs_lock);
                        if (list_empty(&cache->bg_list)) {
                                btrfs_get_block_group(cache);
+                               trace_btrfs_add_unused_block_group(cache);
                                list_add_tail(&cache->bg_list,
                                              &fs_info->unused_bgs);
                        }
index 5af2479e9b163f3103ffc4fafbb413a314487e12..914ddb7a6d2587b98bb3963ec4bd5c50a7a4ba78 100644 (file)
@@ -1805,6 +1805,48 @@ TRACE_EVENT(btrfs_inode_mod_outstanding_extents,
                        __entry->ino, __entry->mod)
 );
 
+DECLARE_EVENT_CLASS(btrfs__block_group,
+       TP_PROTO(const struct btrfs_block_group_cache *bg_cache),
+
+       TP_ARGS(bg_cache),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,    bytenr          )
+               __field(        u64,    len             )
+               __field(        u64,    used            )
+               __field(        u64,    flags           )
+       ),
+
+       TP_fast_assign_btrfs(bg_cache->fs_info,
+               __entry->bytenr = bg_cache->key.objectid,
+               __entry->len    = bg_cache->key.offset,
+               __entry->used   = btrfs_block_group_used(&bg_cache->item);
+               __entry->flags  = bg_cache->flags;
+       ),
+
+       TP_printk_btrfs("bg bytenr=%llu len=%llu used=%llu flags=%llu(%s)",
+               __entry->bytenr, __entry->len, __entry->used, __entry->flags,
+               __print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS))
+);
+
+DEFINE_EVENT(btrfs__block_group, btrfs_remove_block_group,
+       TP_PROTO(const struct btrfs_block_group_cache *bg_cache),
+
+       TP_ARGS(bg_cache)
+);
+
+DEFINE_EVENT(btrfs__block_group, btrfs_add_unused_block_group,
+       TP_PROTO(const struct btrfs_block_group_cache *bg_cache),
+
+       TP_ARGS(bg_cache)
+);
+
+DEFINE_EVENT(btrfs__block_group, btrfs_skip_unused_block_group,
+       TP_PROTO(const struct btrfs_block_group_cache *bg_cache),
+
+       TP_ARGS(bg_cache)
+);
+
 #endif /* _TRACE_BTRFS_H */
 
 /* This part must be outside protection */