Commit 6a5ac228 authored by Johannes Thumshirn's avatar Johannes Thumshirn Committed by David Sterba
Browse files

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: default avatarNaohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 68d4ece9
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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,
+54 −0
Original line number Diff line number Diff line
@@ -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);
}
+8 −0
Original line number Diff line number Diff line
@@ -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)