All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit
@ 2026-11-28 21:04 Muhammad Umer
  2026-11-28 21:25 ` Qu Wenruo
  2026-11-29 12:45 ` Filipe Manana
  0 siblings, 2 replies; 3+ messages in thread
From: Muhammad Umer @ 2026-11-28 21:04 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, mason, fdmanana, wqu, Muhammad Umer

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-29 12:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 21:04 [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit Muhammad Umer
2026-11-28 21:25 ` Qu Wenruo
2026-11-29 12:45 ` Filipe Manana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.