]> git.hungrycats.org Git - linux/commitdiff
btrfs: add allocator_hint to disable allocation completely
authorKai Krakow <kai@kaishome.de>
Fri, 10 Jul 2026 21:51:46 +0000 (23:51 +0200)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 06:08:59 +0000 (01:08 -0500)
This is useful where you want to prevent new allocations of chunks to a
set of multiple disks which are going to be removed from the pool. This
acts as a multiple `btrfs dev remove` on steroids that can remove
multiple disks in parallel without moving data to disks which would be
removed in the next round. In such cases, it will avoid moving the same
data multiple times, and thus avoid placing it on potentially bad
disks.

The restriction applies to non-mixed block groups. Mixed data and
metadata block groups intentionally ignore allocator hints. Device
replace does not copy the hint to the target device, so reapply it
after replacement.

v2:
- Clarify the mixed-block-group scope and device replace behavior.

Thanks to @Zygo for the explanation and suggestion.

Link: https://github.com/kdave/btrfs-progs/issues/907#issuecomment-2520897104
Signed-off-by: Kai Krakow <kai@kaishome.de>
fs/btrfs/Kconfig
fs/btrfs/sysfs.c
fs/btrfs/volumes.c
include/uapi/linux/btrfs_tree.h

index 7c812924309cf21a0ebbea63760d085af29f02bf..21b4694ce987807fb55c938a31b900edc75710fd 100644 (file)
@@ -130,6 +130,9 @@ config BTRFS_ALLOCATOR_HINTS
          - type = 4 - allocate any chunks from this device last, will never
                       allocate any space from this device unless there isn't
                       enough space on other devices
+         - type = 5 - never allocate any new non-mixed chunks, useful when
+                      putting a device out of use and to avoid redundant chunk
+                      writes during balance/replace
 
          If unsure, say N.
 
index 0cc67225bf4ab00f47572b411efbc5095d29a7fc..1c56220b86d93b3a9c9e2f5232f5db39cc02a4c9 100644 (file)
@@ -2111,6 +2111,7 @@ static bool btrfs_dev_allocation_hint_valid(u64 type)
        case BTRFS_DEV_ALLOCATION_METADATA_ONLY:
        case BTRFS_DEV_ALLOCATION_DATA_ONLY:
        case BTRFS_DEV_ALLOCATION_PREFERRED_NONE:
+       case BTRFS_DEV_ALLOCATION_NONE_ONLY:
                return true;
        default:
                return false;
index 1eee9cad877124844bb9114aa485518a6f5c29e4..0f25e0d7681371c0640ebf4647a915352771deee 100644 (file)
@@ -192,6 +192,7 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
                BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT)
 
 static const int alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
+       [BTRFS_DEV_ALLOCATION_NONE_ONLY] = -99,
        [BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
        [BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
        [BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
@@ -5955,6 +5956,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
                         */
                        if (BTRFS_DEV_ALLOCATION_METADATA_ONLY == hint)
                                continue;
+                       /*
+                        * skip BTRFS_DEV_NONE_ONLY disks
+                        */
+                       if (BTRFS_DEV_ALLOCATION_NONE_ONLY == hint)
+                               continue;
                        /*
                         * if a data chunk must be allocated,
                         * sort also by hint (data disk
@@ -5969,6 +5975,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
                         */
                        if (BTRFS_DEV_ALLOCATION_DATA_ONLY == hint)
                                continue;
+                       /*
+                        * skip BTRFS_DEV_NONE_ONLY disks
+                        */
+                       if (BTRFS_DEV_ALLOCATION_NONE_ONLY == hint)
+                               continue;
                        /*
                         * if a metadata chunk must be allocated,
                         * sort also by hint (metadata hint
index 7a940eb91dc680b82a079addee2fa58d20ff53dd..5f1d85b9ad747a4ef2ac0e6341b38d6178af089c 100644 (file)
@@ -604,7 +604,9 @@ struct btrfs_node {
 #define BTRFS_DEV_ALLOCATION_DATA_ONLY         (3ULL)
 /* avoid chunk allocation if possible */
 #define BTRFS_DEV_ALLOCATION_PREFERRED_NONE    (4ULL)
-/* 5..7 are unused values */
+/* deny chunk allocation */
+#define BTRFS_DEV_ALLOCATION_NONE_ONLY         (5ULL)
+/* 6..7 are unused values */
 
 #endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */