* [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats
@ 2026-04-22 1:50 Baolin Liu
2026-04-22 1:50 ` [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Baolin Liu @ 2026-04-22 1:50 UTC (permalink / raw)
To: tytso, adilger.kernel, ojaswin, ritesh.list, yi.zhang
Cc: linux-ext4, linux-kernel, wangguanyu, liubaolin12138
The series contains two patches:
- add blocks_allocated to /proc/fs/ext4/<dev>/mb_stats
- allow writing 0 to /proc/fs/ext4/<dev>/mb_stats to clear the current
mballoc statistics
Changes since v2:
- Add mb_stats documentation to patch 2
- Add Reviewed-by tags
Baolin Liu (2):
ext4: add blocks_allocated to mb_stats output
ext4: allow clearing mballoc stats through mb_stats
Documentation/admin-guide/ext4.rst | 5 ++++
Documentation/filesystems/proc.rst | 3 +++
fs/ext4/ext4.h | 1 +
fs/ext4/mballoc.c | 31 +++++++++++++++++++++++
fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++--
5 files changed, 78 insertions(+), 2 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output 2026-04-22 1:50 [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu @ 2026-04-22 1:50 ` Baolin Liu 2026-04-24 2:35 ` Baokun Li 2026-04-22 1:50 ` [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu 2026-04-22 9:55 ` [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats liubaolin 2 siblings, 1 reply; 10+ messages in thread From: Baolin Liu @ 2026-04-22 1:50 UTC (permalink / raw) To: tytso, adilger.kernel, ojaswin, ritesh.list, yi.zhang Cc: linux-ext4, linux-kernel, wangguanyu, liubaolin12138, Baolin Liu, Andreas Dilger 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. Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> 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] 10+ messages in thread
* Re: [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output 2026-04-22 1:50 ` [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu @ 2026-04-24 2:35 ` Baokun Li 0 siblings, 0 replies; 10+ messages in thread From: Baokun Li @ 2026-04-24 2:35 UTC (permalink / raw) To: Baolin Liu Cc: tytso, adilger.kernel, ojaswin, ritesh.list, yi.zhang, linux-ext4, linux-kernel, wangguanyu, Baolin Liu, Andreas Dilger On 2026/4/22 09:50, 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. > > Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> > Reviewed-by: Andreas Dilger <adilger@dilger.ca> > Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> > Reviewed-by: Zhang Yi <yi.zhang@huawei.com> > Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Looks good, feel free to add: Reviewed-by: Baokun Li <libaokun@linux.alibaba.com> > --- > 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)); > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats 2026-04-22 1:50 [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu 2026-04-22 1:50 ` [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu @ 2026-04-22 1:50 ` Baolin Liu 2026-04-23 16:19 ` Theodore Tso 2026-04-22 9:55 ` [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats liubaolin 2 siblings, 1 reply; 10+ messages in thread From: Baolin Liu @ 2026-04-22 1:50 UTC (permalink / raw) To: tytso, adilger.kernel, ojaswin, ritesh.list, yi.zhang Cc: linux-ext4, linux-kernel, wangguanyu, liubaolin12138, Baolin Liu, Andreas Dilger From: Baolin Liu <liubaolin@kylinos.cn> Make /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime mballoc statistics when 0 is written. Update the related documentation accordingly. Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> --- Documentation/admin-guide/ext4.rst | 5 ++++ Documentation/filesystems/proc.rst | 3 +++ fs/ext4/ext4.h | 1 + fs/ext4/mballoc.c | 29 ++++++++++++++++++++++ fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++-- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/ext4.rst b/Documentation/admin-guide/ext4.rst index ac0c709ea9e7..fb3887cd5e44 100644 --- a/Documentation/admin-guide/ext4.rst +++ b/Documentation/admin-guide/ext4.rst @@ -436,6 +436,11 @@ Files in /proc/fs/ext4/<devname> mb_groups details of multiblock allocator buddy cache of free blocks + mb_stats + reports runtime statistics from the multiblock allocator + (mballoc). Writing 0 to this file clears the current + statistics. + /sys entries ============ diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index b0c0d1b45b99..7ce02573a3d9 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -1634,6 +1634,9 @@ directory are shown in Table 1-12, below. ============== ========================================================== File Content mb_groups details of multiblock allocator buddy cache of free blocks + mb_stats reports runtime statistics from the multiblock allocator + (mballoc). Writing 0 to this file clears the current + statistics. ============== ========================================================== 1.9 /proc/consoles 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] 10+ messages in thread
* Re: [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats 2026-04-22 1:50 ` [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu @ 2026-04-23 16:19 ` Theodore Tso 2026-04-24 3:12 ` Baokun Li 2026-04-24 8:09 ` liubaolin 0 siblings, 2 replies; 10+ messages in thread From: Theodore Tso @ 2026-04-23 16:19 UTC (permalink / raw) To: Baolin Liu Cc: adilger.kernel, ojaswin, ritesh.list, yi.zhang, linux-ext4, linux-kernel, wangguanyu, Baolin Liu, Andreas Dilger On Wed, Apr 22, 2026 at 09:50:25AM +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. At the moment to enable mb_stats the system administrator needs to write "1" to /sys/fs/ext4/<dev>/mb_stats, and writing "0" to the sysfs file will pauce the statistics colleciton (but not clear the statistics). Adding a way to clear the statistics by writing to the procfs file might be confusing to users. So.... as a suggestion, if you're adding to the ability to write to /proc/fs/.../mb_stats, what if we make things work by * Write 1 to /proc/fs/.../mb_stats to enable statistics collection * Write 0 to /proc/fs/.../mb_stats to disable statistics collection * Write -1 to /proc/fs/.../mb_stats to clear statistics counters And then deprecate the /sys/fs/.../mb_stats variable (but we probably won't be able to remove it for at least a year or two). - Ted ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats 2026-04-23 16:19 ` Theodore Tso @ 2026-04-24 3:12 ` Baokun Li 2026-04-24 8:09 ` liubaolin 1 sibling, 0 replies; 10+ messages in thread From: Baokun Li @ 2026-04-24 3:12 UTC (permalink / raw) To: Theodore Tso, Baolin Liu Cc: adilger.kernel, ojaswin, ritesh.list, yi.zhang, linux-ext4, linux-kernel, wangguanyu, Baolin Liu, Andreas Dilger On 2026/4/24 00:19, Theodore Tso wrote: > On Wed, Apr 22, 2026 at 09:50:25AM +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. > At the moment to enable mb_stats the system administrator needs to > write "1" to /sys/fs/ext4/<dev>/mb_stats, and writing "0" to the sysfs > file will pauce the statistics colleciton (but not clear the > statistics). Adding a way to clear the statistics by writing to the > procfs file might be confusing to users. > > So.... as a suggestion, if you're adding to the ability to write to > /proc/fs/.../mb_stats, what if we make things work by > > * Write 1 to /proc/fs/.../mb_stats to enable statistics collection > * Write 0 to /proc/fs/.../mb_stats to disable statistics collection > * Write -1 to /proc/fs/.../mb_stats to clear statistics counters > > And then deprecate the /sys/fs/.../mb_stats variable (but we probably > won't be able to remove it for at least a year or two). I like this idea. Consolidating everything into /proc/fs/.../mb_stats and using -1 to reset the counters is much cleaner than the current split approach. Cheers, Baokun ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats 2026-04-23 16:19 ` Theodore Tso 2026-04-24 3:12 ` Baokun Li @ 2026-04-24 8:09 ` liubaolin 2026-04-24 9:34 ` Baokun Li 2026-04-24 12:07 ` Theodore Tso 1 sibling, 2 replies; 10+ messages in thread From: liubaolin @ 2026-04-24 8:09 UTC (permalink / raw) To: Theodore Tso, libaokun Cc: adilger.kernel, ojaswin, ritesh.list, yi.zhang, linux-ext4, linux-kernel, wangguanyu, Baolin Liu, Andreas Dilger 在 2026/4/24 0:19, Theodore Tso 写道: > On Wed, Apr 22, 2026 at 09:50:25AM +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. > > At the moment to enable mb_stats the system administrator needs to > write "1" to /sys/fs/ext4/<dev>/mb_stats, and writing "0" to the sysfs > file will pauce the statistics colleciton (but not clear the > statistics). Adding a way to clear the statistics by writing to the > procfs file might be confusing to users. > > So.... as a suggestion, if you're adding to the ability to write to > /proc/fs/.../mb_stats, what if we make things work by > > * Write 1 to /proc/fs/.../mb_stats to enable statistics collection > * Write 0 to /proc/fs/.../mb_stats to disable statistics collection > * Write -1 to /proc/fs/.../mb_stats to clear statistics counters > > And then deprecate the /sys/fs/.../mb_stats variable (but we probably > won't be able to remove it for at least a year or two). > > - Ted Dear Ted, Baokun, Thank you for your review and suggestions. Since you mentioned that /sys/fs/.../mb_stats cannot be deleted in the short term, I plan to modify and submit a v4 patch according to the following strategy. 1. Change `/proc/fs/.../mb_stats` to read-write mode. * Read `/proc/fs/.../mb_stats` to show statistics counters. * Write 0 to `/proc/fs/.../mb_stats` to disable statistics collection. * Write 1 to `/proc/fs/.../mb_stats` to enable statistics collection. * Write 2 to `/proc/fs/.../mb_stats` to clear statistics counters. 2. Do not delete the `/sys/fs/.../mb_stats` node for now; implement the same write control logic. * Write 0 to `/sys/fs/.../mb_stats` to disable statistics collection. * Write 1 to `/sys/fs/.../mb_stats` to enable statistics collection. * Write 2 to `/sys/fs/.../mb_stats` to clear statistics counters. Delete `/sys/fs/.../mb_stats` later when it is possible to delete it. 3. Modify the relevant documentation for `mb_stats`. Documentation/ABI/testing/sysfs-fs-ext4 Documentation/admin-guide/ext4.rst Documentation/filesystems/proc.rst Compared to your suggestion, I recommend using the value 2 for the clear operation because s_mb_stats is an unsigned int variable, and using -1 requires changing the variable type. I suggest avoiding changing the s_mb_stats variable type unless absolutely necessary. Do you think this modification is appropriate? If there are no problems, I will start modifying the code and submit the v4 patch as soon as possible. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats 2026-04-24 8:09 ` liubaolin @ 2026-04-24 9:34 ` Baokun Li 2026-04-24 12:07 ` Theodore Tso 1 sibling, 0 replies; 10+ messages in thread From: Baokun Li @ 2026-04-24 9:34 UTC (permalink / raw) To: liubaolin, Theodore Tso Cc: adilger.kernel, ojaswin, ritesh.list, yi.zhang, linux-ext4, linux-kernel, wangguanyu, Baolin Liu, Andreas Dilger On 2026/4/24 16:09, liubaolin wrote: > > > 在 2026/4/24 0:19, Theodore Tso 写道: >> On Wed, Apr 22, 2026 at 09:50:25AM +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. >> >> At the moment to enable mb_stats the system administrator needs to >> write "1" to /sys/fs/ext4/<dev>/mb_stats, and writing "0" to the sysfs >> file will pauce the statistics colleciton (but not clear the >> statistics). Adding a way to clear the statistics by writing to the >> procfs file might be confusing to users. >> >> So.... as a suggestion, if you're adding to the ability to write to >> /proc/fs/.../mb_stats, what if we make things work by >> >> * Write 1 to /proc/fs/.../mb_stats to enable statistics collection >> * Write 0 to /proc/fs/.../mb_stats to disable statistics collection >> * Write -1 to /proc/fs/.../mb_stats to clear statistics counters >> >> And then deprecate the /sys/fs/.../mb_stats variable (but we probably >> won't be able to remove it for at least a year or two). >> >> - Ted > Dear Ted, Baokun, > Thank you for your review and suggestions. > Since you mentioned that /sys/fs/.../mb_stats cannot be deleted in > the short term, > I plan to modify and submit a v4 patch according to the following > strategy. > > 1. Change `/proc/fs/.../mb_stats` to read-write mode. > * Read `/proc/fs/.../mb_stats` to show statistics counters. > * Write 0 to `/proc/fs/.../mb_stats` to disable statistics > collection. > * Write 1 to `/proc/fs/.../mb_stats` to enable statistics collection. > * Write 2 to `/proc/fs/.../mb_stats` to clear statistics counters. > > 2. Do not delete the `/sys/fs/.../mb_stats` node for now; implement > the same write control logic. > * Write 0 to `/sys/fs/.../mb_stats` to disable statistics collection. > * Write 1 to `/sys/fs/.../mb_stats` to enable statistics collection. > * Write 2 to `/sys/fs/.../mb_stats` to clear statistics counters. > > Delete `/sys/fs/.../mb_stats` later when it is possible to delete it. > > 3. Modify the relevant documentation for `mb_stats`. > Documentation/ABI/testing/sysfs-fs-ext4 > Documentation/admin-guide/ext4.rst > Documentation/filesystems/proc.rst > > Compared to your suggestion, I recommend using the value 2 for the > clear operation because s_mb_stats is an unsigned int variable, and > using -1 requires changing the variable type. > I suggest avoiding changing the s_mb_stats variable type unless > absolutely necessary. > > Do you think this modification is appropriate? > If there are no problems, I will start modifying the code and > submit the v4 patch as soon as possible. For the clear command, we only handle it without storing it, so s_mb_stats remains unchanged and still stores only 0 and non-zero values to represent disabled and enabled, respectively. Otherwise, you will have to deal with a large number of s_mb_stats checks That means the /sys/fs/.../mb_stats interface does not need to support clearing, but it might make sense to add a deprecation warning there. Then in `/proc/fs/.../mb_stats`, writing 0 or a positive number passes it to s_mb_stats, writing -1 performs a reset, and other negative values return -EINVAL. Cheers, Baokun ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats 2026-04-24 8:09 ` liubaolin 2026-04-24 9:34 ` Baokun Li @ 2026-04-24 12:07 ` Theodore Tso 1 sibling, 0 replies; 10+ messages in thread From: Theodore Tso @ 2026-04-24 12:07 UTC (permalink / raw) To: liubaolin Cc: libaokun, adilger.kernel, ojaswin, ritesh.list, yi.zhang, linux-ext4, linux-kernel, wangguanyu, Baolin Liu, Andreas Dilger On Fri, Apr 24, 2026 at 04:09:31PM +0800, liubaolin wrote: > > 2. Do not delete the `/sys/fs/.../mb_stats` node for now; implement the > same write control logic. > * Write 0 to `/sys/fs/.../mb_stats` to disable statistics collection. > * Write 1 to `/sys/fs/.../mb_stats` to enable statistics collection. > * Write 2 to `/sys/fs/.../mb_stats` to clear statistics counters. We could do that, but note that currently writing to /sys/fs/.../mb_stats just sets an unsigned integer in EXT4(sb)->s_mb_stats. There is no ext4-specific function that runs when /sys/fs/.../mb_stats is updated. So either you have to add some check in fs/ext4/mballoc.c which gets called every single time a block allocation happens --- and consider the race condition where two CPU's are checking s_mb_stats at the same time, and the desireability of adding a spinlock that would need to be taken every single time a block allocation happens ---- or you have add an ext4-specific function in fs/ext4/sysfs.c. > Compared to your suggestion, I recommend using the value 2 for the clear > operation because s_mb_stats is an unsigned int variable, and using -1 > requires changing the variable type. Well, since you have introduced an ext4-specific function which gets called when writing to the procfs file, that function can clear the statistics counter when -1 is written to the file --- and then set s_mbi_stats to 1. Cheers, - Ted ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats 2026-04-22 1:50 [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu 2026-04-22 1:50 ` [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu 2026-04-22 1:50 ` [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu @ 2026-04-22 9:55 ` liubaolin 2 siblings, 0 replies; 10+ messages in thread From: liubaolin @ 2026-04-22 9:55 UTC (permalink / raw) To: tytso, adilger.kernel, ojaswin, ritesh.list, yi.zhang Cc: linux-ext4, linux-kernel, wangguanyu 在 2026/4/22 9:50, Baolin Liu 写道: > The series contains two patches: > - add blocks_allocated to /proc/fs/ext4/<dev>/mb_stats > - allow writing 0 to /proc/fs/ext4/<dev>/mb_stats to clear the current > mballoc statistics > > Changes since v2: > - Add mb_stats documentation to patch 2 > - Add Reviewed-by tags > > Baolin Liu (2): > ext4: add blocks_allocated to mb_stats output > ext4: allow clearing mballoc stats through mb_stats > > Documentation/admin-guide/ext4.rst | 5 ++++ > Documentation/filesystems/proc.rst | 3 +++ > fs/ext4/ext4.h | 1 + > fs/ext4/mballoc.c | 31 +++++++++++++++++++++++ > fs/ext4/sysfs.c | 40 ++++++++++++++++++++++++++++-- > 5 files changed, 78 insertions(+), 2 deletions(-) > Dear All, This commit adds the description of the ext4 proc parameter mb_stats to the corresponding documentation. I noticed that the documentation also lacks descriptions for the es_shrinker_info, fc_info, mb_structs_summary, and options parameters. However, these parameters are irrelevant to the work done in this series of patches. I will commit a separate patch later to explain the other parameters. This time, I only explain mb_stats. Thanks, Baolin ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-04-24 12:08 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-22 1:50 [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats Baolin Liu 2026-04-22 1:50 ` [PATCH v3 v3 1/2] ext4: add blocks_allocated to mb_stats output Baolin Liu 2026-04-24 2:35 ` Baokun Li 2026-04-22 1:50 ` [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats Baolin Liu 2026-04-23 16:19 ` Theodore Tso 2026-04-24 3:12 ` Baokun Li 2026-04-24 8:09 ` liubaolin 2026-04-24 9:34 ` Baokun Li 2026-04-24 12:07 ` Theodore Tso 2026-04-22 9:55 ` [PATCH v3 v3 0/2] add blocks_allocated to mb_stats and clear mb_stats liubaolin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox