* [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* Re: [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit
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
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2026-11-28 21:25 UTC (permalink / raw)
To: Muhammad Umer, linux-btrfs; +Cc: dsterba, mason, fdmanana, wqu
在 2026/11/29 07:34, 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.
That's all your commit message needs.
>
> 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
The remaining, including the things below the "---" line is unnecessary
LLM garbage, it doesn't contribute to the fix or anything.
>
> 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) {
It will be much simpler just remove the "++" part, and add a dedicated
num++ in the end, other than moving all those code around.
> 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;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit
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
1 sibling, 0 replies; 3+ messages in thread
From: Filipe Manana @ 2026-11-29 12:45 UTC (permalink / raw)
To: Muhammad Umer; +Cc: linux-btrfs, dsterba, mason, fdmanana, wqu
On Sat, Nov 28, 2026 at 9:04 PM Muhammad Umer <mumer.mobi@gmail.com> wrote:
>
> 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.
No we don't want that.
If there are many extent maps from past transactions, we spend a lot
of time processing them, which has several consequences:
1) We waste CPU time;
2) We hold the inode's extent map tree for too long, blocking concurrent reads.
3) We hold the log transaction for long, delaying concurrent fsyncs
trying to sync the log.
etc
That processing must be bounded.
>
> 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
We can always create a "reproducer" that results in transaction
commits, regardless of whether we use the old 32K limit, the new 16K
limit, or some other limit.
>
> Fixes: 4ef2c403d24c ("btrfs: increment extent count once when logging extents during fast fsync")
A Fixes tag is for functional issues or severe enough performance regressions.
What you are trying to "fix" here is avoiding a transaction commit for
a scenario that is very unlikely to happen in practice.
Did you observe an actual performance regression with a real workload
or did you just analyze this with an LLM/AI and decided it must be a
bug?
16K is a fairly large limit and unlikely to be hit in real workloads.
But if we hit this limit often enough in the real world, it would be
better to bump 16K to some higher value.
Falling back to a transaction commit for extreme scenarios is not
necessarily a bad thing.
> 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 [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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox