From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.114 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056767; b=GbgSsgAOE5etms07OAzpUfwXIMLwZlygpYE0ihuprvRzOG5nt0vHF6miRKY5CtNAgBG0 l2ia5O6ihukZDjw7WBuM/dFhs5e517QSe7/4eR5HnY/XDPd4qvttUyZaupqrigrS0m8dR bgmlJ748tiN1GkknXG2a9KPXUQx4reIgvPzuERnIP4IxsAERpPXQktZRRKZY76Ymxq9CX Y00KfTMXnctTsC1HHXBAW4KBm/Qq5PLzDzjTPPpXkOib6+TgmJmARcYlfx3QijFoci5CQ wiQ/X1dPQabJ1q6n6+W1IdHMEemaVj49VmIe+6g6CZf7Avnf2KtdNwGnbOsaV9nWqzQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056767; h=DMARC-Filter:DKIM-Signature:To:Content-Transfer-Encoding:Cc:X-Mailer: X-Lms-Return-Path:Subject:Date:References:In-Reply-To:From:Message-Id: Mime-Version:X-Original-From:Content-Type; bh=ziTafYq2tkVCXUrlsKGoGDtuypgYef05tSoDvKra4E0=; b=LO9xOy//DFnbzZ/wu3e5AGMdq/DHDHOxr14vWzlLCesjaf89JpEzrNJyjwXhOWqUiga1 RhiJPZCjjmYljZvSYrX7mnNg40SJYNxRbH/rivV4BzTYSh1UqYtw83lemHCI3q0NFE0I8 E+c9rUFu8Mn3m8s4A+HmCOqHdUG/6CTMaZfdDGRFMLYw42vsbXJZiatWbjb0oCQW++Ow2 k4AjuHbW/i0ppqTMr1/7fHZRkBoVIeDGUeAvLQygz6++QCGI9btq+e6OmR+E/O2wGKrK9 i/hR9bZFD/YAppXAH5Q0vAW+etPKQxz1cZ8iJbJVddqZ8EHfr8gK43pliCadwr8tyvg== 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=aVKnco1F; arc=none smtp.remote-ip=209.127.231.114 Received: from va-2-114.ptr.blmpb.com (va-2-114.ptr.blmpb.com [209.127.231.114]) (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 EE5A6606A31C for ; Mon, 30 Nov 2026 16:39:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EE5A6606A31C 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=aVKnco1F DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796056762; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=ziTafYq2tkVCXUrlsKGoGDtuypgYef05tSoDvKra4E0=; b=aVKnco1F21CzrP5ygQmnaygHHMJ8GxakxrR/iatMZKGaWt6GVCboqK9EOZEPDqR+E7hs+5 oUUbS/pM1uXTnQb8+ImDffgRL305sQAC33IgT0QdYRdM4RCuhHDE2JI77L1ntiBCTXS/LC yP7KNPTKa8FzXF08ULeE4xp7+mdNpA4q6IcukRInSfL4zUNmKY89v4bQjJhpnExk+gOQ7Q Pz4pCwX2MPwTq7xFxorov9OoRPfqfqvi9RNtKhdWtjlO1YP8loBAt9iFMTEMYah9VlbdIh CXWEmMOsVm50bTi6aggxDHatq3OpDljCzHd1nVpZDUxonk06FEH0yyb7PZ9B6w== To: Content-Transfer-Encoding: 7bit Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani" , "Zhang Yi" , "Harshad Shirwadkar" , "Xin Yin" , "Xing Ma" , X-Mailer: git-send-email 2.54.0 X-Lms-Return-Path: Subject: [PATCH 3/3] ext4: keep tracking newer transactions while older tid is fc-ineligible Date: Tue, 1 Dec 2026 00:38:19 +0800 References: <20261130163819.13819-1-maxing.lan@bytedance.com> In-Reply-To: <20261130163819.13819-1-maxing.lan@bytedance.com> From: "Xing Ma" Message-Id: <20261130163819.13819-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 X-Original-From: Xing Ma Content-Type: text/plain; charset=UTF-8 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 --- 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