From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: Dongjiang Zhu <zhudongjiang@fygo.io>
Cc: linux-btrfs@vger.kernel.org, naohiro.aota@wdc.com
Subject: Re: [PATCH 4/4] btrfs: zoned: serialize zone finishing per block group
Date: Mon, 24 Aug 2026 18:00:45 +0200 [thread overview]
Message-ID: <aoxpGiMYRNdRX0wA@mayhem.fritz.box> (raw)
In-Reply-To: <388e4a6778d65d6d08c7f921c629d4645bac9959.1787551793.git.zhudongjiang@fygo.io>
On Mon, Aug 24, 2026 at 02:49:56PM +0800, Dongjiang Zhu wrote:
> [BUG]
> On an HC620 with max_active_zones=128, buffered writes occupied all 128
> active-zone slots. A metadata-heavy create/delete workload followed by
> sync then forced a metadata block group switch.
Can you explain that to me. In my mental model, if all 128 active-zones are
used and you call sync, we need to add a treelog-bg. But there is no more
active zone resource available so we cannot create the treelog bg. This is why
we fail, so we need to finish a zone first to then create a treelog bg.
>
> A kernel with additional zone finish tracing reported:
>
> zoned-debug: finish clear-runtime bg=140928614400 caller=btrfs_zone_finish_endio_workfn comm=kworker/u8:7
> zoned-debug: finish early-inactive bg=140928614400 caller=btrfs_check_meta_write_pointer comm=sync
> zoned-debug: pivot finish ret=0 old_bg=140928614400 new_bg=339839287296
> zoned-debug: activate fail slot bg=339839287296 type=metadata left=0 max_active=128 comm=sync
> zoned-debug: finish zone-mgmt bg=140928614400 ret=0 left=0 caller=btrfs_zone_finish_endio_workfn comm=kworker/u8:7
> BTRFS error (device sdb): error while writing out transaction: -EAGAIN
> BTRFS error (device sdb state A): Transaction 67 aborted (-EAGAIN)
> BTRFS info (device sdb state EA): forced readonly
> zoned-debug: clear-active dev=/dev/sdb pos=140928614400 left=1 max_active=128
>
> The transaction was aborted before the old block group returned its
> active-zone slot, forcing the filesystem read-only.
Ah now I see we're on the same page.
>
> [CAUSE]
> do_zone_finish() clears BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE before issuing
> the zone finish operation. This allows the following interleaving:
>
> Thread A, endio worker Thread B, transaction writeback
>
> clear ZONE_IS_ACTIVE
> call_zone_finish(old)
> observe old as inactive
> return from do_zone_finish(old)
> activate(new)
> fail with left == 0
> clear the device active bit
> increment active_zones_left
>
> Thread B treats the cleared active bit as a completed finish while thread
> A is still performing the device operation.
>
> [FIX]
> Add BLOCK_GROUP_FLAG_ZONE_FINISHING and keep ZONE_IS_ACTIVE set until the
> zone finish operation and active-list cleanup are complete.
>
> Concurrent finishers wait for ZONE_FINISHING to be cleared instead of
> returning early. Wake them after clearing ZONE_IS_ACTIVE and removing
> the block group from the active list. If a waiter acquired a temporary
> read-only reference, release it after the wait.
>
Stupid question, wouldn't it be enough to re-order the call to
do_zone_finish() vs the clearing of BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE?
next prev parent reply other threads:[~2026-08-24 16:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 6:49 [PATCH 0/4] btrfs: zoned: fix active-zone accounting and transitions Dongjiang Zhu
2026-08-24 6:49 ` [PATCH 1/4] btrfs: zoned: track only sequential zones as active Dongjiang Zhu
2026-08-24 13:55 ` Johannes Thumshirn
2026-08-24 22:40 ` Qu Wenruo
2026-08-25 9:10 ` Johannes Thumshirn
2026-08-25 3:01 ` Dongjiang Zhu
2026-08-24 6:49 ` [PATCH 2/4] btrfs: zoned: recover active non-data block group roles on mount Dongjiang Zhu
2026-08-24 14:42 ` Johannes Thumshirn
2026-08-25 3:08 ` Dongjiang Zhu
2026-08-25 10:02 ` Johannes Thumshirn
2026-08-24 6:49 ` [PATCH 3/4] btrfs: zoned: remove obsolete non-data block group activation helper Dongjiang Zhu
2026-08-24 15:51 ` Johannes Thumshirn
2026-08-24 6:49 ` [PATCH 4/4] btrfs: zoned: serialize zone finishing per block group Dongjiang Zhu
2026-08-24 16:00 ` Johannes Thumshirn [this message]
2026-08-25 3:16 ` Dongjiang Zhu
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=aoxpGiMYRNdRX0wA@mayhem.fritz.box \
--to=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
--cc=zhudongjiang@fygo.io \
/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