]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: zoned: show statistics about zoned filesystems in mountstats
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Wed, 17 Dec 2025 13:41:37 +0000 (14:41 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Feb 2026 06:49:12 +0000 (07:49 +0100)
Add statistics output to /proc/<pid>/mountstats for zoned BTRFS, similar
to the zoned statistics from XFS in mountstats.

The output for /proc/<pid>/mountstats on an example filesystem will be as
follows:

  device /dev/vda mounted on /mnt with fstype btrfs
    zoned statistics:
          active block-groups: 7
            reclaimable: 0
            unused: 5
            need reclaim: false
          data relocation block-group: 1342177280
          active zones:
            start: 1073741824, wp: 268419072 used: 0, reserved: 268419072, unusable: 0
            start: 1342177280, wp: 0 used: 0, reserved: 0, unusable: 0
            start: 1610612736, wp: 49152 used: 16384, reserved: 16384, unusable: 16384
            start: 1879048192, wp: 950272 used: 131072, reserved: 622592, unusable: 196608
            start: 2147483648, wp: 212238336 used: 0, reserved: 212238336, unusable: 0
            start: 2415919104, wp: 0 used: 0, reserved: 0, unusable: 0
            start: 2684354560, wp: 0 used: 0, reserved: 0, unusable: 0

Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/super.c
fs/btrfs/zoned.c
fs/btrfs/zoned.h

index 0a931555e6dcd222c2dd703cc0c0774d4e6370df..d64d303b6edc9676db05d3af15f999a7aefbcb8a 100644 (file)
@@ -2483,6 +2483,18 @@ static void btrfs_shutdown(struct super_block *sb)
 }
 #endif
 
+static int btrfs_show_stats(struct seq_file *seq, struct dentry *root)
+{
+       struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
+
+       if (btrfs_is_zoned(fs_info)) {
+               btrfs_show_zoned_stats(fs_info, seq);
+               return 0;
+       }
+
+       return 0;
+}
+
 static const struct super_operations btrfs_super_ops = {
        .drop_inode     = btrfs_drop_inode,
        .evict_inode    = btrfs_evict_inode,
@@ -2498,6 +2510,7 @@ static const struct super_operations btrfs_super_ops = {
        .unfreeze_fs    = btrfs_unfreeze,
        .nr_cached_objects = btrfs_nr_cached_objects,
        .free_cached_objects = btrfs_free_cached_objects,
+       .show_stats     = btrfs_show_stats,
 #ifdef CONFIG_BTRFS_EXPERIMENTAL
        .remove_bdev    = btrfs_remove_bdev,
        .shutdown       = btrfs_shutdown,
index 359a98e6de8513f635525e337b83ef51d8f159e6..a58a4336a5b725892e6cc467eab5e2cfaef9ccce 100644 (file)
@@ -2984,3 +2984,57 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num
 
        return 0;
 }
+
+void btrfs_show_zoned_stats(struct btrfs_fs_info *fs_info, struct seq_file *seq)
+{
+       struct btrfs_block_group *bg;
+       u64 data_reloc_bg;
+       u64 treelog_bg;
+
+       seq_puts(seq, "\n  zoned statistics:\n");
+
+       spin_lock(&fs_info->zone_active_bgs_lock);
+       seq_printf(seq, "\tactive block-groups: %zu\n",
+                            list_count_nodes(&fs_info->zone_active_bgs));
+       spin_unlock(&fs_info->zone_active_bgs_lock);
+
+       spin_lock(&fs_info->unused_bgs_lock);
+       seq_printf(seq, "\t  reclaimable: %zu\n",
+                            list_count_nodes(&fs_info->reclaim_bgs));
+       seq_printf(seq, "\t  unused: %zu\n", list_count_nodes(&fs_info->unused_bgs));
+       spin_unlock(&fs_info->unused_bgs_lock);
+
+       seq_printf(seq,"\t  need reclaim: %s\n",
+                  str_true_false(btrfs_zoned_should_reclaim(fs_info)));
+
+       data_reloc_bg = data_race(fs_info->data_reloc_bg);
+       if (data_reloc_bg)
+               seq_printf(seq, "\tdata relocation block-group: %llu\n",
+                          data_reloc_bg);
+       treelog_bg = data_race(fs_info->treelog_bg);
+       if (treelog_bg)
+               seq_printf(seq, "\ttree-log block-group: %llu\n", treelog_bg);
+
+       spin_lock(&fs_info->zone_active_bgs_lock);
+       seq_puts(seq, "\tactive zones:\n");
+       list_for_each_entry(bg, &fs_info->zone_active_bgs, active_bg_list) {
+               u64 start;
+               u64 alloc_offset;
+               u64 used;
+               u64 reserved;
+               u64 zone_unusable;
+
+               spin_lock(&bg->lock);
+               start = bg->start;
+               alloc_offset = bg->alloc_offset;
+               used = bg->used;
+               reserved = bg->reserved;
+               zone_unusable = bg->zone_unusable;
+               spin_unlock(&bg->lock);
+
+               seq_printf(seq,
+                          "\t  start: %llu, wp: %llu used: %llu, reserved: %llu, unusable: %llu\n",
+                          start, alloc_offset, used, reserved, zone_unusable);
+       }
+       spin_unlock(&fs_info->zone_active_bgs_lock);
+}
index 5cefdeb08b7b71f511478dd2c06c8a2fd8646dfe..2fdc88c6fa3c9a4868e4c9d542c65a00c0da7021 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/errno.h>
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
+#include <linux/seq_file.h>
 #include "messages.h"
 #include "volumes.h"
 #include "disk-io.h"
@@ -96,6 +97,8 @@ int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info);
 int btrfs_zoned_activate_one_bg(struct btrfs_space_info *space_info, bool do_finish);
 void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info);
 int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num_bytes);
+void btrfs_show_zoned_stats(struct btrfs_fs_info *fs_info, struct seq_file *seq);
+
 #else /* CONFIG_BLK_DEV_ZONED */
 
 static inline int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info)
@@ -275,6 +278,11 @@ static inline int btrfs_reset_unused_block_groups(struct btrfs_space_info *space
        return 0;
 }
 
+static inline int btrfs_show_zoned_stats(struct btrfs_fs_info *fs_info, struct seq_file *seq)
+{
+       return 0;
+}
+
 #endif
 
 static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)