btrfs: add a trace class for dumping the current ENOSPC state
authorJosef Bacik <josef@toxicpanda.com>
Fri, 9 Oct 2020 13:28:29 +0000 (09:28 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 8 Feb 2021 21:58:59 +0000 (22:58 +0100)
Often when I'm debugging ENOSPC related issues I have to resort to
printing the entire ENOSPC state with trace_printk() in different spots.
This gets pretty annoying, so add a trace state that does this for us.
Then add a trace point at the end of preemptive flushing so you can see
the state of the space_info when we decide to exit preemptive flushing.
This helped me figure out we weren't kicking in the preemptive flushing
soon enough.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/space-info.c
include/trace/events/btrfs.h

index bb4f85c07738834b38bc1aa357612125f399620b..bccd98141a6e9a45225fdd434b8481fd07aa73ca 100644 (file)
@@ -1140,6 +1140,7 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
        /* We only went through once, back off our clamping. */
        if (loops == 1 && !space_info->reclaim_size)
                space_info->clamp = max(1, space_info->clamp - 1);
+       trace_btrfs_done_preemptive_reclaim(fs_info, space_info);
        spin_unlock(&space_info->lock);
 }
 
index 807921de6b324eb0382251ef3607b5c722395cb6..0551ea65374fd0a1ed93300984e85ccc7b2e0f95 100644 (file)
@@ -2029,6 +2029,68 @@ TRACE_EVENT(btrfs_convert_extent_bit,
                  __print_flags(__entry->clear_bits, "|", EXTENT_FLAGS))
 );
 
+DECLARE_EVENT_CLASS(btrfs_dump_space_info,
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_space_info *sinfo),
+
+       TP_ARGS(fs_info, sinfo),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,    flags                   )
+               __field(        u64,    total_bytes             )
+               __field(        u64,    bytes_used              )
+               __field(        u64,    bytes_pinned            )
+               __field(        u64,    bytes_reserved          )
+               __field(        u64,    bytes_may_use           )
+               __field(        u64,    bytes_readonly          )
+               __field(        u64,    reclaim_size            )
+               __field(        int,    clamp                   )
+               __field(        u64,    global_reserved         )
+               __field(        u64,    trans_reserved          )
+               __field(        u64,    delayed_refs_reserved   )
+               __field(        u64,    delayed_reserved        )
+               __field(        u64,    free_chunk_space        )
+       ),
+
+       TP_fast_assign_btrfs(fs_info,
+               __entry->flags                  =       sinfo->flags;
+               __entry->total_bytes            =       sinfo->total_bytes;
+               __entry->bytes_used             =       sinfo->bytes_used;
+               __entry->bytes_pinned           =       sinfo->bytes_pinned;
+               __entry->bytes_reserved         =       sinfo->bytes_reserved;
+               __entry->bytes_may_use          =       sinfo->bytes_may_use;
+               __entry->bytes_readonly         =       sinfo->bytes_readonly;
+               __entry->reclaim_size           =       sinfo->reclaim_size;
+               __entry->clamp                  =       sinfo->clamp;
+               __entry->global_reserved        =       fs_info->global_block_rsv.reserved;
+               __entry->trans_reserved         =       fs_info->trans_block_rsv.reserved;
+               __entry->delayed_refs_reserved  =       fs_info->delayed_refs_rsv.reserved;
+               __entry->delayed_reserved       =       fs_info->delayed_block_rsv.reserved;
+               __entry->free_chunk_space       =       atomic64_read(&fs_info->free_chunk_space);
+       ),
+
+       TP_printk_btrfs("flags=%s total_bytes=%llu bytes_used=%llu "
+                       "bytes_pinned=%llu bytes_reserved=%llu "
+                       "bytes_may_use=%llu bytes_readonly=%llu "
+                       "reclaim_size=%llu clamp=%d global_reserved=%llu "
+                       "trans_reserved=%llu delayed_refs_reserved=%llu "
+                       "delayed_reserved=%llu chunk_free_space=%llu",
+                       __print_flags(__entry->flags, "|", BTRFS_GROUP_FLAGS),
+                       __entry->total_bytes, __entry->bytes_used,
+                       __entry->bytes_pinned, __entry->bytes_reserved,
+                       __entry->bytes_may_use, __entry->bytes_readonly,
+                       __entry->reclaim_size, __entry->clamp,
+                       __entry->global_reserved, __entry->trans_reserved,
+                       __entry->delayed_refs_reserved,
+                       __entry->delayed_reserved, __entry->free_chunk_space)
+);
+
+DEFINE_EVENT(btrfs_dump_space_info, btrfs_done_preemptive_reclaim,
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_space_info *sinfo),
+       TP_ARGS(fs_info, sinfo)
+);
+
 TRACE_EVENT(btrfs_reserve_ticket,
        TP_PROTO(const struct btrfs_fs_info *fs_info, u64 flags, u64 bytes,
                 u64 start_ns, int flush, int error),