From: JonasZhou-oc <jonaszhou-oc@zhaoxin.com>
To: tytso@mit.edu, jack@suse.com
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
jianhuizzzzz@gmail.com, JonasZhou-oc <jonaszhou-oc@zhaoxin.com>
Subject: [PATCH] jbd2: avoid false sharing with j_state_lock
Date: Wed, 2 Sep 2026 15:03:31 +0800 [thread overview]
Message-ID: <20260902070331.820322-1-jonaszhou-oc@zhaoxin.com> (raw)
is_journal_aborted() reads journal->j_flags from ext4 and JBD2 hot
paths. At the same time, transaction start and stop paths repeatedly
acquire and release j_state_lock. read_lock() and read_unlock() update
the lock word, so this traffic invalidates the cache line containing
j_flags.
On the tested x86-64 build, j_flags, j_errno, and j_state_lock occupy
the same 64-byte cache line. j_flags starts at offset 0, j_errno at
offset 8, and j_state_lock at offset 56.
Align j_state_lock to a cacheline boundary on SMP builds. This moves it
to offset 64 and prevents lock traffic from invalidating j_flags and
j_errno. Tests were run on Linux 7.3-rc1.
On a two-socket Intel Xeon Silver 4208 system with SMT disabled, CPUs
fixed at 2 GHz, and 16 stress-ng workers, ten-run average bogo-ops/s for
stress-ng.utime, stress-ng.access, stress-ng.file-ioctl, and
stress-ng.open increased by 9.60%, 5.42%, 2.05%, and 4.65%,
respectively. In separate five-run perf c2c measurements, average
Remote HITM samples for the affected j_flags/j_errno line decreased
from 1996, 2041, 1555, and 383 to zero, respectively.
Signed-off-by: JonasZhou-oc <jonaszhou-oc@zhaoxin.com>
---
include/linux/jbd2.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 1b42fe47c26b..e3886963ba00 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -795,7 +795,7 @@ struct journal_s
/**
* @j_state_lock: Protect the various scalars in the journal.
*/
- rwlock_t j_state_lock;
+ rwlock_t j_state_lock ____cacheline_aligned_in_smp;
/**
* @j_barrier_count:
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
--
2.43.0
next reply other threads:[~2026-09-02 7:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 7:03 JonasZhou-oc [this message]
2026-09-02 7:11 ` [PATCH] jbd2: avoid false sharing with j_state_lock sashiko-bot
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=20260902070331.820322-1-jonaszhou-oc@zhaoxin.com \
--to=jonaszhou-oc@zhaoxin.com \
--cc=jack@suse.com \
--cc=jianhuizzzzz@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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