* [PATCH v2] btrfs: zoned: don't wait for ordered extents in do_zone_finish()
@ 2026-10-27 14:33 Johannes Thumshirn
2026-10-27 15:18 ` Naohiro Aota
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Thumshirn @ 2026-10-27 14:33 UTC (permalink / raw)
To: linux-btrfs; +Cc: Naohiro Aota, David Sterba, Johannes Thumshirn
In general, we want to ensure all writes in the block group to
complete before finishing the zone, as relocation does. However, the
current callers do not need the wait (or cannot wait) in do_zone_finish():
- Relocation already waits for reservations and ordered extents itself
before calling btrfs_zone_finish().
- btrfs_delete_unused_bgs() checks that ->reserved is zero and sets the
block group read-only while holding groups_sem, so there can be no
in-flight data write.
- btrfs_zone_finish_one_bg() is called from the allocation path and
cannot wait.
Dropping the wait is still safe. Once the block group is read-only,
->reserved can only drop, and for data it only drops after the ordered
extent's I/O has completed. So if ->reserved is zero, no data write is
left in flight. If it is non-zero, do_zone_finish() returns -EAGAIN,
which all callers handle.
This makes btrfs_zone_finish_one_bg() fail with -EAGAIN when it races
with an allocation in the selected block group.
Fixes: 393f646e34c1 ("btrfs: zoned: finish least available block group on data bg allocation")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
Changes to v1:
- Reword changelog to undermine why this is safe (Naohiro)
fs/btrfs/zoned.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 1fa855a0c31a..35b422a53e2a 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2604,9 +2604,10 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
/* Ensure all writes in this block group finish */
btrfs_wait_block_group_reservations(block_group);
- /* No need to wait for NOCOW writers. Zoned mode does not allow that */
- btrfs_wait_ordered_roots(fs_info, U64_MAX, block_group);
- /* Wait for extent buffers to be written. */
+ /*
+ * No need to wait for NOCOW writers, as zoned mode does not
+ * allow that, only wait for extent buffers to be written.
+ */
if (is_metadata)
wait_eb_writebacks(block_group);
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] btrfs: zoned: don't wait for ordered extents in do_zone_finish()
2026-10-27 14:33 [PATCH v2] btrfs: zoned: don't wait for ordered extents in do_zone_finish() Johannes Thumshirn
@ 2026-10-27 15:18 ` Naohiro Aota
2026-10-28 6:18 ` Johannes Thumshirn
0 siblings, 1 reply; 3+ messages in thread
From: Naohiro Aota @ 2026-10-27 15:18 UTC (permalink / raw)
To: Johannes Thumshirn, linux-btrfs; +Cc: Naohiro Aota, David Sterba
On Tue Oct 27, 2026 at 11:33 PM JST, Johannes Thumshirn wrote:
> In general, we want to ensure all writes in the block group to
> complete before finishing the zone, as relocation does. However, the
> current callers do not need the wait (or cannot wait) in do_zone_finish():
>
> - Relocation already waits for reservations and ordered extents itself
> before calling btrfs_zone_finish().
> - btrfs_delete_unused_bgs() checks that ->reserved is zero and sets the
> block group read-only while holding groups_sem, so there can be no
> in-flight data write.
> - btrfs_zone_finish_one_bg() is called from the allocation path and
> cannot wait.
>
> Dropping the wait is still safe. Once the block group is read-only,
> ->reserved can only drop, and for data it only drops after the ordered
> extent's I/O has completed. So if ->reserved is zero, no data write is
> left in flight. If it is non-zero, do_zone_finish() returns -EAGAIN,
> which all callers handle.
>
> This makes btrfs_zone_finish_one_bg() fail with -EAGAIN when it races
> with an allocation in the selected block group.
Oops, I meant to keep the pragraph mentioning the deadlock and the call
chain. I think we can get that part back on the commit.
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
>
> Fixes: 393f646e34c1 ("btrfs: zoned: finish least available block group on data bg allocation")
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> Changes to v1:
> - Reword changelog to undermine why this is safe (Naohiro)
>
> fs/btrfs/zoned.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 1fa855a0c31a..35b422a53e2a 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -2604,9 +2604,10 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
>
> /* Ensure all writes in this block group finish */
> btrfs_wait_block_group_reservations(block_group);
> - /* No need to wait for NOCOW writers. Zoned mode does not allow that */
> - btrfs_wait_ordered_roots(fs_info, U64_MAX, block_group);
> - /* Wait for extent buffers to be written. */
> + /*
> + * No need to wait for NOCOW writers, as zoned mode does not
> + * allow that, only wait for extent buffers to be written.
> + */
> if (is_metadata)
> wait_eb_writebacks(block_group);
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] btrfs: zoned: don't wait for ordered extents in do_zone_finish()
2026-10-27 15:18 ` Naohiro Aota
@ 2026-10-28 6:18 ` Johannes Thumshirn
0 siblings, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2026-10-28 6:18 UTC (permalink / raw)
To: Naohiro Aota, linux-btrfs; +Cc: David Sterba
On 10/27/26 4:18 PM, Naohiro Aota wrote:
> On Tue Oct 27, 2026 at 11:33 PM JST, Johannes Thumshirn wrote:
>> In general, we want to ensure all writes in the block group to
>> complete before finishing the zone, as relocation does. However, the
>> current callers do not need the wait (or cannot wait) in do_zone_finish():
>>
>> - Relocation already waits for reservations and ordered extents itself
>> before calling btrfs_zone_finish().
>> - btrfs_delete_unused_bgs() checks that ->reserved is zero and sets the
>> block group read-only while holding groups_sem, so there can be no
>> in-flight data write.
>> - btrfs_zone_finish_one_bg() is called from the allocation path and
>> cannot wait.
>>
>> Dropping the wait is still safe. Once the block group is read-only,
>> ->reserved can only drop, and for data it only drops after the ordered
>> extent's I/O has completed. So if ->reserved is zero, no data write is
>> left in flight. If it is non-zero, do_zone_finish() returns -EAGAIN,
>> which all callers handle.
>>
>> This makes btrfs_zone_finish_one_bg() fail with -EAGAIN when it races
>> with an allocation in the selected block group.
> Oops, I meant to keep the pragraph mentioning the deadlock and the call
> chain. I think we can get that part back on the commit.
OK will do that when committing.
>
> Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-28 6:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 14:33 [PATCH v2] btrfs: zoned: don't wait for ordered extents in do_zone_finish() Johannes Thumshirn
2026-10-27 15:18 ` Naohiro Aota
2026-10-28 6:18 ` Johannes Thumshirn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox