* [PATCH v6 v6 1/3] ext4: add blocks_allocated to mb_stats output
2026-05-24 1:54 [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control Baolin Liu
@ 2026-05-24 1:54 ` Baolin Liu
2026-05-24 1:54 ` [PATCH v6 v6 2/3] ext4: use READ_ONCE/WRITE_ONCE for s_mb_stats Baolin Liu
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Baolin Liu @ 2026-05-24 1:54 UTC (permalink / raw)
To: corbet, skhan, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang
Cc: linux-ext4, linux-kernel, 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 bb58eafb87bc..d36b0f7b5d7d 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3217,6 +3217,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] 7+ messages in thread* [PATCH v6 v6 2/3] ext4: use READ_ONCE/WRITE_ONCE for s_mb_stats
2026-05-24 1:54 [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control Baolin Liu
2026-05-24 1:54 ` [PATCH v6 v6 1/3] ext4: add blocks_allocated to mb_stats output Baolin Liu
@ 2026-05-24 1:54 ` Baolin Liu
2026-05-24 1:54 ` [PATCH v6 v6 3/3] ext4: allow controlling mballoc stats through proc mb_stats Baolin Liu
[not found] ` <1816234d.8a1b.19ef8ff3f2e.Coremail.liubaolin12138@163.com>
3 siblings, 0 replies; 7+ messages in thread
From: Baolin Liu @ 2026-05-24 1:54 UTC (permalink / raw)
To: corbet, skhan, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang
Cc: linux-ext4, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Use READ_ONCE()/WRITE_ONCE() for concurrent accesses to
s_mb_stats.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ext4/mballoc.c | 24 ++++++++++++------------
fs/ext4/sysfs.c | 25 ++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index d36b0f7b5d7d..fed6d854877b 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -924,7 +924,7 @@ static int ext4_mb_scan_groups_xa_range(struct ext4_allocation_context *ac,
xa_for_each_range(xa, group, grp, start, end - 1) {
int err;
- if (sbi->s_mb_stats)
+ if (READ_ONCE(sbi->s_mb_stats))
atomic64_inc(&sbi->s_bal_cX_groups_considered[cr]);
err = ext4_mb_scan_group(ac, grp->bb_group);
@@ -980,7 +980,7 @@ static int ext4_mb_scan_groups_p2_aligned(struct ext4_allocation_context *ac,
goto wrap_around;
}
- if (sbi->s_mb_stats)
+ if (READ_ONCE(sbi->s_mb_stats))
atomic64_inc(&sbi->s_bal_cX_failed[ac->ac_criteria]);
/* Increment cr and search again if no group is found */
@@ -1031,7 +1031,7 @@ static int ext4_mb_scan_groups_goal_fast(struct ext4_allocation_context *ac,
goto wrap_around;
}
- if (sbi->s_mb_stats)
+ if (READ_ONCE(sbi->s_mb_stats))
atomic64_inc(&sbi->s_bal_cX_failed[ac->ac_criteria]);
/*
* CR_BEST_AVAIL_LEN works based on the concept that we have
@@ -1135,7 +1135,7 @@ static int ext4_mb_scan_groups_best_avail(struct ext4_allocation_context *ac,
/* Reset goal length to original goal length before falling into CR_GOAL_LEN_SLOW */
ac->ac_g_ex.fe_len = ac->ac_orig_goal_len;
- if (sbi->s_mb_stats)
+ if (READ_ONCE(sbi->s_mb_stats))
atomic64_inc(&sbi->s_bal_cX_failed[ac->ac_criteria]);
ac->ac_criteria = CR_GOAL_LEN_SLOW;
@@ -1184,7 +1184,7 @@ static int ext4_mb_scan_groups_linear(struct ext4_allocation_context *ac,
ac->ac_criteria++;
/* Processed all groups and haven't found blocks */
- if (sbi->s_mb_stats && i == ngroups)
+ if (READ_ONCE(sbi->s_mb_stats) && i == ngroups)
atomic64_inc(&sbi->s_bal_cX_failed[cr]);
return 0;
@@ -2541,7 +2541,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
BUG_ON(ac->ac_f_ex.fe_len != ac->ac_g_ex.fe_len);
- if (EXT4_SB(sb)->s_mb_stats)
+ if (READ_ONCE(EXT4_SB(sb)->s_mb_stats))
atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
break;
@@ -2786,7 +2786,7 @@ static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
if (!grp)
return -EFSCORRUPTED;
- if (sbi->s_mb_stats)
+ if (READ_ONCE(sbi->s_mb_stats))
atomic64_inc(&sbi->s_bal_cX_groups_considered[ac->ac_criteria]);
if (should_lock) {
ext4_lock_group(sb, group);
@@ -3097,7 +3097,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
}
}
- if (sbi->s_mb_stats && ac->ac_status == AC_STATUS_FOUND) {
+ if (READ_ONCE(sbi->s_mb_stats) && ac->ac_status == AC_STATUS_FOUND) {
atomic64_inc(&sbi->s_bal_cX_hits[ac->ac_criteria]);
if (ac->ac_flags & EXT4_MB_STREAM_ALLOC &&
ac->ac_b_ex.fe_group == ac->ac_g_ex.fe_group)
@@ -3210,7 +3210,7 @@ int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
struct ext4_sb_info *sbi = EXT4_SB(sb);
seq_puts(seq, "mballoc:\n");
- if (!sbi->s_mb_stats) {
+ if (!READ_ONCE(sbi->s_mb_stats)) {
seq_puts(seq, "\tmb stats collection turned off.\n");
seq_puts(
seq,
@@ -3787,7 +3787,7 @@ int ext4_mb_init(struct super_block *sb)
sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
- sbi->s_mb_stats = MB_DEFAULT_STATS;
+ WRITE_ONCE(sbi->s_mb_stats, MB_DEFAULT_STATS);
sbi->s_mb_stream_request = MB_DEFAULT_STREAM_THRESHOLD;
sbi->s_mb_order2_reqs = MB_DEFAULT_ORDER2_REQS;
sbi->s_mb_best_avail_max_trim_order = MB_DEFAULT_BEST_AVAIL_TRIM_ORDER;
@@ -3929,7 +3929,7 @@ void ext4_mb_release(struct super_block *sb)
kfree(sbi->s_mb_offsets);
kfree(sbi->s_mb_maxs);
iput(sbi->s_buddy_cache);
- if (sbi->s_mb_stats) {
+ if (READ_ONCE(sbi->s_mb_stats)) {
ext4_msg(sb, KERN_INFO,
"mballoc: %u blocks %u reqs (%u success)",
atomic_read(&sbi->s_bal_allocated),
@@ -4694,7 +4694,7 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
{
struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
- if (sbi->s_mb_stats && ac->ac_g_ex.fe_len >= 1) {
+ if (READ_ONCE(sbi->s_mb_stats) && ac->ac_g_ex.fe_len >= 1) {
atomic_inc(&sbi->s_bal_reqs);
atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index afe12bcc1603..47e06c32c6fb 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -41,6 +41,7 @@ typedef enum {
attr_pointer_atomic,
attr_journal_task,
attr_err_report_sec,
+ attr_mb_stats,
} attr_id_t;
typedef enum {
@@ -241,6 +242,7 @@ EXT4_ATTR_FUNC(session_write_kbytes, 0444);
EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444);
EXT4_ATTR_FUNC(reserved_clusters, 0644);
EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444);
+EXT4_ATTR_FUNC(mb_stats, 0644);
EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead,
ext4_sb_info, s_inode_readahead_blks);
@@ -250,7 +252,6 @@ EXT4_ATTR_OFFSET(mb_best_avail_max_trim_order, 0644, mb_order,
ext4_sb_info, s_mb_best_avail_max_trim_order);
EXT4_ATTR_OFFSET(err_report_sec, 0644, err_report_sec, ext4_sb_info, s_err_report_sec);
EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
-EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
@@ -451,6 +452,24 @@ static ssize_t ext4_generic_attr_show(struct ext4_attr *a,
return 0;
}
+static ssize_t mb_stats_show(struct ext4_sb_info *sbi, char *buf)
+{
+ return sysfs_emit(buf, "%u\n", READ_ONCE(sbi->s_mb_stats));
+}
+
+static ssize_t mb_stats_store(struct ext4_sb_info *sbi,
+ const char *buf, size_t len)
+{
+ unsigned int t;
+ int ret;
+
+ ret = kstrtouint(skip_spaces(buf), 0, &t);
+ if (ret)
+ return ret;
+ WRITE_ONCE(sbi->s_mb_stats, t);
+ return len;
+}
+
static ssize_t ext4_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
@@ -475,6 +494,8 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
return sysfs_emit(buf, "%llu\n",
(unsigned long long)
percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit));
+ case attr_mb_stats:
+ return mb_stats_show(sbi, buf);
case attr_feature:
return sysfs_emit(buf, "supported\n");
case attr_first_error_time:
@@ -559,6 +580,8 @@ static ssize_t ext4_attr_store(struct kobject *kobj,
return inode_readahead_blks_store(sbi, buf, len);
case attr_trigger_test_error:
return trigger_test_error(sbi, buf, len);
+ case attr_mb_stats:
+ return mb_stats_store(sbi, buf, len);
case attr_err_report_sec:
return err_report_sec_store(sbi, buf, len);
default:
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v6 v6 3/3] ext4: allow controlling mballoc stats through proc mb_stats
2026-05-24 1:54 [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control Baolin Liu
2026-05-24 1:54 ` [PATCH v6 v6 1/3] ext4: add blocks_allocated to mb_stats output Baolin Liu
2026-05-24 1:54 ` [PATCH v6 v6 2/3] ext4: use READ_ONCE/WRITE_ONCE for s_mb_stats Baolin Liu
@ 2026-05-24 1:54 ` Baolin Liu
[not found] ` <1816234d.8a1b.19ef8ff3f2e.Coremail.liubaolin12138@163.com>
3 siblings, 0 replies; 7+ messages in thread
From: Baolin Liu @ 2026-05-24 1:54 UTC (permalink / raw)
To: corbet, skhan, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang
Cc: linux-ext4, linux-kernel, Baolin Liu, Andreas Dilger
From: Baolin Liu <liubaolin@kylinos.cn>
Make /proc/fs/ext4/<dev>/mb_stats writable. Writing 0 disables mballoc
statistics collection, writing 1 enables it, and writing -1 clears the
current statistics before enabling collection.
Update the documentation and deprecate the sysfs mb_stats entry.
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>
Reviewed-by: Baokun Li <libaokun@linux.alibaba.com>
Reviewed-by: Ted Tso <tytso@mit.edu>
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
Documentation/ABI/testing/sysfs-fs-ext4 | 3 +-
Documentation/admin-guide/ext4.rst | 9 +++-
Documentation/filesystems/proc.rst | 13 +-----
fs/ext4/ext4.h | 2 +
fs/ext4/mballoc.c | 32 +++++++++++++-
fs/ext4/sysfs.c | 55 ++++++++++++++++++++++++-
6 files changed, 97 insertions(+), 17 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-fs-ext4 b/Documentation/ABI/testing/sysfs-fs-ext4
index 2edd0a6672d3..7bf06c533343 100644
--- a/Documentation/ABI/testing/sysfs-fs-ext4
+++ b/Documentation/ABI/testing/sysfs-fs-ext4
@@ -5,7 +5,8 @@ Description:
Controls whether the multiblock allocator should
collect statistics, which are shown during the unmount.
1 means to collect statistics, 0 means not to collect
- statistics
+ statistics. This sysfs entry is deprecated, and users
+ should prefer /proc/fs/ext4/<disk>/mb_stats.
What: /sys/fs/ext4/<disk>/mb_group_prealloc
Date: March 2008
diff --git a/Documentation/admin-guide/ext4.rst b/Documentation/admin-guide/ext4.rst
index ac0c709ea9e7..ca76e981b2aa 100644
--- a/Documentation/admin-guide/ext4.rst
+++ b/Documentation/admin-guide/ext4.rst
@@ -436,6 +436,12 @@ 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 disables statistics collection, writing
+ 1 enables statistics collection, and writing -1 clears the
+ current statistics and enables statistics collection.
+
/sys entries
============
@@ -493,7 +499,8 @@ Files in /sys/fs/ext4/<devname>:
mb_stats
Controls whether the multiblock allocator should collect statistics,
which are shown during the unmount. 1 means to collect statistics, 0
- means not to collect statistics.
+ means not to collect statistics. This sysfs entry is deprecated, and
+ users should prefer /proc/fs/ext4/<devname>/mb_stats.
mb_stream_req
Files which have fewer blocks than this tunable parameter will have
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index b0c0d1b45b99..dd487004b862 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -1623,18 +1623,7 @@ softirq.
1.8 Ext4 file system parameters
-------------------------------
-Information about mounted ext4 file systems can be found in
-/proc/fs/ext4. Each mounted filesystem will have a directory in
-/proc/fs/ext4 based on its device name (i.e., /proc/fs/ext4/hdc or
-/proc/fs/ext4/sda9 or /proc/fs/ext4/dm-0). The files in each per-device
-directory are shown in Table 1-12, below.
-
-.. table:: Table 1-12: Files in /proc/fs/ext4/<devname>
-
- ============== ==========================================================
- File Content
- mb_groups details of multiblock allocator buddy cache of free blocks
- ============== ==========================================================
+See Documentation/admin-guide/ext4.rst for ext4-specific /proc entries.
1.9 /proc/consoles
-------------------
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index df96bcd53a59..ab69ef8e5634 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1625,6 +1625,7 @@ struct ext4_sb_info {
unsigned int s_mb_stream_request;
unsigned int s_mb_max_to_scan;
unsigned int s_mb_min_to_scan;
+ struct mutex s_mb_stats_mutex;
unsigned int s_mb_stats;
unsigned int s_mb_order2_reqs;
unsigned int s_mb_group_prealloc;
@@ -2995,6 +2996,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 fed6d854877b..ee8f62861941 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3214,7 +3214,7 @@ int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
seq_puts(seq, "\tmb stats collection turned off.\n");
seq_puts(
seq,
- "\tTo enable, please write \"1\" to sysfs file mb_stats.\n");
+ "\tTo enable, please write \"1\" to proc file mb_stats.\n");
return 0;
}
seq_printf(seq, "\tblocks_allocated: %u\n",
@@ -3787,6 +3787,7 @@ int ext4_mb_init(struct super_block *sb)
sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
+ mutex_init(&sbi->s_mb_stats_mutex);
WRITE_ONCE(sbi->s_mb_stats, MB_DEFAULT_STATS);
sbi->s_mb_stream_request = MB_DEFAULT_STREAM_THRESHOLD;
sbi->s_mb_order2_reqs = MB_DEFAULT_ORDER2_REQS;
@@ -4723,6 +4724,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 47e06c32c6fb..20935493dda8 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -53,6 +53,54 @@ 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));
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ int val;
+ int ret;
+
+ ret = kstrtoint_from_user(buf, count, 0, &val);
+ if (ret)
+ return ret;
+
+ ret = count;
+ mutex_lock(&sbi->s_mb_stats_mutex);
+ switch (val) {
+ case -1:
+ WRITE_ONCE(sbi->s_mb_stats, 0);
+ ext4_mb_stats_clear(sbi);
+ WRITE_ONCE(sbi->s_mb_stats, 1);
+ break;
+ case 1:
+ WRITE_ONCE(sbi->s_mb_stats, 1);
+ break;
+ case 0:
+ WRITE_ONCE(sbi->s_mb_stats, 0);
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ mutex_unlock(&sbi->s_mb_stats_mutex);
+
+ return ret;
+}
+
+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;
@@ -466,7 +514,10 @@ static ssize_t mb_stats_store(struct ext4_sb_info *sbi,
ret = kstrtouint(skip_spaces(buf), 0, &t);
if (ret)
return ret;
+
+ mutex_lock(&sbi->s_mb_stats_mutex);
WRITE_ONCE(sbi->s_mb_stats, t);
+ mutex_unlock(&sbi->s_mb_stats_mutex);
return len;
}
@@ -666,8 +717,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 [flat|nested] 7+ messages in thread[parent not found: <1816234d.8a1b.19ef8ff3f2e.Coremail.liubaolin12138@163.com>]
* Re: [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control
[not found] ` <1816234d.8a1b.19ef8ff3f2e.Coremail.liubaolin12138@163.com>
@ 2026-06-24 9:52 ` liubaolin
2026-06-24 9:59 ` liubaolin
1 sibling, 0 replies; 7+ messages in thread
From: liubaolin @ 2026-06-24 9:52 UTC (permalink / raw)
To: corbet, skhan, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang
Cc: linux-ext4, linux-kernel, Baolin Liu
Dear Maintainer,
I was wondering if there are still any concerns or questions
regarding this patch series.
The patches have been updated based on the previous review comments
and have also passed the Sashiko AI review.
I would appreciate any further feedback and look forward to your reply.
Best regards,
Baolin
在 2026/6/24 17:38, Baolin Liu 写道:
>
>
>
>
>
>
>
> At 2026-05-24 09:54:18, "Baolin Liu" <liubaolin12138@163.com> wrote:
>>From: Baolin Liu <liubaolin@kylinos.cn>
>>
>>This series improves mballoc statistics reporting and control by adding
>>blocks_allocated to /proc/fs/ext4/<dev>/mb_stats, using
>>READ_ONCE()/WRITE_ONCE() for concurrent accesses to s_mb_stats, and
>>allowing mballoc stats to be controlled through
>>/proc/fs/ext4/<dev>/mb_stats.
>>
>>Changes in v6:
>> - Serialize proc and sysfs updates to s_mb_stats with a mutex so that
>> clearing mb_stats through the proc control path cannot race with
>> concurrent administrative writes.
>>
>>Baolin Liu (3):
>> ext4: add blocks_allocated to mb_stats output
>> ext4: use READ_ONCE/WRITE_ONCE for s_mb_stats
>> ext4: allow controlling mballoc stats through proc mb_stats
>>
>> Documentation/ABI/testing/sysfs-fs-ext4 | 3 +-
>> Documentation/admin-guide/ext4.rst | 9 ++-
>> Documentation/filesystems/proc.rst | 13 +---
>> fs/ext4/ext4.h | 2 +
>> fs/ext4/mballoc.c | 58 ++++++++++++++----
>> fs/ext4/sysfs.c | 80 ++++++++++++++++++++++++-
>> 6 files changed, 135 insertions(+), 30 deletions(-)
>>
>>--
>>2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control
[not found] ` <1816234d.8a1b.19ef8ff3f2e.Coremail.liubaolin12138@163.com>
2026-06-24 9:52 ` [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control liubaolin
@ 2026-06-24 9:59 ` liubaolin
2026-06-24 10:02 ` liubaolin
1 sibling, 1 reply; 7+ messages in thread
From: liubaolin @ 2026-06-24 9:59 UTC (permalink / raw)
To: corbet, skhan, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang, liubaolin12138
Cc: linux-ext4, linux-kernel, Baolin Liu, liubaolin12138
Add recipient: liubaolin12138@163.com
在 2026/6/24 17:38, Baolin Liu 写道:
>
>
>
>
>
>
>
> At 2026-05-24 09:54:18, "Baolin Liu" <liubaolin12138@163.com> wrote:
>>From: Baolin Liu <liubaolin@kylinos.cn>
>>
>>This series improves mballoc statistics reporting and control by adding
>>blocks_allocated to /proc/fs/ext4/<dev>/mb_stats, using
>>READ_ONCE()/WRITE_ONCE() for concurrent accesses to s_mb_stats, and
>>allowing mballoc stats to be controlled through
>>/proc/fs/ext4/<dev>/mb_stats.
>>
>>Changes in v6:
>> - Serialize proc and sysfs updates to s_mb_stats with a mutex so that
>> clearing mb_stats through the proc control path cannot race with
>> concurrent administrative writes.
>>
>>Baolin Liu (3):
>> ext4: add blocks_allocated to mb_stats output
>> ext4: use READ_ONCE/WRITE_ONCE for s_mb_stats
>> ext4: allow controlling mballoc stats through proc mb_stats
>>
>> Documentation/ABI/testing/sysfs-fs-ext4 | 3 +-
>> Documentation/admin-guide/ext4.rst | 9 ++-
>> Documentation/filesystems/proc.rst | 13 +---
>> fs/ext4/ext4.h | 2 +
>> fs/ext4/mballoc.c | 58 ++++++++++++++----
>> fs/ext4/sysfs.c | 80 ++++++++++++++++++++++++-
>> 6 files changed, 135 insertions(+), 30 deletions(-)
>>
>>--
>>2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v6 v6 0/3] ext4: improve mballoc statistics reporting and control
2026-06-24 9:59 ` liubaolin
@ 2026-06-24 10:02 ` liubaolin
0 siblings, 0 replies; 7+ messages in thread
From: liubaolin @ 2026-06-24 10:02 UTC (permalink / raw)
To: corbet, skhan, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang, liubaolin12138
Cc: linux-ext4, linux-kernel, Baolin Liu, liubaolin12138
Dear Maintainer,
I was wondering if there are still any concerns or questions
regarding this patch series.
The patches have been updated based on the previous review comments
and have also passed the Sashiko AI review.
I would appreciate any further feedback and look forward to your reply.
Best regards,
Baolin
在 2026/6/24 17:59, liubaolin 写道:
> Add recipient: liubaolin12138@163.com
>
> 在 2026/6/24 17:38, Baolin Liu 写道:
>>
>>
>>
>>
>>
>>
>>
>> At 2026-05-24 09:54:18, "Baolin Liu" <liubaolin12138@163.com> wrote:
>>> From: Baolin Liu <liubaolin@kylinos.cn>
>>>
>>> This series improves mballoc statistics reporting and control by adding
>>> blocks_allocated to /proc/fs/ext4/<dev>/mb_stats, using
>>> READ_ONCE()/WRITE_ONCE() for concurrent accesses to s_mb_stats, and
>>> allowing mballoc stats to be controlled through
>>> /proc/fs/ext4/<dev>/mb_stats.
>>>
>>> Changes in v6:
>>> - Serialize proc and sysfs updates to s_mb_stats with a mutex so that
>>> clearing mb_stats through the proc control path cannot race with
>>> concurrent administrative writes.
>>>
>>> Baolin Liu (3):
>>> ext4: add blocks_allocated to mb_stats output
>>> ext4: use READ_ONCE/WRITE_ONCE for s_mb_stats
>>> ext4: allow controlling mballoc stats through proc mb_stats
>>>
>>> Documentation/ABI/testing/sysfs-fs-ext4 | 3 +-
>>> Documentation/admin-guide/ext4.rst | 9 ++-
>>> Documentation/filesystems/proc.rst | 13 +---
>>> fs/ext4/ext4.h | 2 +
>>> fs/ext4/mballoc.c | 58 ++++++++++++++----
>>> fs/ext4/sysfs.c | 80 ++++++++++++++++++++++++-
>>> 6 files changed, 135 insertions(+), 30 deletions(-)
>>>
>>> --
>>> 2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread