From: Jaidev Shastri via B4 Relay <devnull+jaidevshastri.vt.edu@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Jaidev Shastri <jaidevshastri@vt.edu>
Subject: [PATCH] fs/buffer: publish max_buffer_heads with release semantics
Date: Mon, 21 Sep 2026 21:15:46 -0400 [thread overview]
Message-ID: <20260921-mb-fs-buffer-v1-1-e9ce65e8df43@vt.edu> (raw)
From: Jaidev Shastri <jaidevshastri@vt.edu>
buffer_init() creates bh_cachep and then computes max_buffer_heads, both
with plain stores. recalc_bh_state() reads max_buffer_heads with a plain
load from alloc_buffer_head() and free_buffer_head(), on any CPU.
Store it with smp_store_release() and read it with smp_load_acquire().
Found with MBCheck, a static herd7-based memory consistency checker.
Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>
---
fs/buffer.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index ed966fa73..bf5a674c1 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2864,7 +2864,8 @@ static void recalc_bh_state(void)
__this_cpu_write(bh_accounting.ratelimit, 0);
for_each_online_cpu(i)
tot += per_cpu(bh_accounting, i).nr;
- buffer_heads_over_limit = (tot > max_buffer_heads);
+ /* Pairs with the smp_store_release() in buffer_init(). */
+ buffer_heads_over_limit = (tot > smp_load_acquire(&max_buffer_heads));
}
struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
@@ -2998,7 +2999,9 @@ void __init buffer_init(void)
* Limit the bh occupancy to 10% of ZONE_NORMAL
*/
nrpages = (nr_free_buffer_pages() * 10) / 100;
- max_buffer_heads = nrpages * (PAGE_SIZE / sizeof(struct buffer_head));
+ /* Pairs with the smp_load_acquire() in recalc_bh_state(). */
+ smp_store_release(&max_buffer_heads,
+ nrpages * (PAGE_SIZE / sizeof(struct buffer_head)));
ret = cpuhp_setup_state_nocalls(CPUHP_FS_BUFF_DEAD, "fs/buffer:dead",
NULL, buffer_exit_cpu_dead);
WARN_ON(ret < 0);
---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260921-mb-fs-buffer-0a91680176e5
Best regards,
--
Jaidev Shastri <jaidevshastri@vt.edu>
next reply other threads:[~2026-09-22 1:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 1:15 Jaidev Shastri via B4 Relay [this message]
2026-09-22 12:04 ` [PATCH] fs/buffer: publish max_buffer_heads with release semantics Jan Kara
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=20260921-mb-fs-buffer-v1-1-e9ce65e8df43@vt.edu \
--to=devnull+jaidevshastri.vt.edu@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jaidevshastri@vt.edu \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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