Skip to content

Commit fcd9531

Browse files
boryaskdave
authored andcommitted
btrfs: sysfs: add size class stats
Make it possible to see the distribution of size classes for block groups. Helpful for testing and debugging the allocator w.r.t. to size classes. The new stats can be found at the path: /sys/fs/btrfs/<FSID>/allocation/<bg-type>/size_class but they will only be non-zero for bg-type = data. Signed-off-by: Boris Burkov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 964a54e commit fcd9531

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

fs/btrfs/sysfs.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/spinlock.h>
1010
#include <linux/completion.h>
1111
#include <linux/bug.h>
12+
#include <linux/list.h>
1213
#include <crypto/hash.h>
1314
#include "messages.h"
1415
#include "ctree.h"
@@ -778,6 +779,45 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
778779
return len;
779780
}
780781

782+
static ssize_t btrfs_size_classes_show(struct kobject *kobj,
783+
struct kobj_attribute *a, char *buf)
784+
{
785+
struct btrfs_space_info *sinfo = to_space_info(kobj);
786+
struct btrfs_block_group *bg;
787+
u32 none = 0;
788+
u32 small = 0;
789+
u32 medium = 0;
790+
u32 large = 0;
791+
792+
for (int i = 0; i < BTRFS_NR_RAID_TYPES; ++i) {
793+
down_read(&sinfo->groups_sem);
794+
list_for_each_entry(bg, &sinfo->block_groups[i], list) {
795+
if (!btrfs_block_group_should_use_size_class(bg))
796+
continue;
797+
switch (bg->size_class) {
798+
case BTRFS_BG_SZ_NONE:
799+
none++;
800+
break;
801+
case BTRFS_BG_SZ_SMALL:
802+
small++;
803+
break;
804+
case BTRFS_BG_SZ_MEDIUM:
805+
medium++;
806+
break;
807+
case BTRFS_BG_SZ_LARGE:
808+
large++;
809+
break;
810+
}
811+
}
812+
up_read(&sinfo->groups_sem);
813+
}
814+
return sysfs_emit(buf, "none %u\n"
815+
"small %u\n"
816+
"medium %u\n"
817+
"large %u\n",
818+
none, small, medium, large);
819+
}
820+
781821
#ifdef CONFIG_BTRFS_DEBUG
782822
/*
783823
* Request chunk allocation with current chunk size.
@@ -835,6 +875,7 @@ SPACE_INFO_ATTR(bytes_zone_unusable);
835875
SPACE_INFO_ATTR(disk_used);
836876
SPACE_INFO_ATTR(disk_total);
837877
BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store);
878+
BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show);
838879

839880
static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj,
840881
struct kobj_attribute *a,
@@ -887,6 +928,7 @@ static struct attribute *space_info_attrs[] = {
887928
BTRFS_ATTR_PTR(space_info, disk_total),
888929
BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
889930
BTRFS_ATTR_PTR(space_info, chunk_size),
931+
BTRFS_ATTR_PTR(space_info, size_classes),
890932
#ifdef CONFIG_BTRFS_DEBUG
891933
BTRFS_ATTR_PTR(space_info, force_chunk_alloc),
892934
#endif

0 commit comments

Comments
 (0)