Skip to content

Commit b9fd2af

Browse files
naotakdave
authored andcommitted
btrfs: zoned: fix initial free space detection
When creating a new block group, it calls btrfs_add_new_free_space() to add the entire block group range into the free space accounting. __btrfs_add_free_space_zoned() checks if size == block_group->length to detect the initial free space adding, and proceed that case properly. However, if the zone_capacity == zone_size and the over-write speed is fast enough, the entire zone can be over-written within one transaction. That confuses __btrfs_add_free_space_zoned() to handle it as an initial free space accounting. As a result, that block group becomes a strange state: 0 used bytes, 0 zone_unusable bytes, but alloc_offset == zone_capacity (no allocation anymore). The initial free space accounting can properly be checked by checking alloc_offset too. Fixes: 9817325 ("btrfs: zoned: calculate free space from zone capacity") CC: [email protected] # 6.1+ Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d182575 commit b9fd2af

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/free-space-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
26972697
u64 offset = bytenr - block_group->start;
26982698
u64 to_free, to_unusable;
26992699
int bg_reclaim_threshold = 0;
2700-
bool initial = (size == block_group->length);
2700+
bool initial = ((size == block_group->length) && (block_group->alloc_offset == 0));
27012701
u64 reclaimable_unusable;
27022702

27032703
WARN_ON(!initial && offset + size > block_group->zone_capacity);

0 commit comments

Comments
 (0)