* [PATCH v2] btrfs: add size class stats to sysfs
@ 2023-01-27 21:56 Boris Burkov
2023-01-30 16:44 ` Anand Jain
2023-02-07 15:51 ` David Sterba
0 siblings, 2 replies; 4+ messages in thread
From: Boris Burkov @ 2023-01-27 21:56 UTC (permalink / raw)
To: linux-btrfs, kernel-team
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/<uid>/allocation/<bg-type>/size_class
but they will only be non-zero for bg-type = data.
Signed-off-by: Boris Burkov <boris@bur.io>
---
Changelog:
v2:
- add sysfs path to commit message
- unsigned counter types
- labeled stat-per-line output format
fs/btrfs/sysfs.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 108aa3876186..639f3842f99d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -9,6 +9,7 @@
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/bug.h>
+#include <linux/list.h>
#include <crypto/hash.h>
#include "messages.h"
#include "ctree.h"
@@ -778,6 +779,40 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
return len;
}
+static ssize_t btrfs_size_classes_show(struct kobject *kobj,
+ struct kobj_attribute *a, char *buf)
+{
+ struct btrfs_space_info *sinfo = to_space_info(kobj);
+ struct btrfs_block_group *bg;
+ u32 none = 0;
+ u32 small = 0;
+ u32 medium = 0;
+ u32 large = 0;
+
+ for (int i = 0; i < BTRFS_NR_RAID_TYPES; ++i) {
+ list_for_each_entry(bg, &sinfo->block_groups[i], list) {
+ if (!btrfs_block_group_should_use_size_class(bg))
+ continue;
+ switch (bg->size_class) {
+ case BTRFS_BG_SZ_NONE:
+ none++;
+ break;
+ case BTRFS_BG_SZ_SMALL:
+ small++;
+ break;
+ case BTRFS_BG_SZ_MEDIUM:
+ medium++;
+ break;
+ case BTRFS_BG_SZ_LARGE:
+ large++;
+ break;
+ }
+ }
+ }
+ return sysfs_emit(buf, "none %u\nsmall %u\nmedium %u\nlarge %u\n",
+ none, small, medium, large);
+}
+
#ifdef CONFIG_BTRFS_DEBUG
/*
* Request chunk allocation with current chunk size.
@@ -835,6 +870,7 @@ SPACE_INFO_ATTR(bytes_zone_unusable);
SPACE_INFO_ATTR(disk_used);
SPACE_INFO_ATTR(disk_total);
BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store);
+BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show);
static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj,
struct kobj_attribute *a,
@@ -887,6 +923,7 @@ static struct attribute *space_info_attrs[] = {
BTRFS_ATTR_PTR(space_info, disk_total),
BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
BTRFS_ATTR_PTR(space_info, chunk_size),
+ BTRFS_ATTR_PTR(space_info, size_classes),
#ifdef CONFIG_BTRFS_DEBUG
BTRFS_ATTR_PTR(space_info, force_chunk_alloc),
#endif
--
2.38.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] btrfs: add size class stats to sysfs
2023-01-27 21:56 [PATCH v2] btrfs: add size class stats to sysfs Boris Burkov
@ 2023-01-30 16:44 ` Anand Jain
2023-02-07 15:51 ` David Sterba
1 sibling, 0 replies; 4+ messages in thread
From: Anand Jain @ 2023-01-30 16:44 UTC (permalink / raw)
To: Boris Burkov, linux-btrfs, kernel-team
On 1/28/23 05:56, Boris Burkov wrote:
> 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.
We could place debug/testing feature in CONFIG_BTRFS_DEBUG. If not, how
would the user be aware of the class size range in non-debugging cases?
Otherwise, the change looks good.
Thanks, Anand
>
> The new stats can be found at the path:
> /sys/fs/btrfs/<uid>/allocation/<bg-type>/size_class
> but they will only be non-zero for bg-type = data.
>
> Signed-off-by: Boris Burkov <boris@bur.io>
> ---
> Changelog:
> v2:
> - add sysfs path to commit message
> - unsigned counter types
> - labeled stat-per-line output format
>
> fs/btrfs/sysfs.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 108aa3876186..639f3842f99d 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -9,6 +9,7 @@
> #include <linux/spinlock.h>
> #include <linux/completion.h>
> #include <linux/bug.h>
> +#include <linux/list.h>
> #include <crypto/hash.h>
> #include "messages.h"
> #include "ctree.h"
> @@ -778,6 +779,40 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
> return len;
> }
>
> +static ssize_t btrfs_size_classes_show(struct kobject *kobj,
> + struct kobj_attribute *a, char *buf)
> +{
> + struct btrfs_space_info *sinfo = to_space_info(kobj);
> + struct btrfs_block_group *bg;
> + u32 none = 0;
> + u32 small = 0;
> + u32 medium = 0;
> + u32 large = 0;
> +
> + for (int i = 0; i < BTRFS_NR_RAID_TYPES; ++i) {
> + list_for_each_entry(bg, &sinfo->block_groups[i], list) {
> + if (!btrfs_block_group_should_use_size_class(bg))
> + continue;
> + switch (bg->size_class) {
> + case BTRFS_BG_SZ_NONE:
> + none++;
> + break;
> + case BTRFS_BG_SZ_SMALL:
> + small++;
> + break;
> + case BTRFS_BG_SZ_MEDIUM:
> + medium++;
> + break;
> + case BTRFS_BG_SZ_LARGE:
> + large++;
> + break;
> + }
> + }
> + }
> + return sysfs_emit(buf, "none %u\nsmall %u\nmedium %u\nlarge %u\n",
> + none, small, medium, large);
> +}
> +
> #ifdef CONFIG_BTRFS_DEBUG
> /*
> * Request chunk allocation with current chunk size.
> @@ -835,6 +870,7 @@ SPACE_INFO_ATTR(bytes_zone_unusable);
> SPACE_INFO_ATTR(disk_used);
> SPACE_INFO_ATTR(disk_total);
> BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store);
> +BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show);
>
> static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj,
> struct kobj_attribute *a,
> @@ -887,6 +923,7 @@ static struct attribute *space_info_attrs[] = {
> BTRFS_ATTR_PTR(space_info, disk_total),
> BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
> BTRFS_ATTR_PTR(space_info, chunk_size),
> + BTRFS_ATTR_PTR(space_info, size_classes),
> #ifdef CONFIG_BTRFS_DEBUG
> BTRFS_ATTR_PTR(space_info, force_chunk_alloc),
> #endif
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] btrfs: add size class stats to sysfs
2023-01-27 21:56 [PATCH v2] btrfs: add size class stats to sysfs Boris Burkov
2023-01-30 16:44 ` Anand Jain
@ 2023-02-07 15:51 ` David Sterba
2023-02-07 17:29 ` Boris Burkov
1 sibling, 1 reply; 4+ messages in thread
From: David Sterba @ 2023-02-07 15:51 UTC (permalink / raw)
To: Boris Burkov; +Cc: linux-btrfs, kernel-team
On Fri, Jan 27, 2023 at 01:56:50PM -0800, Boris Burkov wrote:
> 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/<uid>/allocation/<bg-type>/size_class
> but they will only be non-zero for bg-type = data.
>
> Signed-off-by: Boris Burkov <boris@bur.io>
> ---
> Changelog:
> v2:
> - add sysfs path to commit message
> - unsigned counter types
> - labeled stat-per-line output format
>
> fs/btrfs/sysfs.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 108aa3876186..639f3842f99d 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -9,6 +9,7 @@
> #include <linux/spinlock.h>
> #include <linux/completion.h>
> #include <linux/bug.h>
> +#include <linux/list.h>
> #include <crypto/hash.h>
> #include "messages.h"
> #include "ctree.h"
> @@ -778,6 +779,40 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
> return len;
> }
>
> +static ssize_t btrfs_size_classes_show(struct kobject *kobj,
> + struct kobj_attribute *a, char *buf)
> +{
> + struct btrfs_space_info *sinfo = to_space_info(kobj);
> + struct btrfs_block_group *bg;
> + u32 none = 0;
> + u32 small = 0;
> + u32 medium = 0;
> + u32 large = 0;
> +
> + for (int i = 0; i < BTRFS_NR_RAID_TYPES; ++i) {
> + list_for_each_entry(bg, &sinfo->block_groups[i], list) {
Some locking is needed, you can eventually lock only iteration of one
sinfo and not the whole for cycle. Otherwise looks good.
> + if (!btrfs_block_group_should_use_size_class(bg))
> + continue;
> + switch (bg->size_class) {
> + case BTRFS_BG_SZ_NONE:
> + none++;
> + break;
> + case BTRFS_BG_SZ_SMALL:
> + small++;
> + break;
> + case BTRFS_BG_SZ_MEDIUM:
> + medium++;
> + break;
> + case BTRFS_BG_SZ_LARGE:
> + large++;
> + break;
> + }
> + }
> + }
> + return sysfs_emit(buf, "none %u\nsmall %u\nmedium %u\nlarge %u\n",
> + none, small, medium, large);
> +}
> +
> #ifdef CONFIG_BTRFS_DEBUG
> /*
> * Request chunk allocation with current chunk size.
> @@ -835,6 +870,7 @@ SPACE_INFO_ATTR(bytes_zone_unusable);
> SPACE_INFO_ATTR(disk_used);
> SPACE_INFO_ATTR(disk_total);
> BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store);
> +BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show);
>
> static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj,
> struct kobj_attribute *a,
> @@ -887,6 +923,7 @@ static struct attribute *space_info_attrs[] = {
> BTRFS_ATTR_PTR(space_info, disk_total),
> BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
> BTRFS_ATTR_PTR(space_info, chunk_size),
> + BTRFS_ATTR_PTR(space_info, size_classes),
> #ifdef CONFIG_BTRFS_DEBUG
> BTRFS_ATTR_PTR(space_info, force_chunk_alloc),
> #endif
> --
> 2.38.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] btrfs: add size class stats to sysfs
2023-02-07 15:51 ` David Sterba
@ 2023-02-07 17:29 ` Boris Burkov
0 siblings, 0 replies; 4+ messages in thread
From: Boris Burkov @ 2023-02-07 17:29 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs, kernel-team
On Tue, Feb 07, 2023 at 04:51:01PM +0100, David Sterba wrote:
> On Fri, Jan 27, 2023 at 01:56:50PM -0800, Boris Burkov wrote:
> > 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/<uid>/allocation/<bg-type>/size_class
> > but they will only be non-zero for bg-type = data.
> >
> > Signed-off-by: Boris Burkov <boris@bur.io>
> > ---
> > Changelog:
> > v2:
> > - add sysfs path to commit message
> > - unsigned counter types
> > - labeled stat-per-line output format
> >
> > fs/btrfs/sysfs.c | 37 +++++++++++++++++++++++++++++++++++++
> > 1 file changed, 37 insertions(+)
> >
> > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> > index 108aa3876186..639f3842f99d 100644
> > --- a/fs/btrfs/sysfs.c
> > +++ b/fs/btrfs/sysfs.c
> > @@ -9,6 +9,7 @@
> > #include <linux/spinlock.h>
> > #include <linux/completion.h>
> > #include <linux/bug.h>
> > +#include <linux/list.h>
> > #include <crypto/hash.h>
> > #include "messages.h"
> > #include "ctree.h"
> > @@ -778,6 +779,40 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
> > return len;
> > }
> >
> > +static ssize_t btrfs_size_classes_show(struct kobject *kobj,
> > + struct kobj_attribute *a, char *buf)
> > +{
> > + struct btrfs_space_info *sinfo = to_space_info(kobj);
> > + struct btrfs_block_group *bg;
> > + u32 none = 0;
> > + u32 small = 0;
> > + u32 medium = 0;
> > + u32 large = 0;
> > +
> > + for (int i = 0; i < BTRFS_NR_RAID_TYPES; ++i) {
> > + list_for_each_entry(bg, &sinfo->block_groups[i], list) {
>
> Some locking is needed, you can eventually lock only iteration of one
> sinfo and not the whole for cycle. Otherwise looks good.
That sounds like a good way to go to me, as well. Thanks for the review.
>
> > + if (!btrfs_block_group_should_use_size_class(bg))
> > + continue;
> > + switch (bg->size_class) {
> > + case BTRFS_BG_SZ_NONE:
> > + none++;
> > + break;
> > + case BTRFS_BG_SZ_SMALL:
> > + small++;
> > + break;
> > + case BTRFS_BG_SZ_MEDIUM:
> > + medium++;
> > + break;
> > + case BTRFS_BG_SZ_LARGE:
> > + large++;
> > + break;
> > + }
> > + }
> > + }
> > + return sysfs_emit(buf, "none %u\nsmall %u\nmedium %u\nlarge %u\n",
> > + none, small, medium, large);
> > +}
> > +
> > #ifdef CONFIG_BTRFS_DEBUG
> > /*
> > * Request chunk allocation with current chunk size.
> > @@ -835,6 +870,7 @@ SPACE_INFO_ATTR(bytes_zone_unusable);
> > SPACE_INFO_ATTR(disk_used);
> > SPACE_INFO_ATTR(disk_total);
> > BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store);
> > +BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show);
> >
> > static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj,
> > struct kobj_attribute *a,
> > @@ -887,6 +923,7 @@ static struct attribute *space_info_attrs[] = {
> > BTRFS_ATTR_PTR(space_info, disk_total),
> > BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
> > BTRFS_ATTR_PTR(space_info, chunk_size),
> > + BTRFS_ATTR_PTR(space_info, size_classes),
> > #ifdef CONFIG_BTRFS_DEBUG
> > BTRFS_ATTR_PTR(space_info, force_chunk_alloc),
> > #endif
> > --
> > 2.38.1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-07 17:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-27 21:56 [PATCH v2] btrfs: add size class stats to sysfs Boris Burkov
2023-01-30 16:44 ` Anand Jain
2023-02-07 15:51 ` David Sterba
2023-02-07 17:29 ` Boris Burkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox