From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.230.111 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060341; b=ex/76XXV8EX33DjAN768uVCUsVCsoYoNGzvalCeEixPQY1ShQsbf81uvm84/a6ardXOU rB0fh3FdpPbgufpsvunG7dn1tJD4r/UHWeWH/b+us7YpNxn1xoRIKMLI7ht6eqj5E97Al PIBDp5CQIgWWxiRV6YM+ZxgaiRSaqLxze9qpdDbaPLF3l+ji7nb8LcG00E9j7CH5fvIcA Bzkp1QCIRS+QjQtrUpes+cb9jt2jwdCmX5M5KGXX3/lMyUotrXvmzxvekDgzGBTCDTQNC 4mcYuYR6LTIsH77cvNiaBd4ac9Bch+66uYOoXZ+Xfzd6l9Pad2QsijOwVSpVfNj4aAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060341; h=DMARC-Filter:DKIM-Signature:Content-Type:X-Original-From:To: Message-Id:Mime-Version:From:References:Cc:Date:X-Lms-Return-Path: Subject:In-Reply-To:Content-Transfer-Encoding; bh=5bbB+tNr0Goe8S5TSVmxBxj9Jem4x1v2P63GqwE7Gyg=; b=w/kUfHpROzlLhYBhG65N/HfvV0GkIAnKw7FsEvusSblwWuhCuOFPiFe4h6wUHBjbe1Ph q+diWIuayXCgYuUcY4gceHgCLJXFnG25mbUeSIjUh+pyxRK71PRE/qv/V8gMXpeNn5v24 OVCnRZcd+q6tBmmRSBmhUIMgI3KefIgWw4xuX3tizJh3P8XylNvm+cF4Wz5tLQejxPzWv gnBGruuIqKqKjXMxYsCd9vfCsLUIFaVVa/vNw5w3glmic1gymGFfZfqvZ+j0ejIxVg+Dv KIVNp9ODzUQdvm/PajI5+dlYFscV52DgQfykvPVuDIP/tL5bABgcRWTCXfErroHhz3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=EzrdaGBQ; arc=none smtp.remote-ip=209.127.230.111 Received: from va-1-111.ptr.blmpb.com (va-1-111.ptr.blmpb.com [209.127.230.111]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0C20606A320 for ; Mon, 30 Nov 2026 17:39:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A0C20606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=EzrdaGBQ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796060335; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=5bbB+tNr0Goe8S5TSVmxBxj9Jem4x1v2P63GqwE7Gyg=; b=EzrdaGBQbxxHdYttUBOA/4NcP7L4w1WqFH7ysV01HoeX3leZa6p1u9NjAva4+3wztLrsXY nt6dMIY+9AUcVZoF+cGlZqac4dQPw9nohinw20/8Y5JW5ffj/5ICLRCmvk+0ZdPjSJCWST p49qDjSnZaUCJAnldZjj6l5Q2QadwtaAqjuJL7541a8p1raDk6NSvNzYjKgqbGMaddhNGX +1Vv6Go9d/sAW5F58IS7pi6Ye5KbzNWxfGyGDbIiuArN2pYD7Wv3FfUvbW7pfTChO9oAAo OVBsLwUvZeY3gaBhAoBTTCHI2Sg/5PWEVndgfpiT0YtpUnQpldVf22phaQXueg== Content-Type: text/plain; charset=UTF-8 X-Original-From: Xing Ma To: Message-Id: <20261201013742.1562967-4-maxing.lan@bytedance.com> X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 From: "Xing Ma" References: <20261201013742.1562967-1-maxing.lan@bytedance.com> Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani (IBM)" , "Zhang Yi" , "Harshad Shirwadkar" , "Xin Yin" , Date: Tue, 01 Dec 2026 01:37:45 +0800 X-Lms-Return-Path: Subject: [PATCH v2 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible In-Reply-To: <20261201013742.1562967-1-maxing.lan@bytedance.com> Content-Transfer-Encoding: 7bit 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}() and ext4_rename() 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() and use it in all fast commit tracking entry points (including ext4_rename()). On the slow path when EXT4_MF_FC_INELIGIBLE is set, re-check under s_fc_lock (serializing with ext4_fc_mark_ineligible() and ext4_fc_cleanup() so a cleared s_fc_ineligible_tid == 0 is never passed to tid_gt()) and continue tracking handles whose TID is newer than s_fc_ineligible_tid. Also inline ext4_fc_eligible() into ext4_fc_eligible_test() to avoid an unused-function warning when CONFIG_EXT4_KUNIT_TESTS=n, 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 --- fs/ext4/ext4.h | 1 + fs/ext4/fast_commit.c | 47 ++++++++++++++++++++++++++++++++++--------- fs/ext4/namei.c | 4 +--- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index fb595277f2c1c..f7ecd7925e8e3 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3144,6 +3144,7 @@ void ext4_fc_init(struct super_block *sb, journal_t *journal); void ext4_fc_init_inode(struct inode *inode); void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start, ext4_lblk_t end); +bool ext4_fc_handle_eligible(struct super_block *sb, handle_t *handle); void __ext4_fc_track_unlink(handle_t *handle, struct inode *inode, struct dentry *dentry); void __ext4_fc_track_link(handle_t *handle, struct inode *inode, diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index f02dca2c9a3a1..6af6c1d37e4b4 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -229,10 +229,36 @@ static bool ext4_fc_disabled(struct super_block *sb) (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)); } -static bool ext4_fc_eligible(struct super_block *sb) +bool ext4_fc_handle_eligible(struct super_block *sb, handle_t *handle) { - return !ext4_fc_disabled(sb) && - !(ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)); + struct ext4_sb_info *sbi = EXT4_SB(sb); + bool eligible; + int alloc_ctx; + + 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. Re-check under s_fc_lock (which serializes both + * ext4_fc_mark_ineligible() and ext4_fc_cleanup()) so we never compare + * against a cleared s_fc_ineligible_tid == 0, and continue tracking + * handles whose TID is newer than s_fc_ineligible_tid. + */ + alloc_ctx = ext4_fc_lock(sb); + if (!ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) + eligible = true; + else + eligible = tid_gt(handle->h_transaction->t_tid, + sbi->s_fc_ineligible_tid); + ext4_fc_unlock(sb, alloc_ctx); + + return eligible; } /* @@ -522,7 +548,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); } @@ -543,7 +569,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); } @@ -565,7 +591,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); } @@ -594,7 +620,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; /* @@ -654,7 +680,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)) { @@ -1785,7 +1811,7 @@ 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)) { + if (full && tid_geq(tid, sbi->s_fc_ineligible_tid)) { sbi->s_fc_ineligible_tid = 0; ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE); } @@ -2860,7 +2886,8 @@ EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_fc_disabled_test); bool ext4_fc_eligible_test(struct super_block *sb) { - return ext4_fc_eligible(sb); + return !ext4_fc_disabled(sb) && + !(ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)); } EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_fc_eligible_test); diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b2753daad49f4..85942dde3421a 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3865,9 +3865,7 @@ static int ext4_rename(const struct mnt_idmap *idmap, struct inode *old_dir, 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))) { + if (ext4_fc_handle_eligible(sb, handle)) { __ext4_fc_track_link(handle, old.inode, new.dentry); __ext4_fc_track_unlink(handle, old.inode, old.dentry); if (whiteout) -- 2.39.5