Skip to content

Commit 951c972

Browse files
committed
btrfs: zoned: show statistics for zoned filesystems
Provide statistics for zoned filesystems. These statistics include, the number of active block-groups, how many of them are reclaimable or unused, if the filesystem needs to be reclaimed, the currently assigned relocation and treelog block-groups if they're present and a list of active zones. Example: active block-groups: 4   reclaimable: 0   unused: 2   need reclaim: false data reclocation block-group: 4294967296 active zones:   start: 1610612736, wp: 344064 used: 16384, reserved: 0, unusable: 327680   start: 1879048192, wp: 34963456 used: 131072, reserved: 0, unusable: 34832384   start: 4026531840, wp: 0 used: 0, reserved: 0, unusable: 0   start: 4294967296, wp: 0 used: 0, reserved: 0, unusable: 0 Reviewed-by: David Sterba <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]>
1 parent afa3997 commit 951c972

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

fs/btrfs/sysfs.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/completion.h>
1111
#include <linux/bug.h>
1212
#include <linux/list.h>
13+
#include <linux/string_choices.h>
1314
#include <crypto/hash.h>
1415
#include "messages.h"
1516
#include "ctree.h"
@@ -25,6 +26,7 @@
2526
#include "misc.h"
2627
#include "fs.h"
2728
#include "accessors.h"
29+
#include "zoned.h"
2830

2931
/*
3032
* Structure name Path
@@ -1187,6 +1189,56 @@ static ssize_t btrfs_commit_stats_store(struct kobject *kobj,
11871189
}
11881190
BTRFS_ATTR_RW(, commit_stats, btrfs_commit_stats_show, btrfs_commit_stats_store);
11891191

1192+
static ssize_t btrfs_zoned_stats_show(struct kobject *kobj,
1193+
struct kobj_attribute *a, char *buf)
1194+
{
1195+
struct btrfs_fs_info *fs_info = to_fs_info(kobj);
1196+
struct btrfs_block_group *bg;
1197+
size_t ret = 0;
1198+
1199+
1200+
if (!btrfs_is_zoned(fs_info))
1201+
return ret;
1202+
1203+
spin_lock(&fs_info->zone_active_bgs_lock);
1204+
ret += sysfs_emit_at(buf, ret, "active block-groups: %zu\n",
1205+
list_count_nodes(&fs_info->zone_active_bgs));
1206+
spin_unlock(&fs_info->zone_active_bgs_lock);
1207+
1208+
mutex_lock(&fs_info->reclaim_bgs_lock);
1209+
spin_lock(&fs_info->unused_bgs_lock);
1210+
ret += sysfs_emit_at(buf, ret, "\treclaimable: %zu\n",
1211+
list_count_nodes(&fs_info->reclaim_bgs));
1212+
ret += sysfs_emit_at(buf, ret, "\tunused: %zu\n",
1213+
list_count_nodes(&fs_info->unused_bgs));
1214+
spin_unlock(&fs_info->unused_bgs_lock);
1215+
mutex_unlock(&fs_info->reclaim_bgs_lock);
1216+
1217+
ret += sysfs_emit_at(buf, ret, "\tneed reclaim: %s\n",
1218+
str_true_false(btrfs_zoned_should_reclaim(fs_info)));
1219+
1220+
if (fs_info->data_reloc_bg)
1221+
ret += sysfs_emit_at(buf, ret,
1222+
"data reclocation block-group: %llu\n",
1223+
fs_info->data_reloc_bg);
1224+
if (fs_info->treelog_bg)
1225+
ret += sysfs_emit_at(buf, ret,
1226+
"tree-log block-group: %llu\n",
1227+
fs_info->treelog_bg);
1228+
1229+
spin_lock(&fs_info->zone_active_bgs_lock);
1230+
ret += sysfs_emit_at(buf, ret, "active zones:\n");
1231+
list_for_each_entry(bg, &fs_info->zone_active_bgs, active_bg_list) {
1232+
ret += sysfs_emit_at(buf, ret,
1233+
"\tstart: %llu, wp: %llu used: %llu, reserved: %llu, unusable: %llu\n",
1234+
bg->start, bg->alloc_offset, bg->used,
1235+
bg->reserved, bg->zone_unusable);
1236+
}
1237+
spin_unlock(&fs_info->zone_active_bgs_lock);
1238+
return ret;
1239+
}
1240+
BTRFS_ATTR(, zoned_stats, btrfs_zoned_stats_show);
1241+
11901242
static ssize_t btrfs_clone_alignment_show(struct kobject *kobj,
11911243
struct kobj_attribute *a, char *buf)
11921244
{
@@ -1599,6 +1651,7 @@ static const struct attribute *btrfs_attrs[] = {
15991651
BTRFS_ATTR_PTR(, bg_reclaim_threshold),
16001652
BTRFS_ATTR_PTR(, commit_stats),
16011653
BTRFS_ATTR_PTR(, temp_fsid),
1654+
BTRFS_ATTR_PTR(, zoned_stats),
16021655
#ifdef CONFIG_BTRFS_EXPERIMENTAL
16031656
BTRFS_ATTR_PTR(, offload_csum),
16041657
#endif

0 commit comments

Comments
 (0)