Re: [PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats
From: liubaolin
Date: Sun Apr 26 2026 - 21:34:22 EST
Dear Ted,
Thank you and Baokun for your review and suggestions.
I will incorporate your suggestions and submit the v4 patch as soon as possible.
Thanks,
Baolin
在 2026/4/24 20:07, Theodore Tso 写道:
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