]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: zoned: add zone reclaim flush state for DATA space_info
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 10 Feb 2026 11:04:23 +0000 (12:04 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:55:55 +0000 (18:55 +0200)
commite2a7fd22378f6500bcf979edc71e6837271eacfd
tree47b46ff6eab5e98823d9e400bd0b7c86ae433907
parent258e46a6385c57a3caef3fb1dc888e2efcfe5b18
btrfs: zoned: add zone reclaim flush state for DATA space_info

On zoned block devices, DATA block groups can accumulate large amounts
of zone_unusable space (space between the write pointer and zone end).
When zone_unusable reaches high levels (e.g., 98% of total space), new
allocations fail with ENOSPC even though space could be reclaimed by
relocating data and resetting zones.

The existing flush states don't handle this scenario effectively - they
either try to free cached space (which doesn't exist for zone_unusable)
or reset empty zones (which doesn't help when zones contain valid data
mixed with zone_unusable space).

Add a new RECLAIM_ZONES flush state that triggers the block group
reclaim machinery. This state:
- Calls btrfs_reclaim_sweep() to identify reclaimable block groups
- Calls btrfs_reclaim_bgs() to queue reclaim work
- Waits for reclaim_bgs_work to complete via flush_work()
- Commits the transaction to finalize changes

The reclaim work (btrfs_reclaim_bgs_work) safely relocates valid data
from fragmented block groups to other locations before resetting zones,
converting zone_unusable space back into usable space.

Insert RECLAIM_ZONES before RESET_ZONES in data_flush_states so that
we attempt to reclaim partially-used block groups before falling back
to resetting completely empty ones.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/space-info.c
fs/btrfs/space-info.h