From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.230.114 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060327; b=DOF1UPZw1REGZfY73YqqylPFScLxQ07PXBG7rLnMY64C5uPbtef5HA5piGOyETh0OUjF As88O4vnkycAGtjNWxq1tkERcq9ENNq6cVHEk5zKzQmYnFlAAHcCJiJQw9TXkv7/+Hkoc NnUANAUZXyRq4rNxBgApy7EcVl8GM+VsVd0/S8sizFA0t/VlOh8i3MD7NBFjOOXmxiSca kUrJKPlfIERNDhI2zmP2KSvZwBhfHFCXkJU1KWTZOEXjliaA4X2ZjRhLXwXPxo2XbGDqZ wZQuvrIQ4PqEf11/R0Wa8tz7S5wMW4ke/UWlYT4cKWJVEFi4Sbz3GWtugahGIia2yeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060327; h=DMARC-Filter:DKIM-Signature:To:Mime-Version:X-Lms-Return-Path: Content-Transfer-Encoding:X-Original-From:Message-Id:In-Reply-To:Cc: From:References:Content-Type:Subject:Date; bh=ti9WJ84QEhviB9Y6jVUc1q4t+dj5HiAtqHDlHhe6opk=; b=3gpPcIxBbYMker9FxLtACGHLm5tyELlXCULPSWnfRn1vxPKMSTJEIvIFMd43MGvzTcWO y9SVRhxrcJspuqF7qt3N8/djufwGVTvgAWH4fGU2HbQIcZSkZcdyuCAKbGi05N9rI9J72 ETouNEdLtHHftuDBEVh9P9n7pKH/M/9xL30LV1BmZNLWs0cJXVAlKp5FEy0IWMRKGF2id OhaDSWqijugrE9NCvvHKLBcPWQDUPqGL1aIZCOgasVoYdMNhMuwb+jeNWqVFt5VxxUm89 HbhwcnsWEEN58IfF5F4lT8XzrYda3RMRHTxKot3fRdvqJbYdo7mHWojEXEKEcIIrMJQ== 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="C/A3aY3C"; arc=none smtp.remote-ip=209.127.230.114 Received: from va-1-114.ptr.blmpb.com (va-1-114.ptr.blmpb.com [209.127.230.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 01A7F606A325 for ; Mon, 30 Nov 2026 17:38:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 01A7F606A325 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=C/A3aY3C DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796060322; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=ti9WJ84QEhviB9Y6jVUc1q4t+dj5HiAtqHDlHhe6opk=; b=C/A3aY3CuLyL4ystfd9H/5gmQPMvZLAQP/EuV5CUMsxe8qR4gZe+FpekYpQRc0Urq24m0D W814KfKtfEUSCPV3uZS20lAvuy19VnkuDMH1F4XXQPAiIA4VlBejiTqgeVkRMaT2uj1tDQ iICA2pKiXOstDteDCGqh4x7txfKOEcyaYDnRdVp8ANTVVFCKtzte7ZhFnzLPYaWa/OWz+J BGeyEXF8i3UfmtkpnLcyRl0uI/cWA+XeLvoO2tpB+pZvzkp+snLwI42oN6cN14q1ChcuWu fuzmSL7RD7xqwlkXVjLe6RxkseQQ5ffLY0R8gMej9OhqNU/gxGSadVOgG3As4w== To: 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-Lms-Return-Path: Content-Transfer-Encoding: 7bit X-Original-From: Xing Ma Message-Id: <20261201013742.1562967-3-maxing.lan@bytedance.com> In-Reply-To: <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" , From: "Xing Ma" References: <20261201013742.1562967-1-maxing.lan@bytedance.com> Content-Type: text/plain; charset=UTF-8 Subject: [PATCH v2 2/3] ext4: do not skip fast commit for updates queued during ongoing commit Date: Tue, 01 Dec 2026 01:37:44 +0800 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. Increment s_fc_subtid in ext4_fc_cleanup() under the same write_lock(&journal->j_state_lock) that clears JBD2_FAST_COMMIT_ONGOING so readers never observe the incremented subtid while the old ongoing flag is still set. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Cc: stable@vger.kernel.org Signed-off-by: Xing Ma --- fs/ext4/ext4.h | 1 + fs/ext4/fast_commit.c | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index dc2c181337a16..fb595277f2c1c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1860,6 +1860,7 @@ struct ext4_sb_info { /* Ext4 fast commit sub transaction ID */ atomic_t s_fc_subtid; + bool s_fc_commit_succeeded; /* * After commit starts, the main queue gets locked, and the further diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index ecc5fee9f6b54..f02dca2c9a3a1 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1597,7 +1597,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; @@ -1610,11 +1610,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, @@ -1663,7 +1676,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) status = EXT4_FC_STATUS_FAILED; goto fallback; } - atomic_inc(&sbi->s_fc_subtid); + sbi->s_fc_commit_succeeded = true; ret = jbd2_fc_end_commit(journal); set_task_ioprio(current, old_ioprio); /* @@ -1786,10 +1799,15 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) * FC_Q_STAGING after the splice above has already drained it. */ write_lock(&journal->j_state_lock); - if (full) + if (full) { journal->j_flags &= ~JBD2_FULL_COMMIT_ONGOING; - else + } else { + if (sbi->s_fc_commit_succeeded) { + sbi->s_fc_commit_succeeded = false; + atomic_inc(&sbi->s_fc_subtid); + } journal->j_flags &= ~JBD2_FAST_COMMIT_ONGOING; + } write_unlock(&journal->j_state_lock); ext4_fc_unlock(sb, alloc_ctx); -- 2.39.5