* [PATCH v2 v2 0/2] add blocks_allocated to mb_stats and clear mb_stats
@ 2026-04-19 6:34 Baolin Liu
2026-04-19 6:34 ` [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu
2026-04-19 6:34 ` [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu
0 siblings, 2 replies; 12+ messages in thread
From: Baolin Liu @ 2026-04-19 6:34 UTC (permalink / raw)
To: tytso, adilger.kernel
Cc: wangguanyu, liubaolin12138, yi.zhang, ritesh.list, ojaswin,
linux-ext4, linux-kernel
This series improves ext4 mballoc statistics in two small ways.
The first patch adds blocks_allocated to /proc/fs/ext4/<dev>/mb_stats,
so that the proc output covers the same mballoc summary counters
printed at unmount time.
The second patch makes /proc/fs/ext4/<dev>/mb_stats writable
and allows writing 0 to clear the current runtime mballoc statistics.
Changes since v1:
- Split blocks_allocated reporting and statistics clearing into two patches
- Drop the separate mb_stats_clear sysfs node
- Make /proc/fs/ext4/<dev>/mb_stats writable instead
Baolin Liu (2):
ext4: add blocks_allocated to mb_stats output
ext4: allow clearing mballoc stats through mb_stats
fs/ext4/ext4.h | 1 +
fs/ext4/mballoc.c | 31 +++++++++++++++++++++++++++++++
fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++--
3 files changed, 70 insertions(+), 2 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output
2026-04-19 6:34 [PATCH v2 v2 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu
@ 2026-04-19 6:34 ` Baolin Liu
2026-04-19 9:19 ` Andreas Dilger
2026-04-20 9:13 ` Ojaswin Mujoo
2026-04-19 6:34 ` [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu
1 sibling, 2 replies; 12+ messages in thread
From: Baolin Liu @ 2026-04-19 6:34 UTC (permalink / raw)
To: tytso, adilger.kernel
Cc: wangguanyu, liubaolin12138, yi.zhang, ritesh.list, ojaswin,
linux-ext4, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Add blocks_allocated to /proc/fs/ext4/<dev>/mb_stats so that the
reported statistics match the mballoc summary printed at unmount time.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ext4/mballoc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 20e9fdaf4301..1e13ef62cb9d 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3211,6 +3211,8 @@ int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
"\tTo enable, please write \"1\" to sysfs file mb_stats.\n");
return 0;
}
+ seq_printf(seq, "\tblocks_allocated: %u\n",
+ atomic_read(&sbi->s_bal_allocated));
seq_printf(seq, "\treqs: %u\n", atomic_read(&sbi->s_bal_reqs));
seq_printf(seq, "\tsuccess: %u\n", atomic_read(&sbi->s_bal_success));
--
2.51.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-19 6:34 [PATCH v2 v2 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu
2026-04-19 6:34 ` [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu
@ 2026-04-19 6:34 ` Baolin Liu
2026-04-19 9:23 ` Andreas Dilger
2026-04-20 9:12 ` Ojaswin Mujoo
1 sibling, 2 replies; 12+ messages in thread
From: Baolin Liu @ 2026-04-19 6:34 UTC (permalink / raw)
To: tytso, adilger.kernel
Cc: wangguanyu, liubaolin12138, yi.zhang, ritesh.list, ojaswin,
linux-ext4, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
mballoc statistics when 0 is written.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ext4/ext4.h | 1 +
fs/ext4/mballoc.c | 29 +++++++++++++++++++++++++++++
fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++--
3 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 293f698b7042..3223e73612ae 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2994,6 +2994,7 @@ int ext4_fc_record_regions(struct super_block *sb, int ino,
extern const struct seq_operations ext4_mb_seq_groups_ops;
extern const struct seq_operations ext4_mb_seq_structs_summary_ops;
extern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset);
+extern void ext4_mb_stats_clear(struct ext4_sb_info *sbi);
extern int ext4_mb_init(struct super_block *);
extern void ext4_mb_release(struct super_block *);
extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 1e13ef62cb9d..79ddfa935813 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4723,6 +4723,35 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
trace_ext4_mballoc_prealloc(ac);
}
+void ext4_mb_stats_clear(struct ext4_sb_info *sbi)
+{
+ int i;
+
+ atomic_set(&sbi->s_bal_reqs, 0);
+ atomic_set(&sbi->s_bal_success, 0);
+ atomic_set(&sbi->s_bal_allocated, 0);
+ atomic_set(&sbi->s_bal_groups_scanned, 0);
+
+ for (i = 0; i < EXT4_MB_NUM_CRS; i++) {
+ atomic64_set(&sbi->s_bal_cX_hits[i], 0);
+ atomic64_set(&sbi->s_bal_cX_groups_considered[i], 0);
+ atomic_set(&sbi->s_bal_cX_ex_scanned[i], 0);
+ atomic64_set(&sbi->s_bal_cX_failed[i], 0);
+ }
+
+ atomic_set(&sbi->s_bal_ex_scanned, 0);
+ atomic_set(&sbi->s_bal_goals, 0);
+ atomic_set(&sbi->s_bal_stream_goals, 0);
+ atomic_set(&sbi->s_bal_len_goals, 0);
+ atomic_set(&sbi->s_bal_2orders, 0);
+ atomic_set(&sbi->s_bal_breaks, 0);
+ atomic_set(&sbi->s_mb_lost_chunks, 0);
+ atomic_set(&sbi->s_mb_buddies_generated, 0);
+ atomic64_set(&sbi->s_mb_generation_time, 0);
+ atomic_set(&sbi->s_mb_preallocated, 0);
+ atomic_set(&sbi->s_mb_discarded, 0);
+}
+
/*
* Called on failure; free up any blocks from the inode PA for this
* context. We don't need this for MB_GROUP_PA because we only change
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index b87d7bdab06a..e90885d470ab 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -52,6 +52,42 @@ typedef enum {
static const char proc_dirname[] = "fs/ext4";
static struct proc_dir_entry *ext4_proc_root;
+static int ext4_mb_stats_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, ext4_seq_mb_stats_show, pde_data(inode));
+}
+
+static ssize_t ext4_mb_stats_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct super_block *sb = pde_data(file_inode(file));
+ char kbuf[2];
+
+ if (count == 0 || count > sizeof(kbuf))
+ return -EINVAL;
+
+ if (copy_from_user(kbuf, buf, count))
+ return -EFAULT;
+
+ if (count == 2) {
+ if (kbuf[0] != '0' || kbuf[1] != '\n')
+ return -EINVAL;
+ } else if (kbuf[0] != '0') {
+ return -EINVAL;
+ }
+
+ ext4_mb_stats_clear(EXT4_SB(sb));
+ return count;
+}
+
+static const struct proc_ops ext4_mb_stats_proc_ops = {
+ .proc_open = ext4_mb_stats_open,
+ .proc_read = seq_read,
+ .proc_lseek = seq_lseek,
+ .proc_release = single_release,
+ .proc_write = ext4_mb_stats_write,
+};
+
struct ext4_attr {
struct attribute attr;
short attr_id;
@@ -630,8 +666,8 @@ int ext4_register_sysfs(struct super_block *sb)
ext4_fc_info_show, sb);
proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
&ext4_mb_seq_groups_ops, sb);
- proc_create_single_data("mb_stats", 0444, sbi->s_proc,
- ext4_seq_mb_stats_show, sb);
+ proc_create_data("mb_stats", 0644, sbi->s_proc,
+ &ext4_mb_stats_proc_ops, sb);
proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc,
&ext4_mb_seq_structs_summary_ops, sb);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output
2026-04-19 6:34 ` [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu
@ 2026-04-19 9:19 ` Andreas Dilger
2026-04-20 9:13 ` Ojaswin Mujoo
1 sibling, 0 replies; 12+ messages in thread
From: Andreas Dilger @ 2026-04-19 9:19 UTC (permalink / raw)
To: Baolin Liu
Cc: tytso, wangguanyu, yi.zhang, ritesh.list, ojaswin, linux-ext4,
linux-kernel, Baolin Liu
On Apr 19, 2026, at 00:34, Baolin Liu <liubaolin12138@163.com> wrote:
>
> From: Baolin Liu <liubaolin@kylinos.cn>
>
> Add blocks_allocated to /proc/fs/ext4/<dev>/mb_stats so that the
> reported statistics match the mballoc summary printed at unmount time.
>
> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
Reviewed-by: Andreas Dilger <adilger@dilger.ca <mailto:adilger@dilger.ca>>
> ---
> fs/ext4/mballoc.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 20e9fdaf4301..1e13ef62cb9d 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3211,6 +3211,8 @@ int ext4_seq_mb_stats_show(struct seq_file *seq,
> "\tTo enable, please write \"1\" to sysfs file mb_stats.\n");
> return 0;
> }
> + seq_printf(seq, "\tblocks_allocated: %u\n",
> + atomic_read(&sbi->s_bal_allocated));
> seq_printf(seq, "\treqs: %u\n", atomic_read(&sbi->s_bal_reqs));
> seq_printf(seq, "\tsuccess: %u\n", atomic_read(&sbi->s_bal_success));
>
> --
> 2.51.0
>
Cheers, Andreas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-19 6:34 ` [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu
@ 2026-04-19 9:23 ` Andreas Dilger
2026-04-20 9:12 ` Ojaswin Mujoo
1 sibling, 0 replies; 12+ messages in thread
From: Andreas Dilger @ 2026-04-19 9:23 UTC (permalink / raw)
To: Baolin Liu
Cc: tytso, wangguanyu, yi.zhang, ritesh.list, ojaswin, linux-ext4,
linux-kernel, Baolin Liu
On Apr 19, 2026, at 00:34, Baolin Liu <liubaolin12138@163.com> wrote:
>
> From: Baolin Liu <liubaolin@kylinos.cn>
>
> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
> mballoc statistics when 0 is written.
>
> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
Reviewed-by: Andreas Dilger <adilger@dilger.ca <mailto:adilger@dilger.ca>>
> ---
> fs/ext4/ext4.h | 1 +
> fs/ext4/mballoc.c | 29 +++++++++++++++++++++++++++++
> fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++--
> 3 files changed, 68 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 293f698b7042..3223e73612ae 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2994,6 +2994,7 @@ int ext4_fc_record_regions(struct super_block *sb, int ino,
> extern const struct seq_operations ext4_mb_seq_groups_ops;
> extern const struct seq_operations ext4_mb_seq_structs_summary_ops;
> extern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset);
> +extern void ext4_mb_stats_clear(struct ext4_sb_info *sbi);
> extern int ext4_mb_init(struct super_block *);
> extern void ext4_mb_release(struct super_block *);
> extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 1e13ef62cb9d..79ddfa935813 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -4723,6 +4723,35 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
> trace_ext4_mballoc_prealloc(ac);
> }
>
> +void ext4_mb_stats_clear(struct ext4_sb_info *sbi)
> +{
> + int i;
> +
> + atomic_set(&sbi->s_bal_reqs, 0);
> + atomic_set(&sbi->s_bal_success, 0);
> + atomic_set(&sbi->s_bal_allocated, 0);
> + atomic_set(&sbi->s_bal_groups_scanned, 0);
> +
> + for (i = 0; i < EXT4_MB_NUM_CRS; i++) {
> + atomic64_set(&sbi->s_bal_cX_hits[i], 0);
> + atomic64_set(&sbi->s_bal_cX_groups_considered[i], 0);
> + atomic_set(&sbi->s_bal_cX_ex_scanned[i], 0);
> + atomic64_set(&sbi->s_bal_cX_failed[i], 0);
> + }
> +
> + atomic_set(&sbi->s_bal_ex_scanned, 0);
> + atomic_set(&sbi->s_bal_goals, 0);
> + atomic_set(&sbi->s_bal_stream_goals, 0);
> + atomic_set(&sbi->s_bal_len_goals, 0);
> + atomic_set(&sbi->s_bal_2orders, 0);
> + atomic_set(&sbi->s_bal_breaks, 0);
> + atomic_set(&sbi->s_mb_lost_chunks, 0);
> + atomic_set(&sbi->s_mb_buddies_generated, 0);
> + atomic64_set(&sbi->s_mb_generation_time, 0);
> + atomic_set(&sbi->s_mb_preallocated, 0);
> + atomic_set(&sbi->s_mb_discarded, 0);
> +}
> +
> /*
> * Called on failure; free up any blocks from the inode PA for this
> * context. We don't need this for MB_GROUP_PA because we only change
> diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
> index b87d7bdab06a..e90885d470ab 100644
> --- a/fs/ext4/sysfs.c
> +++ b/fs/ext4/sysfs.c
> @@ -52,6 +52,42 @@ typedef enum {
> static const char proc_dirname[] = "fs/ext4";
> static struct proc_dir_entry *ext4_proc_root;
>
> +static int ext4_mb_stats_open(struct inode *inode, struct file *file)
> +{
> + return single_open(file, ext4_seq_mb_stats_show, pde_data(inode));
> +}
> +
> +static ssize_t ext4_mb_stats_write(struct file *file, const char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + struct super_block *sb = pde_data(file_inode(file));
> + char kbuf[2];
> +
> + if (count == 0 || count > sizeof(kbuf))
> + return -EINVAL;
> +
> + if (copy_from_user(kbuf, buf, count))
> + return -EFAULT;
> +
> + if (count == 2) {
> + if (kbuf[0] != '0' || kbuf[1] != '\n')
> + return -EINVAL;
> + } else if (kbuf[0] != '0') {
> + return -EINVAL;
> + }
> +
> + ext4_mb_stats_clear(EXT4_SB(sb));
> + return count;
> +}
> +
> +static const struct proc_ops ext4_mb_stats_proc_ops = {
> + .proc_open = ext4_mb_stats_open,
> + .proc_read = seq_read,
> + .proc_lseek = seq_lseek,
> + .proc_release = single_release,
> + .proc_write = ext4_mb_stats_write,
> +};
> +
> struct ext4_attr {
> struct attribute attr;
> short attr_id;
> @@ -630,8 +666,8 @@ int ext4_register_sysfs(struct super_block *sb)
> ext4_fc_info_show, sb);
> proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
> &ext4_mb_seq_groups_ops, sb);
> - proc_create_single_data("mb_stats", 0444, sbi->s_proc,
> - ext4_seq_mb_stats_show, sb);
> + proc_create_data("mb_stats", 0644, sbi->s_proc,
> + &ext4_mb_stats_proc_ops, sb);
> proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc,
> &ext4_mb_seq_structs_summary_ops, sb);
> }
> --
> 2.51.0
>
Cheers, Andreas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-19 6:34 ` [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu
2026-04-19 9:23 ` Andreas Dilger
@ 2026-04-20 9:12 ` Ojaswin Mujoo
2026-04-20 18:28 ` Andreas Dilger
1 sibling, 1 reply; 12+ messages in thread
From: Ojaswin Mujoo @ 2026-04-20 9:12 UTC (permalink / raw)
To: Baolin Liu
Cc: tytso, adilger.kernel, wangguanyu, yi.zhang, ritesh.list,
linux-ext4, linux-kernel, Baolin Liu
On Sun, Apr 19, 2026 at 02:34:36PM +0800, Baolin Liu wrote:
> From: Baolin Liu <liubaolin@kylinos.cn>
>
> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
> mballoc statistics when 0 is written.
>
> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
> ---
Hi Baolin, thanks for the changes.
Seems like userspace doesn't have any way to know that writing 0 will
clear the that. Well, I guess if you are looking at this file you are
anyways debugging kernel code so that should be fine
Feel free to add:
Ojaswin Mujoo <ojaswin@linux.ibm.com>
Regards,
ojaswin
> fs/ext4/ext4.h | 1 +
> fs/ext4/mballoc.c | 29 +++++++++++++++++++++++++++++
> fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++--
> 3 files changed, 68 insertions(+), 2 deletions(-)
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output
2026-04-19 6:34 ` [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu
2026-04-19 9:19 ` Andreas Dilger
@ 2026-04-20 9:13 ` Ojaswin Mujoo
1 sibling, 0 replies; 12+ messages in thread
From: Ojaswin Mujoo @ 2026-04-20 9:13 UTC (permalink / raw)
To: Baolin Liu
Cc: tytso, adilger.kernel, wangguanyu, yi.zhang, ritesh.list,
linux-ext4, linux-kernel, Baolin Liu
On Sun, Apr 19, 2026 at 02:34:35PM +0800, Baolin Liu wrote:
> From: Baolin Liu <liubaolin@kylinos.cn>
>
> Add blocks_allocated to /proc/fs/ext4/<dev>/mb_stats so that the
> reported statistics match the mballoc summary printed at unmount time.
>
> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
> ---
Looks good,
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Regards,
ojaswin
> fs/ext4/mballoc.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 20e9fdaf4301..1e13ef62cb9d 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3211,6 +3211,8 @@ int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
> "\tTo enable, please write \"1\" to sysfs file mb_stats.\n");
> return 0;
> }
> + seq_printf(seq, "\tblocks_allocated: %u\n",
> + atomic_read(&sbi->s_bal_allocated));
> seq_printf(seq, "\treqs: %u\n", atomic_read(&sbi->s_bal_reqs));
> seq_printf(seq, "\tsuccess: %u\n", atomic_read(&sbi->s_bal_success));
>
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-20 9:12 ` Ojaswin Mujoo
@ 2026-04-20 18:28 ` Andreas Dilger
2026-04-21 3:40 ` Ritesh Harjani
0 siblings, 1 reply; 12+ messages in thread
From: Andreas Dilger @ 2026-04-20 18:28 UTC (permalink / raw)
To: Ojaswin Mujoo
Cc: Baolin Liu, tytso, wangguanyu, yi.zhang, ritesh.list, linux-ext4,
linux-kernel, Baolin Liu
On Apr 20, 2026, at 03:12, Ojaswin Mujoo <ojaswin@linux.ibm.com> wrote:
>
> On Sun, Apr 19, 2026 at 02:34:36PM +0800, Baolin Liu wrote:
>> From: Baolin Liu <liubaolin@kylinos.cn>
>>
>> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
>> mballoc statistics when 0 is written.
>>
>> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
>> ---
> Hi Baolin, thanks for the changes.
>
> Seems like userspace doesn't have any way to know that writing 0 will
> clear the that. Well, I guess if you are looking at this file you are
> anyways debugging kernel code so that should be fine
That could be documented in Documentation/filesystems/ext4/allocators.rst,
or better would be to add a new file that covers mballoc in more detail.
Cheers, Andreas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-20 18:28 ` Andreas Dilger
@ 2026-04-21 3:40 ` Ritesh Harjani
2026-04-21 5:22 ` liubaolin
0 siblings, 1 reply; 12+ messages in thread
From: Ritesh Harjani @ 2026-04-21 3:40 UTC (permalink / raw)
To: Andreas Dilger, Ojaswin Mujoo
Cc: Baolin Liu, tytso, wangguanyu, yi.zhang, linux-ext4, linux-kernel,
Baolin Liu
Andreas Dilger <adilger@dilger.ca> writes:
> On Apr 20, 2026, at 03:12, Ojaswin Mujoo <ojaswin@linux.ibm.com> wrote:
>>
>> On Sun, Apr 19, 2026 at 02:34:36PM +0800, Baolin Liu wrote:
>>> From: Baolin Liu <liubaolin@kylinos.cn>
>>>
>>> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
>>> mballoc statistics when 0 is written.
>>>
>>> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
>>> ---
>> Hi Baolin, thanks for the changes.
>>
>> Seems like userspace doesn't have any way to know that writing 0 will
>> clear the that. Well, I guess if you are looking at this file you are
>> anyways debugging kernel code so that should be fine
>
> That could be documented in Documentation/filesystems/ext4/allocators.rst,
> or better would be to add a new file that covers mballoc in more detail.
>
I started looking for ext4's control knobs for sys-admins in kernel
Documentation where we should ideally document this, and I see those
are declared here..
Documentation/admin-guide/ext4.rst
Documentation/ABI/testing/sysfs-fs-ext4.rst
Looking at this and the relevant code, I see all /proc/ entries in ext4
are all readable and sysfs entries for ext4 are mostly the control knobs
which are declared in above admin guide.
But now this patch adds a control knob to /proc/fs/ext4/<dev>/mb_stats,
to clear the stats :).
I guess we could have simply documented a new control knob value (e.g.
"2") for clearing the stats via /sys/fs/ext4/<dev>/mb_stats itself or
maybe even having mb_stats_clear file in sysfs wasn't bad either... But
either ways, clearing the stats via the same procfs mb_stats file is not
totally bad and I don't have a strong preference.
For documenting this, we can add mb_stats entry under /proc section in
Documentation/admin-guide/ext4.rst and document this change. Something
like -
mb_stats
reports runtime statistics from multiblock allocator (mballoc),
including allocation request counts, groups scanned,
per-criteria scan hits (cr_p2_aligned, cr_goal_fast,
cr_best_avail, cr_goal_slow, cr_any_free), groups / extents
scanned, goal hits, buddy bitmap generations, and preallocation
usage etc.
Writing 0 to this procfs file resets all counters to zero.
-ritesh
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-21 3:40 ` Ritesh Harjani
@ 2026-04-21 5:22 ` liubaolin
2026-04-21 6:12 ` Ojaswin Mujoo
0 siblings, 1 reply; 12+ messages in thread
From: liubaolin @ 2026-04-21 5:22 UTC (permalink / raw)
To: Ritesh Harjani (IBM), Andreas Dilger, Ojaswin Mujoo
Cc: tytso, wangguanyu, yi.zhang, linux-ext4, linux-kernel, Baolin Liu
Dear all,
I noticed the discussion about where to document the ext4 proc
parameter mb_stats.
I ran:
git grep -n "/proc/fs/ext4" Documentation/
and found that ext4 proc parameters are currently documented in both
Documentation/admin-guide/ext4.rst and
Documentation/filesystems/proc.rst.
To be consistent with the existing documentation, I am thinking
about documenting mb_stats in both places.
If there are no objections, I will send a v3 shortly.
Compared with v2,the v3 patch will add the mb_stats documentation to
both ext4.rst and proc.rst.
Regards,
Baolin
在 2026/4/21 11:40, Ritesh Harjani (IBM) 写道:
> Andreas Dilger <adilger@dilger.ca> writes:
>
>> On Apr 20, 2026, at 03:12, Ojaswin Mujoo <ojaswin@linux.ibm.com> wrote:
>>>
>>> On Sun, Apr 19, 2026 at 02:34:36PM +0800, Baolin Liu wrote:
>>>> From: Baolin Liu <liubaolin@kylinos.cn>
>>>>
>>>> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
>>>> mballoc statistics when 0 is written.
>>>>
>>>> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
>>>> ---
>>> Hi Baolin, thanks for the changes.
>>>
>>> Seems like userspace doesn't have any way to know that writing 0 will
>>> clear the that. Well, I guess if you are looking at this file you are
>>> anyways debugging kernel code so that should be fine
>>
>> That could be documented in Documentation/filesystems/ext4/allocators.rst,
>> or better would be to add a new file that covers mballoc in more detail.
>>
>
> I started looking for ext4's control knobs for sys-admins in kernel
> Documentation where we should ideally document this, and I see those
> are declared here..
>
> Documentation/admin-guide/ext4.rst
> Documentation/ABI/testing/sysfs-fs-ext4.rst
>
> Looking at this and the relevant code, I see all /proc/ entries in ext4
> are all readable and sysfs entries for ext4 are mostly the control knobs
> which are declared in above admin guide.
>
> But now this patch adds a control knob to /proc/fs/ext4/<dev>/mb_stats,
> to clear the stats :).
>
> I guess we could have simply documented a new control knob value (e.g.
> "2") for clearing the stats via /sys/fs/ext4/<dev>/mb_stats itself or
> maybe even having mb_stats_clear file in sysfs wasn't bad either... But
> either ways, clearing the stats via the same procfs mb_stats file is not
> totally bad and I don't have a strong preference.
>
>
> For documenting this, we can add mb_stats entry under /proc section in
> Documentation/admin-guide/ext4.rst and document this change. Something
> like -
>
> mb_stats
> reports runtime statistics from multiblock allocator (mballoc),
> including allocation request counts, groups scanned,
> per-criteria scan hits (cr_p2_aligned, cr_goal_fast,
> cr_best_avail, cr_goal_slow, cr_any_free), groups / extents
> scanned, goal hits, buddy bitmap generations, and preallocation
> usage etc.
> Writing 0 to this procfs file resets all counters to zero.
>
>
> -ritesh
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-21 5:22 ` liubaolin
@ 2026-04-21 6:12 ` Ojaswin Mujoo
2026-04-21 7:07 ` liubaolin
0 siblings, 1 reply; 12+ messages in thread
From: Ojaswin Mujoo @ 2026-04-21 6:12 UTC (permalink / raw)
To: liubaolin
Cc: Ritesh Harjani (IBM), Andreas Dilger, tytso, wangguanyu, yi.zhang,
linux-ext4, linux-kernel, Baolin Liu
On Tue, Apr 21, 2026 at 01:22:31PM +0800, liubaolin wrote:
> Dear all,
> I noticed the discussion about where to document the ext4 proc parameter
> mb_stats.
> I ran:
> git grep -n "/proc/fs/ext4" Documentation/
> and found that ext4 proc parameters are currently documented in both
> Documentation/admin-guide/ext4.rst and
> Documentation/filesystems/proc.rst.
>
> To be consistent with the existing documentation, I am thinking about
> documenting mb_stats in both places.
> If there are no objections, I will send a v3 shortly.
> Compared with v2,the v3 patch will add the mb_stats documentation to both
> ext4.rst and proc.rst.
Yes this makes sense to me. Feel free to retain the Reviewed-by since this is
just a documentation change.
Thanks,
Ojaswin
>
> Regards,
> Baolin
>
>
>
> 在 2026/4/21 11:40, Ritesh Harjani (IBM) 写道:
> > Andreas Dilger <adilger@dilger.ca> writes:
> >
> > > On Apr 20, 2026, at 03:12, Ojaswin Mujoo <ojaswin@linux.ibm.com> wrote:
> > > >
> > > > On Sun, Apr 19, 2026 at 02:34:36PM +0800, Baolin Liu wrote:
> > > > > From: Baolin Liu <liubaolin@kylinos.cn>
> > > > >
> > > > > Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
> > > > > mballoc statistics when 0 is written.
> > > > >
> > > > > Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
> > > > > ---
> > > > Hi Baolin, thanks for the changes.
> > > >
> > > > Seems like userspace doesn't have any way to know that writing 0 will
> > > > clear the that. Well, I guess if you are looking at this file you are
> > > > anyways debugging kernel code so that should be fine
> > >
> > > That could be documented in Documentation/filesystems/ext4/allocators.rst,
> > > or better would be to add a new file that covers mballoc in more detail.
> > >
> >
> > I started looking for ext4's control knobs for sys-admins in kernel
> > Documentation where we should ideally document this, and I see those
> > are declared here..
> >
> > Documentation/admin-guide/ext4.rst
> > Documentation/ABI/testing/sysfs-fs-ext4.rst
> >
> > Looking at this and the relevant code, I see all /proc/ entries in ext4
> > are all readable and sysfs entries for ext4 are mostly the control knobs
> > which are declared in above admin guide.
> >
> > But now this patch adds a control knob to /proc/fs/ext4/<dev>/mb_stats,
> > to clear the stats :).
> >
> > I guess we could have simply documented a new control knob value (e.g.
> > "2") for clearing the stats via /sys/fs/ext4/<dev>/mb_stats itself or
> > maybe even having mb_stats_clear file in sysfs wasn't bad either... But
> > either ways, clearing the stats via the same procfs mb_stats file is not
> > totally bad and I don't have a strong preference.
> >
> >
> > For documenting this, we can add mb_stats entry under /proc section in
> > Documentation/admin-guide/ext4.rst and document this change. Something
> > like -
> >
> > mb_stats
> > reports runtime statistics from multiblock allocator (mballoc),
> > including allocation request counts, groups scanned,
> > per-criteria scan hits (cr_p2_aligned, cr_goal_fast,
> > cr_best_avail, cr_goal_slow, cr_any_free), groups / extents
> > scanned, goal hits, buddy bitmap generations, and preallocation
> > usage etc.
> > Writing 0 to this procfs file resets all counters to zero.
> >
> >
> > -ritesh
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats
2026-04-21 6:12 ` Ojaswin Mujoo
@ 2026-04-21 7:07 ` liubaolin
0 siblings, 0 replies; 12+ messages in thread
From: liubaolin @ 2026-04-21 7:07 UTC (permalink / raw)
To: Ojaswin Mujoo
Cc: Ritesh Harjani (IBM), Andreas Dilger, tytso, wangguanyu, yi.zhang,
linux-ext4, linux-kernel, Baolin Liu
在 2026/4/21 14:12, Ojaswin Mujoo 写道:
> On Tue, Apr 21, 2026 at 01:22:31PM +0800, liubaolin wrote:
>> Dear all,
>> I noticed the discussion about where to document the ext4 proc parameter
>> mb_stats.
>> I ran:
>> git grep -n "/proc/fs/ext4" Documentation/
>> and found that ext4 proc parameters are currently documented in both
>> Documentation/admin-guide/ext4.rst and
>> Documentation/filesystems/proc.rst.
>>
>> To be consistent with the existing documentation, I am thinking about
>> documenting mb_stats in both places.
>> If there are no objections, I will send a v3 shortly.
>> Compared with v2,the v3 patch will add the mb_stats documentation to both
>> ext4.rst and proc.rst.
>
> Yes this makes sense to me. Feel free to retain the Reviewed-by since this is
> just a documentation change.
> OK, I will add all the reviewers who helped review my patch with Reviewed-by tags in the v3 version.
>
> Thanks,
> Ojaswin
>
>>
>> Regards,
>> Baolin
>>
>>
>>
>> 在 2026/4/21 11:40, Ritesh Harjani (IBM) 写道:
>>> Andreas Dilger <adilger@dilger.ca> writes:
>>>
>>>> On Apr 20, 2026, at 03:12, Ojaswin Mujoo <ojaswin@linux.ibm.com> wrote:
>>>>>
>>>>> On Sun, Apr 19, 2026 at 02:34:36PM +0800, Baolin Liu wrote:
>>>>>> From: Baolin Liu <liubaolin@kylinos.cn>
>>>>>>
>>>>>> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime
>>>>>> mballoc statistics when 0 is written.
>>>>>>
>>>>>> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
>>>>>> ---
>>>>> Hi Baolin, thanks for the changes.
>>>>>
>>>>> Seems like userspace doesn't have any way to know that writing 0 will
>>>>> clear the that. Well, I guess if you are looking at this file you are
>>>>> anyways debugging kernel code so that should be fine
>>>>
>>>> That could be documented in Documentation/filesystems/ext4/allocators.rst,
>>>> or better would be to add a new file that covers mballoc in more detail.
>>>>
>>>
>>> I started looking for ext4's control knobs for sys-admins in kernel
>>> Documentation where we should ideally document this, and I see those
>>> are declared here..
>>>
>>> Documentation/admin-guide/ext4.rst
>>> Documentation/ABI/testing/sysfs-fs-ext4.rst
>>>
>>> Looking at this and the relevant code, I see all /proc/ entries in ext4
>>> are all readable and sysfs entries for ext4 are mostly the control knobs
>>> which are declared in above admin guide.
>>>
>>> But now this patch adds a control knob to /proc/fs/ext4/<dev>/mb_stats,
>>> to clear the stats :).
>>>
>>> I guess we could have simply documented a new control knob value (e.g.
>>> "2") for clearing the stats via /sys/fs/ext4/<dev>/mb_stats itself or
>>> maybe even having mb_stats_clear file in sysfs wasn't bad either... But
>>> either ways, clearing the stats via the same procfs mb_stats file is not
>>> totally bad and I don't have a strong preference.
>>>
>>>
>>> For documenting this, we can add mb_stats entry under /proc section in
>>> Documentation/admin-guide/ext4.rst and document this change. Something
>>> like -
>>>
>>> mb_stats
>>> reports runtime statistics from multiblock allocator (mballoc),
>>> including allocation request counts, groups scanned,
>>> per-criteria scan hits (cr_p2_aligned, cr_goal_fast,
>>> cr_best_avail, cr_goal_slow, cr_any_free), groups / extents
>>> scanned, goal hits, buddy bitmap generations, and preallocation
>>> usage etc.
>>> Writing 0 to this procfs file resets all counters to zero.
>>>
>>>
>>> -ritesh
>>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-04-21 7:08 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 6:34 [PATCH v2 v2 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu
2026-04-19 6:34 ` [PATCH v2 v2 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu
2026-04-19 9:19 ` Andreas Dilger
2026-04-20 9:13 ` Ojaswin Mujoo
2026-04-19 6:34 ` [PATCH v2 v2 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu
2026-04-19 9:23 ` Andreas Dilger
2026-04-20 9:12 ` Ojaswin Mujoo
2026-04-20 18:28 ` Andreas Dilger
2026-04-21 3:40 ` Ritesh Harjani
2026-04-21 5:22 ` liubaolin
2026-04-21 6:12 ` Ojaswin Mujoo
2026-04-21 7:07 ` liubaolin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox