Skip to contentSkip to conversation

btrfs: zoned: don't skip bgs with 100% zone unusable

PATCH In review Johannes Thumshirn 2 participants 2 messages Mar 18, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: zoned: don't skip bgs with 100% zone unusable

From: Johannes Thumshirn <[email protected]>

Commit f4a9f219411f ("btrfs: do not delete unused block group if it may be used soon") changed the behaviour of deleting unused block-groups on zoned filesystems. Starting with this commit, we're using btrfs_space_info_used() to calculate the number of used bytes in a space_info. But btrfs_space_info_used() also accounts btrfs_space_info::bytes_zone_unusable as used bytes.

So if a block group is 100% zone_unusable it is skipped from the deletion step.

In order not to skip fully zone_unusable block-groups, also check if the block-group has bytes left that can be used on a zoned filesystem.

Fixes f4a9f219411f ("btrfs: do not delete unused block group if it may be used soon")
---
 fs/btrfs/block-group.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/block-group.c +2 -1
index 5f7587ca1ca7..1e09aeea69c2 100644
@@ -1559,7 +1559,8 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 		 * needing to allocate extents from the block group.
 		 */
 		used = btrfs_space_info_used(space_info, true);
-		if (space_info->total_bytes - block_group->length < used) {
+		if (space_info->total_bytes - block_group->length < used &&
+		    block_group->zone_unusable < block_group->length) {
 			/*
 			 * Add a reference for the list, compensate for the ref
 			 * drop under the "next" label for the
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

Commit f4a9f219411f ("btrfs: do not delete unused block group if it may be used soon") changed the behaviour of deleting unused block-groups on zoned filesystems. Starting with this commit, we're using btrfs_space_info_used() to calculate the number of used bytes in a space_info. But btrfs_space_info_used() also accounts btrfs_space_info::bytes_zone_unusable as used bytes.

Quoted 8 lines

So if a block group is 100% zone_unusable it is skipped from the deletion step.

In order not to skip fully zone_unusable block-groups, also check if the block-group has bytes left that can be used on a zoned filesystem.

Fixes f4a9f219411f ("btrfs: do not delete unused block group if it may be used soon")

Looks good, thanks.

Quoted 22 lines
---
 fs/btrfs/block-group.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/block-group.c +2 -2
index 5f7587ca1ca7..1e09aeea69c2 100644
@@ -1559,7 +1559,8 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
                 * needing to allocate extents from the block group.
                 */
                used = btrfs_space_info_used(space_info, true);
-               if (space_info->total_bytes - block_group->length < used) {
+               if (space_info->total_bytes - block_group->length < used &&
+                   block_group->zone_unusable < block_group->length) {
                        /*
                         * Add a reference for the list, compensate for the ref
                         * drop under the "next" label for the
--

2.35.3