Linux EXT4 FS development
 help / color / mirror / Atom feed
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 2/3] ext4: splice stranded fast commit staging queues before starting commit
Date: Tue,  1 Dec 2026 00:38:18 +0800	[thread overview]
Message-ID: <20261130163819.13819-3-maxing.lan@bytedance.com> (raw)
In-Reply-To: <20261130163819.13819-1-maxing.lan@bytedance.com>

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

  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 ` Xing Ma [this message]
2026-11-30 16:54   ` [PATCH 2/3] ext4: splice stranded fast commit staging queues before starting commit 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-3-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