* [PATCH 0/3] ext4: fix concurrent fast commit durability and tracking races
@ 2026-11-30 16:38 Xing Ma
2026-11-30 16:38 ` [PATCH 1/3] ext4: do not skip fast commit for updates queued during ongoing commit Xing Ma
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Xing Ma @ 2026-11-30 16:38 UTC (permalink / raw)
To: linux-ext4
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, Harshad Shirwadkar,
Xin Yin, Xing Ma
Under concurrent writers and fsync() workloads (reproducible with
xfstests generic/455 and MKFS_OPTIONS="-O fast_commit"), ext4 fast
commit has three concurrency races that lose fsync()'d updates or leave
extents inconsistent after crash recovery:
1. ext4_fc_commit() skips committing when an already-ongoing fast
commit increments s_fc_subtid, even though the waiting caller's
updates were queued on FC_Q_STAGING or marked EXT4_STATE_FC_REQUEUE
and were not included in that commit.
2. __jbd2_fc_end_commit() and jbd2_journal_commit_transaction() invoke
ext4_fc_cleanup() before clearing JBD2_FAST_COMMIT_ONGOING /
JBD2_FULL_COMMIT_ONGOING, letting concurrent updates land on
FC_Q_STAGING after cleanup drains it and remain stranded during the
next fast commit.
3. ext4_fc_track_{inode,range,create,link,unlink}() skip tracking
whenever EXT4_MF_FC_INELIGIBLE is set without comparing
handle->h_transaction->t_tid against s_fc_ineligible_tid, dropping
tracking for transaction T + 1 while transaction T finishes its full
commit; ext4_fc_cleanup() also cleared EXT4_MF_FC_INELIGIBLE when
full == 0.
Testing on tytso/ext4.git dev (aceadbccd428f):
- xfstests generic/455 (-O fast_commit): 7/26 FAIL (~27%) before;
48/48 PASS after (96/96 PASS combined with the companion orphan and
truncate fast commit fixes).
- KUnit ext4_fast_commit_test: 11/11 PASS, 0 lockdep warnings.
Xing Ma (3):
ext4: do not skip fast commit for updates queued during ongoing commit
ext4: splice stranded fast commit staging queues before starting
commit
ext4: keep tracking newer transactions while older tid is
fc-ineligible
fs/ext4/fast_commit.c | 74 +++++++++++++++++++++++++++++++++++--------
1 file changed, 61 insertions(+), 13 deletions(-)
base-commit: aceadbccd428fb8e6593b27a3091d961f80225d1
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] ext4: do not skip fast commit for updates queued during ongoing commit
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
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:38 ` [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible Xing Ma
2 siblings, 1 reply; 8+ messages in thread
From: Xing Ma @ 2026-11-30 16:38 UTC (permalink / raw)
To: linux-ext4
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, Harshad Shirwadkar,
Xin Yin, Xing Ma, stable
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] ext4: splice stranded fast commit staging queues before starting commit
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:38 ` 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
2 siblings, 1 reply; 8+ messages in thread
From: Xing Ma @ 2026-11-30 16:38 UTC (permalink / raw)
To: linux-ext4
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, Harshad Shirwadkar,
Xin Yin, Xing Ma, stable
In both __jbd2_fc_end_commit() and jbd2_journal_commit_transaction(),
j_fc_cleanup_callback (ext4_fc_cleanup()) splices FC_Q_STAGING into
FC_Q_MAIN and releases s_fc_lock BEFORE JBD2_FAST_COMMIT_ONGOING /
JBD2_FULL_COMMIT_ONGOING is cleared under j_state_lock.
If a concurrent writer calls ext4_fc_track_template() or
__track_dentry_update() in that window, it still observes the ONGOING
flag set and inserts its inode or dentry update onto FC_Q_STAGING after
ext4_fc_cleanup() has already drained it. When that writer then calls
fsync() after the flag clears, ext4_fc_perform_commit() only processes
FC_Q_MAIN and writes an empty fast commit while the update remains
stranded on FC_Q_STAGING.
Splice s_fc_dentry_q[FC_Q_STAGING] and s_fc_q[FC_Q_STAGING] onto the
tail of FC_Q_MAIN under s_fc_lock at Step 1 of ext4_fc_perform_commit()
so any stranded updates are included in chronological order.
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 | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 03ab9b8a2d983..e03a829e2a10a 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1353,11 +1353,17 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid)
u64 locked_ns;
/*
- * Step 1: Mark all inodes on s_fc_q[MAIN] with
- * EXT4_STATE_FC_FLUSHING_DATA. This prevents these inodes from being
- * freed until the data flush is over.
+ * Step 1: Splice any entries that landed on STAGING while the
+ * previous commit was clearing its ONGOING flag, then mark all
+ * inodes on s_fc_q[MAIN] with EXT4_STATE_FC_FLUSHING_DATA. This
+ * prevents these inodes from being freed until the data flush is
+ * over.
*/
alloc_ctx = ext4_fc_lock(sb);
+ list_splice_tail_init(&sbi->s_fc_dentry_q[FC_Q_STAGING],
+ &sbi->s_fc_dentry_q[FC_Q_MAIN]);
+ list_splice_tail_init(&sbi->s_fc_q[FC_Q_STAGING],
+ &sbi->s_fc_q[FC_Q_MAIN]);
list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) {
ext4_set_inode_state(&iter->vfs_inode,
EXT4_STATE_FC_FLUSHING_DATA);
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible
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:38 ` [PATCH 2/3] ext4: splice stranded fast commit staging queues before starting commit Xing Ma
@ 2026-11-30 16:38 ` Xing Ma
2026-11-30 16:58 ` sashiko-bot
2026-12-01 6:13 ` kernel test robot
2 siblings, 2 replies; 8+ messages in thread
From: Xing Ma @ 2026-11-30 16:38 UTC (permalink / raw)
To: linux-ext4
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, Harshad Shirwadkar,
Xin Yin, Xing Ma, stable
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] ext4: splice stranded fast commit staging queues before starting commit
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
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-30 16:54 UTC (permalink / raw)
To: Xing Ma, linux-ext4; +Cc: tytso
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ext4: dentry update reordering in ext4_fc_perform_commit()
staging splice
- [High] ext4: concurrent handle updates split by splice in
ext4_fc_perform_commit()
- [Low] ext4: inaccurate Fixes trailer in commit message for staging
queue race
--
commit 7490b868c8b70faeca81dcb7b1cdc8721e4fd438
Author: Xing Ma <maxing.lan@bytedance.com>
> ext4: splice stranded fast commit staging queues before starting commit
>
> In both __jbd2_fc_end_commit() and jbd2_journal_commit_transaction(),
> j_fc_cleanup_callback (ext4_fc_cleanup()) splices FC_Q_STAGING into
> FC_Q_MAIN and releases s_fc_lock BEFORE JBD2_FAST_COMMIT_ONGOING /
> JBD2_FULL_COMMIT_ONGOING is cleared under j_state_lock.
>
> If a concurrent writer calls ext4_fc_track_template() or
> __track_dentry_update() in that window, it still observes the ONGOING
> flag set and inserts its inode or dentry update onto FC_Q_STAGING after
> ext4_fc_cleanup() has already drained it. When that writer then calls
> fsync() after the flag clears, ext4_fc_perform_commit() only processes
> FC_Q_MAIN and writes an empty fast commit while the update remains
> stranded on FC_Q_STAGING.
>
> Splice s_fc_dentry_q[FC_Q_STAGING] and s_fc_q[FC_Q_STAGING] onto the
> tail of FC_Q_MAIN under s_fc_lock at Step 1 of ext4_fc_perform_commit()
> so any stranded updates are included in chronological order.
>
> Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xing Ma <maxing.lan@bytedance.com>
[Severity: Low]
In aa75f4d3daae ("ext4: main fast-commit commit path"),
ext4_fc_track_template() and __track_dentry_update() checked
EXT4_FC_COMMITTING under s_fc_lock, and ext4_fc_cleanup() cleared
EXT4_FC_COMMITTING inside the same s_fc_lock critical section right after
splicing FC_Q_STAGING into FC_Q_MAIN. The post-cleanup window only
appeared when queue selection was switched to JBD2_FULL_COMMIT_ONGOING and
JBD2_FAST_COMMIT_ONGOING. Should the Fixes: tag instead be:
Fixes: bdc8a53a6f2f ("ext4: fast commit may miss file actions")
> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index 03ab9b8a2d983..e03a829e2a10a 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
> @@ -1353,11 +1353,17 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid)
> u64 locked_ns;
>
> /*
> - * Step 1: Mark all inodes on s_fc_q[MAIN] with
> - * EXT4_STATE_FC_FLUSHING_DATA. This prevents these inodes from being
> - * freed until the data flush is over.
> + * Step 1: Splice any entries that landed on STAGING while the
> + * previous commit was clearing its ONGOING flag, then mark all
> + * inodes on s_fc_q[MAIN] with EXT4_STATE_FC_FLUSHING_DATA. This
> + * prevents these inodes from being freed until the data flush is
> + * over.
> */
> alloc_ctx = ext4_fc_lock(sb);
> + list_splice_tail_init(&sbi->s_fc_dentry_q[FC_Q_STAGING],
> + &sbi->s_fc_dentry_q[FC_Q_MAIN]);
[Severity: High]
Does list_splice_tail_init() on s_fc_dentry_q[FC_Q_STAGING] invert the
order of stranded dentry updates relative to updates queued after the
ONGOING flag clears?
CPU0 (previous commit) CPU1 (writer)
ext4_fc_cleanup()
splice STAGING -> MAIN
ext4_fc_unlock()
unlink("foo")
__track_dentry_update()
/* ONGOING still set */
list_add_tail(D1, STAGING)
clear JBD2_FAST_COMMIT_ONGOING
creat("foo")
__track_dentry_update()
/* ONGOING now clear */
list_add_tail(D2, MAIN)
fsync()
ext4_fc_perform_commit()
list_splice_tail_init(STAGING, MAIN)
/* MAIN is now [D2, D1] */
The same inversion can also happen within a single overwriting
ext4_rename(), which acquires and releases s_fc_lock separately for
ext4_fc_track_unlink(), __ext4_fc_track_link() and
__ext4_fc_track_unlink().
Because ext4_fc_commit_dentry_updates() writes TLVs in
s_fc_dentry_q[FC_Q_MAIN] order, crash recovery replays the newer link or
creat (D2) before the older unlink (D1). In
ext4_fc_replay_link_internal(), __ext4_link() returns -EEXIST and is
ignored, and the subsequent unlink replay deletes the newly created or
renamed directory entry.
> + list_splice_tail_init(&sbi->s_fc_q[FC_Q_STAGING],
> + &sbi->s_fc_q[FC_Q_MAIN]);
[Severity: High]
Can splicing FC_Q_STAGING into FC_Q_MAIN here split a concurrent journal
handle's updates across two fast commits?
ext4_fc_commit() calls jbd2_fc_begin_commit(), which sets
JBD2_FAST_COMMIT_ONGOING before calling ext4_fc_perform_commit(), while
active handles are not drained until jbd2_journal_lock_updates() in
Step 4:
CPU0 (fsync) CPU1 (ext4_create)
jbd2_fc_begin_commit()
set JBD2_FAST_COMMIT_ONGOING
ext4_new_inode_start_handle()
ext4_fc_track_inode()
/* ONGOING set -> STAGING */
list_add_tail(inode,
s_fc_q[STAGING])
ext4_fc_perform_commit()
/* Step 1 */
list_splice_tail_init(STAGING,
MAIN)
/* inode moved to MAIN */
ext4_fc_track_create()
/* queued after Step 1 splice */
list_add_tail(CREAT,
s_fc_dentry_q[STAGING])
/* Step 4 */
jbd2_journal_lock_updates()
ext4_fc_snapshot_inodes()
/* snapshots inode on MAIN,
* resets i_fc_lblk_len = 0 */
/* Step 6 */
/* writes inode without CREAT;
* ext4_fc_cleanup() drops inode
* from MAIN and moves CREAT to
* MAIN for the next commit */
Any extent updates tracked on the new inode before Step 4 sets
EXT4_STATE_FC_COMMITTING do not set EXT4_STATE_FC_REQUEUE, so the current
fast commit logs the inode and its extents without EXT4_FC_TAG_CREAT and
removes the inode from s_fc_q[FC_Q_MAIN], leaving EXT4_FC_TAG_CREAT for a
later fast commit where i_fc_lblk_len has already been cleared. Multi-step
dentry operations under one handle (such as ext4_rename() or
__ext4_unlink()) can likewise have their earlier tracking calls spliced
into the current fast commit while their remaining calls stay in
FC_Q_STAGING.
Would splicing FC_Q_STAGING into FC_Q_MAIN in jbd2_fc_begin_commit() (or
in ext4_fc_cleanup() after the ONGOING flag is cleared) while holding
s_fc_lock avoid racing with handles that observe the new commit's
JBD2_FAST_COMMIT_ONGOING flag?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130163819.13819-1-maxing.lan@bytedance.com?part=2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] ext4: do not skip fast commit for updates queued during ongoing commit
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
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-30 16:57 UTC (permalink / raw)
To: Xing Ma, linux-ext4; +Cc: tytso
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: double-counted target_subtid in ext4_fc_commit() during
cleanup
--
commit b8e5dbb706be86ee24d82de27b0c55791a280c70
Author: Xing Ma <maxing.lan@bytedance.com>
ext4: do not skip fast commit for updates queued during ongoing commit
This commit samples s_fc_subtid and JBD2_FAST_COMMIT_ONGOING under
j_state_lock at entry to ext4_fc_commit() so callers wait for an
additional fast commit when one is already in progress.
> 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);
[Severity: Medium]
Can target_subtid be incremented twice for the same ongoing fast commit
when ext4_fc_commit() enters while another commit is in cleanup?
ext4_fc_commit() increments sbi->s_fc_subtid before calling
jbd2_fc_end_commit(), whereas __jbd2_fc_end_commit() clears
JBD2_FAST_COMMIT_ONGOING only after j_fc_cleanup_callback()
(ext4_fc_cleanup()) returns:
CPU0 (s_fc_subtid == N) CPU1
ext4_fc_commit()
...
atomic_inc(&sbi->s_fc_subtid)
-> N + 1
jbd2_fc_end_commit()
__jbd2_fc_end_commit()
ext4_fc_cleanup()
ext4_fc_commit()
read_lock(&journal->j_state_lock)
target_subtid = (N + 1) + 1
JBD2_FAST_COMMIT_ONGOING is set
-> target_subtid = N + 3
read_unlock(&journal->j_state_lock)
write_lock(&journal->j_state_lock)
j_flags &= ~JBD2_FAST_COMMIT_ONGOING
write_unlock(&journal->j_state_lock)
After the next fast commit (N + 2) commits the updates spliced onto
FC_Q_MAIN during CPU0's cleanup, CPU1 wakes from jbd2_fc_begin_commit()
with s_fc_subtid == N + 2 < target_subtid (N + 3) and restarts to run an
extra fast commit.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130163819.13819-1-maxing.lan@bytedance.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible
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
2026-12-01 6:13 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-30 16:58 UTC (permalink / raw)
To: Xing Ma, linux-ext4; +Cc: tytso
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ext4: ext4_rename() checks EXT4_MF_FC_INELIGIBLE causing torn
fc tracking
- [Medium] ext4: ordering race in ext4_fc_cleanup() passes
s_fc_ineligible_tid=0 to tid_gt()
- [Low] ext4: unused static ext4_fc_eligible() when
CONFIG_EXT4_KUNIT_TESTS=n
--
commit ab665c709db8ebc5f4e6685eece8b5ca94164b47
Author: Xing Ma <maxing.lan@bytedance.com>
ext4: keep tracking newer transactions while older tid is fc-ineligible
This commit introduces ext4_fc_handle_eligible() so that handles in a
newer transaction continue tracking fast-commit updates while an older
ineligible transaction is still committing, and only clears
EXT4_MF_FC_INELIGIBLE in ext4_fc_cleanup() on a full commit.
> 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));
> +}
[Severity: Low]
Does leaving ext4_fc_eligible() unconditionally defined trigger a
-Wunused-function warning when CONFIG_EXT4_KUNIT_TESTS is disabled?
All non-test callers of ext4_fc_eligible() are replaced with
ext4_fc_handle_eligible(), leaving ext4_fc_eligible_test() under
#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) as the only caller.
[ ... ]
> @@ -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);
> }
[Severity: High]
Can a rename in transaction T + 1 still suffer torn fast-commit tracking
while transaction T is committing?
ext4_rename() calls ext4_fc_track_unlink(handle, new.dentry), which now
uses ext4_fc_handle_eligible(), but then checks EXT4_MF_FC_INELIGIBLE
directly before tracking the link and unlink of the renamed file:
fs/ext4/namei.c:ext4_rename() {
...
if (new.inode)
ext4_fc_track_unlink(handle, new.dentry);
if (test_opt2(sb, JOURNAL_FAST_COMMIT) &&
!(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY) &&
!(ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE))) {
__ext4_fc_track_link(handle, old.inode, new.dentry);
__ext4_fc_track_unlink(handle, old.inode, old.dentry);
if (whiteout)
__ext4_fc_track_create(handle, whiteout,
old.dentry);
}
...
}
For an overwriting rename in T + 1 while T is performing a full commit,
fast commit tracks EXT4_FC_TAG_UNLINK for new.dentry (and the inode
updates via ext4_mark_inode_dirty()) without tracking EXT4_FC_TAG_LINK for
new.dentry or EXT4_FC_TAG_UNLINK for old.dentry. Once T finishes and a
subsequent fsync() commits T + 1, crash recovery replays the destination
unlink without linking the replacement file.
[ ... ]
> @@ -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);
> }
[Severity: Medium]
Can ext4_fc_handle_eligible() race with ext4_fc_cleanup() and pass
s_fc_ineligible_tid == 0 to tid_gt()?
Because both functions access EXT4_MF_FC_INELIGIBLE before
s_fc_ineligible_tid, a reader can see the flag set and then read the
zeroed TID:
CPU0 CPU1
ext4_fc_handle_eligible() ext4_fc_cleanup()
ext4_test_mount_flag(
..., EXT4_MF_FC_INELIGIBLE) == 1
ext4_clear_mount_flag(
..., EXT4_MF_FC_INELIGIBLE)
smp_wmb()
WRITE_ONCE(
sbi->s_fc_ineligible_tid, 0)
smp_rmb()
tid_gt(t_tid, 0) <-- false when t_tid >= 0x80000000
As noted in ebc4b2c1ac92 ("ext4: fix incorrect tid assumption in
ext4_fc_mark_ineligible()"), tid_gt() uses signed 32-bit subtraction
((int)(x - y) > 0), so tid_gt(t_tid, 0) returns false whenever t_tid has
bit 31 set, causing ext4_fc_handle_eligible() to skip tracking for
transaction T + 1.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130163819.13819-1-maxing.lan@bytedance.com?part=3
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible
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
@ 2026-12-01 6:13 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2026-12-01 6:13 UTC (permalink / raw)
To: Xing Ma, linux-ext4
Cc: oe-kbuild-all, Theodore Ts'o, Andreas Dilger, Jan Kara,
Baokun Li, Ojaswin Mujoo, Ritesh Harjani, Zhang Yi,
Harshad Shirwadkar, Xin Yin, Xing Ma, stable
Hi Xing,
kernel test robot noticed the following build warnings:
[auto build test WARNING on aceadbccd428fb8e6593b27a3091d961f80225d1]
url: https://github.com/intel-lab-lkp/linux/commits/Xing-Ma/ext4-do-not-skip-fast-commit-for-updates-queued-during-ongoing-commit/20261201-003817
base: aceadbccd428fb8e6593b27a3091d961f80225d1
patch link: https://lore.kernel.org/r/20261130163819.13819-4-maxing.lan%40bytedance.com
patch subject: [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261201/20261201135934.3nyhX0Cn-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261201/20261201135934.3nyhX0Cn-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261201135934.3nyhX0Cn-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> fs/ext4/fast_commit.c:232:13: warning: 'ext4_fc_eligible' defined but not used [-Wunused-function]
232 | static bool ext4_fc_eligible(struct super_block *sb)
| ^~~~~~~~~~~~~~~~
vim +/ext4_fc_eligible +232 fs/ext4/fast_commit.c
b7b80a35fb51319 Ye Bin 2022-09-16 231
0f5f14f334c85ef NeilBrown 2026-03-20 @232 static bool ext4_fc_eligible(struct super_block *sb)
0f5f14f334c85ef NeilBrown 2026-03-20 233 {
0f5f14f334c85ef NeilBrown 2026-03-20 234 return !ext4_fc_disabled(sb) &&
0f5f14f334c85ef NeilBrown 2026-03-20 235 !(ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE));
0f5f14f334c85ef NeilBrown 2026-03-20 236 }
0f5f14f334c85ef NeilBrown 2026-03-20 237
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-01 6:14 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible Xing Ma
2026-11-30 16:58 ` sashiko-bot
2026-12-01 6:13 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox