OSDN Git Service

btrfs: zoned: don't activate non-DATA BG on allocation
authorNaohiro Aota <naohiro.aota@wdc.com>
Mon, 7 Aug 2023 16:12:39 +0000 (01:12 +0900)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Aug 2023 12:52:19 +0000 (14:52 +0200)
Now that a non-DATA block group is activated at write time, don't
activate it on allocation time.

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>
fs/btrfs/block-group.c
fs/btrfs/extent-tree.c
fs/btrfs/space-info.c

index b0e432c..0cb1dee 100644 (file)
@@ -4089,7 +4089,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
 
        if (IS_ERR(ret_bg)) {
                ret = PTR_ERR(ret_bg);
-       } else if (from_extent_allocation) {
+       } else if (from_extent_allocation && (flags & BTRFS_BLOCK_GROUP_DATA)) {
                /*
                 * New block group is likely to be used soon. Try to activate
                 * it now. Failure is OK for now.
index 6dfe086..bc9ff19 100644 (file)
@@ -3690,7 +3690,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group,
        }
        spin_unlock(&block_group->lock);
 
-       if (!ret && !btrfs_zone_activate(block_group)) {
+       /* Metadata block group is activated at write time. */
+       if (!ret && (block_group->flags & BTRFS_BLOCK_GROUP_DATA) &&
+           !btrfs_zone_activate(block_group)) {
                ret = 1;
                /*
                 * May need to clear fs_info->{treelog,data_reloc}_bg.
@@ -3866,6 +3868,10 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl,
 static int can_allocate_chunk_zoned(struct btrfs_fs_info *fs_info,
                                    struct find_free_extent_ctl *ffe_ctl)
 {
+       /* Block group's activeness is not a requirement for METADATA block groups. */
+       if (!(ffe_ctl->flags & BTRFS_BLOCK_GROUP_DATA))
+               return 0;
+
        /* If we can activate new zone, just allocate a chunk and use it */
        if (btrfs_can_activate_zone(fs_info->fs_devices, ffe_ctl->flags))
                return 0;
index 17c86db..356638f 100644 (file)
@@ -761,18 +761,6 @@ static void flush_space(struct btrfs_fs_info *fs_info,
                break;
        case ALLOC_CHUNK:
        case ALLOC_CHUNK_FORCE:
-               /*
-                * For metadata space on zoned filesystem, reaching here means we
-                * don't have enough space left in active_total_bytes. Try to
-                * activate a block group first, because we may have inactive
-                * block group already allocated.
-                */
-               ret = btrfs_zoned_activate_one_bg(fs_info, space_info, false);
-               if (ret < 0)
-                       break;
-               else if (ret == 1)
-                       break;
-
                trans = btrfs_join_transaction(root);
                if (IS_ERR(trans)) {
                        ret = PTR_ERR(trans);
@@ -784,22 +772,6 @@ static void flush_space(struct btrfs_fs_info *fs_info,
                                        CHUNK_ALLOC_FORCE);
                btrfs_end_transaction(trans);
 
-               /*
-                * For metadata space on zoned filesystem, allocating a new chunk
-                * is not enough. We still need to activate the block * group.
-                * Active the newly allocated block group by (maybe) finishing
-                * a block group.
-                */
-               if (ret == 1) {
-                       ret = btrfs_zoned_activate_one_bg(fs_info, space_info, true);
-                       /*
-                        * Revert to the original ret regardless we could finish
-                        * one block group or not.
-                        */
-                       if (ret >= 0)
-                               ret = 1;
-               }
-
                if (ret > 0 || ret == -ENOSPC)
                        ret = 0;
                break;