From: liubaolin <liubaolin12138@163.com>
To: sashiko@lists.linux.dev, libaokun@linux.alibaba.com,
adilger.kernel@dilger.ca, tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
adilger@dilger.ca, wangguanyu@vivo.com
Subject: Re: [PATCH v4 v4 2/3] ext4: use atomic operations for s_mb_stats accesses
Date: Tue, 12 May 2026 10:11:02 +0800 [thread overview]
Message-ID: <f64bdace-15c0-43e6-98eb-12628cdfbf33@163.com> (raw)
In-Reply-To: <20260508200245.A703BC2BCC7@smtp.kernel.org>
Dear All,
Sashiko AI reviewed the patch and provided two points. I will take
these into consideration and submit a revised version for v5 as soon as
possible.
Thanks,
Baolin
在 2026/5/9 04:02, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] Architectural Anti-pattern: Using `atomic_t` for a simple configuration flag
> --
>
> commit 4ef770887d49b5db285ae4848dba912e51abd333
> Author: Baolin Liu <liubaolin@kylinos.cn>
> ext4: use atomic operations for s_mb_stats accesses
>
> This commit converts the s_mb_stats configuration flag in ext4 from an
> unsigned int to an atomic_t to fix data races between sysfs updates and
> mballoc reads.
>
>> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
>> index 94283a991e5c4..4fb19fcb1f5f3 100644
>> --- a/fs/ext4/ext4.h
>> +++ b/fs/ext4/ext4.h
> [ ... ]
>> @@ -1622,7 +1622,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;
>> - unsigned int s_mb_stats;
>> + atomic_t s_mb_stats;
>
> Since s_mb_stats is only loaded and stored concurrently without any
> read-modify-write operations (like atomic_inc), would it be better to retain
> the unsigned int type and use READ_ONCE() and WRITE_ONCE() instead? Using
> atomic_t for simple configuration flags can add unnecessary conceptual
> overhead.
>
>> diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
>> index 923b375e017fa..fad2819f36319 100644
>> --- a/fs/ext4/sysfs.c
>> +++ b/fs/ext4/sysfs.c
> [ ... ]
>> @@ -540,6 +541,12 @@ static ssize_t ext4_generic_attr_store(struct ext4_attr *a,
>> return ret;
>> *((unsigned long *) ptr) = lt;
>> return len;
>> + case attr_pointer_atomic:
>> + ret = kstrtoint(skip_spaces(buf), 0, &i);
>> + if (ret)
>> + return ret;
>> + atomic_set((atomic_t *)ptr, i);
>> + return len;
>> }
>> return 0;
>
> Does migrating from attr_pointer_ui (which uses kstrtouint) to
> attr_pointer_atomic unintentionally allow logically invalid negative
> values to be written to s_mb_stats, since kstrtoint accepts negative numbers?
>
next prev parent reply other threads:[~2026-05-12 2:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 9:34 [PATCH v4 v4 0/3] ext4: improve mballoc statistics reporting and control Baolin Liu
2026-05-08 9:34 ` [PATCH v4 v4 1/3] ext4: add blocks_allocated to mb_stats output Baolin Liu
2026-05-08 9:34 ` [PATCH v4 v4 2/3] ext4: use atomic operations for s_mb_stats accesses Baolin Liu
[not found] ` <20260508200245.A703BC2BCC7@smtp.kernel.org>
2026-05-12 2:11 ` liubaolin [this message]
2026-05-08 9:34 ` [PATCH v4 v4 3/3] ext4: allow controlling mballoc stats through proc mb_stats Baolin Liu
2026-05-08 10:31 ` [PATCH v4 v4 0/3] ext4: improve mballoc statistics reporting and control liubaolin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f64bdace-15c0-43e6-98eb-12628cdfbf33@163.com \
--to=liubaolin12138@163.com \
--cc=adilger.kernel@dilger.ca \
--cc=adilger@dilger.ca \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=tytso@mit.edu \
--cc=wangguanyu@vivo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox