Re: [PATCH v2 06/10] btrfs: zoned: reserve zones for an active metadata/system block group

Naohiro Aota
2023-08-02T04:50:53Z

On Tue, Aug 01, 2023 at 02:17:15AM +0900, Naohiro Aota wrote:
> Ensure a metadata and system block group can be activated on write time, by
> leaving a certain number of active zones when trying to activate a data
> block group.
>
> When both metadata and system profiles are set to SINGLE, we need to
> reserve two zones. When both are DUP, we need to reserve four zones.
>
> In the case only one of them is DUP, we should reserve three zones.
> However, handling the case requires at least two bits to track if we have
> seen DUP profile for metadata and system, which is cumbersome. So, just
> reserve four zones in that case for now.
>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

I noticed this over-reserves the zones. Even when there are already
metadata and system block group allocated, it still leaves 2 (or 4 in
DUP) zones to be claimed by a data block group.

The reservation count must be increased when we free a metadata block group
and increased when we allocate one.

Or, in fact, we only need to reserve the zones when pivoting the block
group. With the zoned_meta_io_lock, metadata and system block group won't
pivot at the same time. So, adding a bit BTRFS_*_ZONED_PIVOT_META_BG would
be enough.

Anyway, I'll rework this patch.