Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: fix initial free space detection
@ 2024-06-11  9:05 Naohiro Aota
  2024-06-11 10:45 ` Johannes Thumshirn
  2024-06-12 19:51 ` David Sterba
  0 siblings, 2 replies; 6+ messages in thread
From: Naohiro Aota @ 2024-06-11  9:05 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Naohiro Aota

When creating a new block group, it calls btrfs_fadd_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.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Fixes: 98173255bddd ("btrfs: zoned: calculate free space from zone capacity")
CC: stable@vger.kernel.org # 6.1+
---
 fs/btrfs/free-space-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index fcfc1b62e762..72e60764d1ea 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -2697,7 +2697,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
 	u64 offset = bytenr - block_group->start;
 	u64 to_free, to_unusable;
 	int bg_reclaim_threshold = 0;
-	bool initial = (size == block_group->length);
+	bool initial = (size == block_group->length) && block_group->alloc_offset == 0;
 	u64 reclaimable_unusable;
 
 	WARN_ON(!initial && offset + size > block_group->zone_capacity);
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-13 15:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-11  9:05 [PATCH] btrfs: zoned: fix initial free space detection Naohiro Aota
2024-06-11 10:45 ` Johannes Thumshirn
2024-06-13  0:18   ` Naohiro Aota
2024-06-12 19:51 ` David Sterba
2024-06-13  0:18   ` Naohiro Aota
2024-06-13 15:09     ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox