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 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible
Date: Tue, 1 Dec 2026 00:38:19 +0800 [thread overview]
Message-ID: <20261130163819.13819-4-maxing.lan@bytedance.com> (raw)
In-Reply-To: <20261130163819.13819-1-maxing.lan@bytedance.com>
While an ineligible transaction T (with s_fc_ineligible_tid == T) is
performing a full JBD2 commit, EXT4_MF_FC_INELIGIBLE remains set until
ext4_fc_cleanup(journal, full=1, T) runs at the end of that commit.
Meanwhile, JBD2 already allows new handles to run in transaction T + 1.
Because ext4_fc_track_{inode,range,create,link,unlink}() check only
EXT4_MF_FC_INELIGIBLE without comparing handle->h_transaction->t_tid
against s_fc_ineligible_tid, updates in T + 1 silently skip fast commit
tracking. Once T's full commit finishes and clears
EXT4_MF_FC_INELIGIBLE, a subsequent fsync() in T + 1 proceeds with a
fast commit that omits some or all of T + 1's updates:
- If both range and inode tracking were skipped, fsync() writes an
empty fast commit and silently loses operations such as truncate.
- If range tracking was skipped before cleanup cleared the flag and
inode tracking ran afterward, fast commit replays the shrunk inode
without DEL_RANGE, leaving stale extents beyond EOF ("end of extent
exceeds allowed value" in e2fsck).
In addition, ext4_fc_cleanup() cleared EXT4_MF_FC_INELIGIBLE even when
full == 0, which allows jbd2_fc_end_commit_fallback() to clear the flag
before the fallback full commit has even started.
Introduce ext4_fc_handle_eligible() so tracking continues for any
handle whose transaction TID is newer than s_fc_ineligible_tid, and
only clear EXT4_MF_FC_INELIGIBLE in ext4_fc_cleanup() when full is set.
Fixes: e85c81ba8859 ("ext4: fast commit may not fallback for ineligible commit")
Cc: stable@vger.kernel.org
Signed-off-by: Xing Ma <maxing.lan@bytedance.com>
---
fs/ext4/fast_commit.c | 45 +++++++++++++++++++++++++++++++++++--------
1 file changed, 37 insertions(+), 8 deletions(-)
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index e03a829e2a10a..27e54ffa4ae5e 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -235,6 +235,31 @@ static bool ext4_fc_eligible(struct super_block *sb)
!(ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE));
}
+static bool ext4_fc_handle_eligible(struct super_block *sb, handle_t *handle)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ if (ext4_fc_disabled(sb))
+ return false;
+ if (!ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE))
+ return true;
+ if (!handle || !handle->h_transaction)
+ return false;
+ /*
+ * EXT4_MF_FC_INELIGIBLE may still be set for an older committing
+ * transaction while new handles are already modifying the next running
+ * transaction. Continue tracking handles whose TID is newer than
+ * s_fc_ineligible_tid so the next transaction is completely tracked
+ * once the older full commit clears EXT4_MF_FC_INELIGIBLE.
+ *
+ * Pairs with smp_wmb() in ext4_fc_mark_ineligible() and
+ * ext4_fc_cleanup().
+ */
+ smp_rmb();
+ return tid_gt(handle->h_transaction->t_tid,
+ READ_ONCE(sbi->s_fc_ineligible_tid));
+}
+
/*
* Wait for an inode fast-commit state bit to clear while dropping the
* fast-commit lock around schedule().
@@ -371,7 +396,9 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
alloc_ctx = ext4_fc_lock(sb);
is_ineligible = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
if (has_transaction && (!is_ineligible || tid_gt(tid, sbi->s_fc_ineligible_tid)))
- sbi->s_fc_ineligible_tid = tid;
+ WRITE_ONCE(sbi->s_fc_ineligible_tid, tid);
+ /* Pairs with smp_rmb() in ext4_fc_handle_eligible(). */
+ smp_wmb();
ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
ext4_fc_unlock(sb, alloc_ctx);
WARN_ON(reason >= EXT4_FC_REASON_MAX);
@@ -513,7 +540,7 @@ void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry)
{
struct inode *inode = d_inode(dentry);
- if (ext4_fc_eligible(inode->i_sb))
+ if (ext4_fc_handle_eligible(inode->i_sb, handle))
__ext4_fc_track_unlink(handle, inode, dentry);
}
@@ -534,7 +561,7 @@ void __ext4_fc_track_link(handle_t *handle,
void ext4_fc_track_link(handle_t *handle, struct inode *inode,
struct dentry *dentry)
{
- if (ext4_fc_eligible(inode->i_sb))
+ if (ext4_fc_handle_eligible(inode->i_sb, handle))
__ext4_fc_track_link(handle, inode, dentry);
}
@@ -556,7 +583,7 @@ void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
{
struct inode *inode = d_inode(dentry);
- if (ext4_fc_eligible(inode->i_sb))
+ if (ext4_fc_handle_eligible(inode->i_sb, handle))
__ext4_fc_track_create(handle, inode, dentry);
}
@@ -585,7 +612,7 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode)
return;
}
- if (!ext4_fc_eligible(inode->i_sb))
+ if (!ext4_fc_handle_eligible(inode->i_sb, handle))
return;
/*
@@ -645,7 +672,7 @@ void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t star
if (S_ISDIR(inode->i_mode))
return;
- if (!ext4_fc_eligible(inode->i_sb))
+ if (!ext4_fc_handle_eligible(inode->i_sb, handle))
return;
if (ext4_has_inline_data(inode)) {
@@ -1782,9 +1809,11 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
list_splice_init(&sbi->s_fc_q[FC_Q_STAGING],
&sbi->s_fc_q[FC_Q_MAIN]);
- if (tid_geq(tid, sbi->s_fc_ineligible_tid)) {
- sbi->s_fc_ineligible_tid = 0;
+ if (full && tid_geq(tid, sbi->s_fc_ineligible_tid)) {
ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
+ /* Pairs with smp_rmb() in ext4_fc_handle_eligible(). */
+ smp_wmb();
+ WRITE_ONCE(sbi->s_fc_ineligible_tid, 0);
}
if (full)
--
2.39.5
next prev parent reply other threads:[~2026-11-30 16:39 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 ` [PATCH 1/3] ext4: do not skip fast commit for updates queued during ongoing commit Xing Ma
2026-11-30 16:57 ` 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 ` Xing Ma [this message]
2026-11-30 16:58 ` [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible 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-4-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