From: sashiko-bot@kernel.org
To: "Wesley Atwell" <atwellwea@gmail.com>
Cc: linux-ext4@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
tytso@mit.edu
Subject: Re: [PATCH] ext4: force a full commit when quota data is modified
Date: Sat, 28 Nov 2026 21:45:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-239048@kernel.org> (raw)
In-Reply-To: <kernel-7f509bcdfe16388c-v1.atwellwea@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ext4: premature clearing of EXT4_MF_FC_INELIGIBLE in
ext4_fc_cleanup()
- [Medium] ext4: late ext4_fc_mark_ineligible() in ext4_quota_write()
tracks quota inode
- [Medium] ext4: stale ineligible_on_entry in ext4_fc_commit() forces
full commit
- [Low] ext4: missing EXT4_FC_REASON_QUOTA in ext4_fc_stats tracepoint
TP_printk()
- [Low] ext4: unnecessary s_fc_lock acquisition on entry to
ext4_fc_commit()
--
commit 27f3c8498a2c6f9057fcdc7d749d8315055f56a8
Author: Wesley Atwell <atwellwea@gmail.com>
ext4: force a full commit when quota data is modified
This commit marks the active transaction ineligible for fast commit when
ext4_quota_write() modifies a quota block, and updates ext4_fc_commit()
and ext4_fc_perform_commit() to fall back to a full commit when quota
updates race with an ongoing fast commit.
> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index 9beb423b208f8..5e7c9b4b0c2b1 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
[ ... ]
> @@ -1588,10 +1599,11 @@ 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 subtid, alloc_ctx;
> int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0;
> ktime_t start_time, commit_time;
> int old_ioprio, journal_ioprio;
> + bool ineligible_on_entry;
>
> if (!test_opt2(sb, JOURNAL_FAST_COMMIT))
> return jbd2_complete_transaction(journal, commit_tid);
> @@ -1601,6 +1613,12 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
> start_time = ktime_get();
> old_ioprio = get_current_ioprio();
>
> + /* Keep ineligibility observed before waiting for another fast commit. */
> + alloc_ctx = ext4_fc_lock(sb);
> + ineligible_on_entry = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
> + subtid = atomic_read(&sbi->s_fc_subtid);
> + ext4_fc_unlock(sb, alloc_ctx);
[Severity: Low]
Is taking sbi->s_fc_lock on entry to ext4_fc_commit() needed here?
EXT4_MF_FC_INELIGIBLE is an atomic bit in sbi->s_mount_flags, and
s_fc_subtid is incremented outside sbi->s_fc_lock via atomic_inc(), so
ext4_fc_lock() does not serialize the two reads against s_fc_subtid
updates. Acquiring sbi->s_fc_lock unconditionally before
jbd2_fc_begin_commit() also blocks callers whose commit_tid is already
committed behind any thread holding sbi->s_fc_lock during fast-commit log
writing in ext4_fc_perform_commit().
> +
> restart_fc:
> ret = jbd2_fc_begin_commit(journal, commit_tid);
> if (ret == -EALREADY) {
> @@ -1608,6 +1626,13 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
> if (atomic_read(&sbi->s_fc_subtid) <= subtid &&
> tid_gt(commit_tid, journal->j_commit_sequence))
> goto restart_fc;
> + if (tid_gt(commit_tid, journal->j_commit_sequence) &&
> + (ineligible_on_entry ||
> + ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE))) {
> + ext4_fc_update_stats(sb, EXT4_FC_STATUS_INELIGIBLE,
> + 0, 0, commit_tid);
> + return jbd2_complete_transaction(journal, commit_tid);
> + }
[Severity: High]
Can a waiting fsync() caller still miss EXT4_MF_FC_INELIGIBLE and return
0 before commit_tid is committed?
When a fast commit falls back to a full commit,
jbd2_fc_end_commit_fallback() runs __jbd2_fc_end_commit(journal, tid,
true), which invokes ext4_fc_cleanup(journal, 0, tid) and wakes j_fc_wait
before calling jbd2_complete_transaction(journal, tid). In
ext4_fc_cleanup(), clearing EXT4_MF_FC_INELIGIBLE is not gated on full:
fs/ext4/fast_commit.c:ext4_fc_cleanup() {
...
if (tid_geq(tid, sbi->s_fc_ineligible_tid)) {
sbi->s_fc_ineligible_tid = 0;
ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
}
...
}
If a third thread falls back to a full commit after an earlier fast
commit has already incremented s_fc_subtid, a waiter on j_fc_wait can see
both ineligible_on_entry and EXT4_MF_FC_INELIGIBLE as false:
CPU0 CPU1 CPU2
ext4_fc_commit(T)
jbd2_fc_begin_commit(T)
...
unlock_updates()
ext4_fc_commit(T)
ineligible_on_entry = 0
subtid = S
jbd2_fc_begin_commit(T)
/* sleeps on j_fc_wait */
ext4_quota_write()
ext4_fc_mark_ineligible()
ext4_fc_commit(T)
/* sleeps on j_fc_wait */
atomic_inc(s_fc_subtid)
jbd2_fc_end_commit()
wake_up(j_fc_wait)
jbd2_fc_begin_commit(T) == 0
/* sees FC_INELIGIBLE */
jbd2_fc_end_commit_fallback()
ext4_fc_cleanup(0, T)
clear(FC_INELIGIBLE)
wake_up(j_fc_wait)
/* wakes with -EALREADY */
s_fc_subtid > S
ineligible_on_entry == 0
test(FC_INELIGIBLE) == 0
return 0; <-- T uncommitted
jbd2_complete_transaction(T)
CPU2 then returns from fsync() with EXT4_FC_STATUS_SKIPPED before the
full commit of transaction T completes. Only clearing
EXT4_MF_FC_INELIGIBLE in ext4_fc_cleanup() when full is true avoids
dropping the flag before transaction T has committed.
[Severity: Medium]
Can a stale ineligible_on_entry from a previous committing transaction
force a redundant full commit on a newly fast-committed transaction?
While an ineligible transaction T is undergoing a full commit,
JBD2_FULL_COMMIT_ONGOING and EXT4_MF_FC_INELIGIBLE remain set until the
end of jbd2_journal_commit_transaction(), whereas updates for transaction
T + 1 can start once T leaves T_LOCKED. If two threads call
ext4_fc_commit(journal, T + 1) while T is still committing, both capture
ineligible_on_entry = true (from T) and subtid = S, then sleep in
jbd2_fc_begin_commit() on j_fc_wait.
When T finishes its full commit, ext4_fc_cleanup(journal, 1, T) clears
EXT4_MF_FC_INELIGIBLE and wakes both threads. Both see s_fc_subtid <= S
and jump to restart_fc without refreshing ineligible_on_entry. The first
thread wins jbd2_fc_begin_commit(journal, T + 1), sees
EXT4_MF_FC_INELIGIBLE is now clear, fast-commits T + 1, and increments
s_fc_subtid to S + 1. The second thread then wakes from
jbd2_fc_begin_commit() with -EALREADY, sees s_fc_subtid > S and
ineligible_on_entry == true, and calls jbd2_complete_transaction(journal,
T + 1) on a transaction that was just fast-committed.
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 880f664d6c04b..8f3c1de720be3 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -7560,6 +7560,8 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
> memcpy(bh->b_data+offset, data, len);
> flush_dcache_folio(bh->b_folio);
> unlock_buffer(bh);
> + /* Fast commit does not track quota file updates. */
> + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_QUOTA, handle);
> err = ext4_handle_dirty_metadata(handle, NULL, bh);
> brelse(bh);
> out:
[Severity: Medium]
Should ext4_fc_mark_ineligible() be called before ext4_bread() in
ext4_quota_write()?
Earlier in ext4_quota_write(), ext4_bread(handle, inode, blk,
EXT4_GET_BLOCKS_CREATE | EXT4_GET_BLOCKS_METADATA_NOFAIL) can allocate a
new block for the quota inode while the transaction is still eligible.
Inside ext4_map_blocks(), ext4_fc_track_inode(handle, inode) runs before
ext4_map_create_blocks() and queues the quota inode onto sbi->s_fc_q. If
ext4_bread() or ext4_journal_get_write_access() then returns an error,
ext4_quota_write() returns before reaching ext4_fc_mark_ineligible(),
leaving the transaction fast-commit eligible with the special quota inode
queued on sbi->s_fc_q. A later fast commit will write an
EXT4_FC_TAG_INODE tag for that quota inode, which fails recovery replay in
ext4_fc_replay_inode() because ext4_iget(sb, ino, EXT4_IGET_NORMAL)
rejects special quota inodes with -EFSCORRUPTED.
> diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
> index 92048da9dae43..56edde70dbac1 100644
> --- a/include/trace/events/ext4.h
> +++ b/include/trace/events/ext4.h
> @@ -105,6 +105,7 @@ TRACE_DEFINE_ENUM(EXT4_FC_REASON_ENCRYPTED_FILENAME);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_MIGRATE);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_VERITY);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_MOVE_EXT);
> +TRACE_DEFINE_ENUM(EXT4_FC_REASON_QUOTA);
> TRACE_DEFINE_ENUM(EXT4_FC_REASON_MAX);
>
> #undef EM
> @@ -141,7 +142,8 @@ TRACE_SNAP_ERR
> { EXT4_FC_REASON_ENCRYPTED_FILENAME, "ENCRYPTED_FILENAME"}, \
> { EXT4_FC_REASON_MIGRATE, "MIGRATE"}, \
> { EXT4_FC_REASON_VERITY, "VERITY"}, \
> - { EXT4_FC_REASON_MOVE_EXT, "MOVE_EXT"})
> + { EXT4_FC_REASON_MOVE_EXT, "MOVE_EXT"}, \
> + { EXT4_FC_REASON_QUOTA, "QUOTA"})
[Severity: Low]
show_fc_reason() is only used by FC_REASON_NAME_STAT() in
TRACE_EVENT(ext4_fc_stats), whose TP_printk() format string and argument
list stop at EXT4_FC_REASON_ENCRYPTED_FILENAME and were not updated to
include FC_REASON_NAME_STAT(EXT4_FC_REASON_QUOTA). As a result, the
EXT4_FC_REASON_QUOTA entry in show_fc_reason() is unused and never
appears in the ext4_fc_stats trace output.
--
Sashiko AI review · https://sashiko.dev/#/patchset/kernel-7f509bcdfe16388c-v1.atwellwea@gmail.com?part=1
prev parent reply other threads:[~2026-11-28 21:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 21:19 [PATCH] ext4: force a full commit when quota data is modified Wesley Atwell
2026-11-28 21:45 ` sashiko-bot [this message]
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=sashiko-outbox-239048@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=atwellwea@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/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