]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: zoned: refine extent allocator hint selection
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 16 Jul 2025 02:13:15 +0000 (11:13 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 2 Nov 2025 13:14:40 +0000 (22:14 +0900)
[ Upstream commit 0d703963d297964451783e1a0688ebdf74cd6151 ]

The hint block group selection in the extent allocator is wrong in the
first place, as it can select the dedicated data relocation block group for
the normal data allocation.

Since we separated the normal data space_info and the data relocation
space_info, we can easily identify a block group is for data relocation or
not. Do not choose it for the normal data allocation.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/extent-tree.c

index 8248113eb067faa910e4cc39ea622c0f0932657a..5e3d1a87b7e9da4755e196b9bf8dfd0d7910bb05 100644 (file)
@@ -4175,7 +4175,8 @@ static int prepare_allocation_clustered(struct btrfs_fs_info *fs_info,
 }
 
 static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
-                                   struct find_free_extent_ctl *ffe_ctl)
+                                   struct find_free_extent_ctl *ffe_ctl,
+                                   struct btrfs_space_info *space_info)
 {
        if (ffe_ctl->for_treelog) {
                spin_lock(&fs_info->treelog_bg_lock);
@@ -4199,6 +4200,7 @@ static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
                        u64 avail = block_group->zone_capacity - block_group->alloc_offset;
 
                        if (block_group_bits(block_group, ffe_ctl->flags) &&
+                           block_group->space_info == space_info &&
                            avail >= ffe_ctl->num_bytes) {
                                ffe_ctl->hint_byte = block_group->start;
                                break;
@@ -4220,7 +4222,7 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info,
                return prepare_allocation_clustered(fs_info, ffe_ctl,
                                                    space_info, ins);
        case BTRFS_EXTENT_ALLOC_ZONED:
-               return prepare_allocation_zoned(fs_info, ffe_ctl);
+               return prepare_allocation_zoned(fs_info, ffe_ctl, space_info);
        default:
                BUG();
        }