From: "Xing Ma" <maxing.lan@bytedance.com>
To: <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>,
"Andreas Dilger" <adilger.kernel@dilger.ca>,
"Jan Kara" <jack@suse.cz>,
"Baokun Li" <libaokun@linux.alibaba.com>,
"Ojaswin Mujoo" <ojaswin@linux.ibm.com>,
"Ritesh Harjani" <ritesh.list@gmail.com>,
"Zhang Yi" <yi.zhang@huawei.com>,
"Harshad Shirwadkar" <harshadshirwadkar@gmail.com>,
"Xin Yin" <yinxin.x@bytedance.com>,
"Xing Ma" <maxing.lan@bytedance.com>, <stable@vger.kernel.org>
Subject: [PATCH 1/3] ext4: do not skip fast commit for updates queued during ongoing commit
Date: Tue, 1 Dec 2026 00:38:17 +0800 [thread overview]
Message-ID: <20261130163819.13819-2-maxing.lan@bytedance.com> (raw)
In-Reply-To: <20261130163819.13819-1-maxing.lan@bytedance.com>
When ext4_fc_commit() waits on an already-ongoing fast commit (T1) and
jbd2_fc_begin_commit() returns -EALREADY, it currently skips restarting
whenever sbi->s_fc_subtid has incremented past the value read at entry.
However, once T1 sets JBD2_FAST_COMMIT_ONGOING, any concurrent update
made by another thread (T2) is placed on FC_Q_STAGING or marked
EXT4_STATE_FC_REQUEUE and will NOT be written by T1. When T2 then
calls fsync() while T1 is still running:
1. T2 reads s_fc_subtid == N and waits in jbd2_fc_begin_commit().
2. T1 finishes committing its own earlier snapshot, increments
s_fc_subtid to N + 1, moves T2's updates from FC_Q_STAGING to
FC_Q_MAIN in ext4_fc_cleanup(), and wakes T2.
3. T2 sees s_fc_subtid (N + 1) > subtid (N), skips committing
(EXT4_FC_STATUS_SKIPPED), and returns 0 from fsync().
T2's fsync() thus returns success even though its updates are still
uncommitted in memory, causing silent data loss or stale file size
after a crash. This is readily reproduced by concurrent fsx writers
in xfstests generic/455 with -O fast_commit.
Sample s_fc_subtid and JBD2_FAST_COMMIT_ONGOING under j_state_lock at
entry to ext4_fc_commit(). If a fast commit is already ongoing,
require target_subtid = s_fc_subtid + 2 (a subsequent fast commit
started after the ongoing one finishes) or a full commit of commit_tid
before skipping.
Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
Cc: stable@vger.kernel.org
Signed-off-by: Xing Ma <maxing.lan@bytedance.com>
---
fs/ext4/fast_commit.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 9beb423b208f8..03ab9b8a2d983 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1588,7 +1588,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
struct super_block *sb = journal->j_private;
struct ext4_sb_info *sbi = EXT4_SB(sb);
int nblks = 0, ret, bsize = journal->j_blocksize;
- int subtid = atomic_read(&sbi->s_fc_subtid);
+ int target_subtid;
int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0;
ktime_t start_time, commit_time;
int old_ioprio, journal_ioprio;
@@ -1601,11 +1601,24 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
start_time = ktime_get();
old_ioprio = get_current_ioprio();
+ /*
+ * If a fast commit is already ongoing when we enter ext4_fc_commit(),
+ * updates made by this caller may have been queued on FC_Q_STAGING or
+ * marked EXT4_STATE_FC_REQUEUE and will not be included in that
+ * ongoing fast commit. Require a subsequent fast commit (or a full
+ * commit of commit_tid) before skipping.
+ */
+ read_lock(&journal->j_state_lock);
+ target_subtid = atomic_read(&sbi->s_fc_subtid) + 1;
+ if (journal->j_flags & JBD2_FAST_COMMIT_ONGOING)
+ target_subtid++;
+ read_unlock(&journal->j_state_lock);
+
restart_fc:
ret = jbd2_fc_begin_commit(journal, commit_tid);
if (ret == -EALREADY) {
/* There was an ongoing commit, check if we need to restart */
- if (atomic_read(&sbi->s_fc_subtid) <= subtid &&
+ if ((int)(atomic_read(&sbi->s_fc_subtid) - target_subtid) < 0 &&
tid_gt(commit_tid, journal->j_commit_sequence))
goto restart_fc;
ext4_fc_update_stats(sb, EXT4_FC_STATUS_SKIPPED, 0, 0,
--
2.39.5
next prev parent reply other threads:[~2026-11-30 16:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:38 [PATCH 0/3] ext4: fix concurrent fast commit durability and tracking races Xing Ma
2026-11-30 16:38 ` Xing Ma [this message]
2026-11-30 16:57 ` [PATCH 1/3] ext4: do not skip fast commit for updates queued during ongoing commit sashiko-bot
2026-11-30 16:38 ` [PATCH 2/3] ext4: splice stranded fast commit staging queues before starting commit Xing Ma
2026-11-30 16:54 ` sashiko-bot
2026-11-30 16:38 ` [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible Xing Ma
2026-11-30 16:58 ` 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=20261130163819.13819-2-maxing.lan@bytedance.com \
--to=maxing.lan@bytedance.com \
--cc=adilger.kernel@dilger.ca \
--cc=harshadshirwadkar@gmail.com \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
--cc=yinxin.x@bytedance.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