aboutsummaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>2025-12-17 14:41:37 +0100
committerDavid Sterba <dsterba@suse.com>2026-02-03 07:49:12 +0100
commit6a5ac228d4ad05c250de0bf06713d81bfb70c714 (patch)
treee5692a3dcf5ddb9e92c69d72037b954d7e061955 /fs
parent68d4ece9c30e966ebb92798ea54a7777daff384b (diff)
btrfs: zoned: show statistics about zoned filesystems in mountstats
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/super.c13
-rw-r--r--fs/btrfs/zoned.c54
-rw-r--r--fs/btrfs/zoned.h8
3 files changed, 75 insertions, 0 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 0a931555e6dc..d64d303b6edc 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -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,
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 359a98e6de85..a58a4336a5b7 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -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);
+}
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index 5cefdeb08b7b..2fdc88c6fa3c 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -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)