From: Muhammad Umer <mumer.mobi@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.com, mason@kernel.org, fdmanana@suse.com,
wqu@suse.com, Muhammad Umer <mumer.mobi@gmail.com>
Subject: [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit
Date: Sat, 28 Nov 2026 16:04:07 -0500 [thread overview]
Message-ID: <20261128210407.26387-1-mumer.mobi@gmail.com> (raw)
Commit 4ef2c403d24c ("btrfs: increment extent count once when logging
extents during fast fsync") dropped the second increment of num and
halved the limit to 16K. That keeps the limit for extent maps that get
logged, but the remaining increment happens before the generation check,
so extent maps from past transactions, which are skipped, now count
against a limit half the size.
Those extent maps stay on modified_extents until the next fsync, so a
file with more than 16K extent maps written since its last fsync, in
previous transactions, now gets -EFBIG and a full transaction commit on
fsync. Before that commit the same happened only above 32K.
Move the check after the skips, so only extent maps we are going to log
count.
Reproducer: write a file densely and fsync it, overwrite N 4K blocks at
an 8K stride, sync, then overwrite one block and fsync. Transaction
commits during the last fsync:
N v6.18 v7.4-rc3 v7.4-rc3 + this patch
15000 0 0 0
18000 0 1 0
31000 0 1 0
34000 1 1 0
Fixes: 4ef2c403d24c ("btrfs: increment extent count once when logging extents during fast fsync")
Signed-off-by: Muhammad Umer <mumer.mobi@gmail.com>
---
Also tested on 7.2.15 with 4ef2c403d24c backported: commits during the
final fsync were 0/0/1/1/1/1 for N = 8000, 15000, 18000, 25000, 31000,
34000 without this patch, and 0 at every size with it.
With this patch extent maps from past transactions don't count at all,
so N = 34000 no longer commits either (v6.18 did). Happy to keep them
counted against the old 32K limit instead if that is preferred.
Reproducer: https://github.com/mumer2834/btrfs-fsync-efbig-repro
fs/btrfs/tree-log.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 62d94d1a0..f69d25692 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -5344,11 +5344,21 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
list_for_each_entry_safe(em, n, &tree->modified_extents, list) {
list_del_init(&em->list);
+
+ if (em->generation < trans->transid)
+ continue;
+
+ /* We log prealloc extents beyond eof later. */
+ if ((em->flags & EXTENT_FLAG_PREALLOC) &&
+ em->start >= i_size_read(&inode->vfs_inode))
+ continue;
+
/*
* Just an arbitrary number, this can be really CPU intensive
* once we start getting a lot of extents, and really once we
* have a bunch of extents we just want to commit since it will
- * be faster.
+ * be faster. Only count extents we are going to log, extent
+ * maps from past transactions are skipped above at no cost.
*/
if (++num > SZ_16K) {
list_del_init(&tree->modified_extents);
@@ -5356,14 +5366,6 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
goto process;
}
- if (em->generation < trans->transid)
- continue;
-
- /* We log prealloc extents beyond eof later. */
- if ((em->flags & EXTENT_FLAG_PREALLOC) &&
- em->start >= i_size_read(&inode->vfs_inode))
- continue;
-
/* Need a ref to keep it from getting evicted from cache */
refcount_inc(&em->refs);
em->flags |= EXTENT_FLAG_LOGGING;
--
2.53.0
next reply other threads:[~2026-11-28 21:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 21:04 Muhammad Umer [this message]
2026-11-28 21:25 ` [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit Qu Wenruo
2026-11-29 12:45 ` Filipe Manana
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=20261128210407.26387-1-mumer.mobi@gmail.com \
--to=mumer.mobi@gmail.com \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=mason@kernel.org \
--cc=wqu@suse.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