]> 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>
Mon, 2 Nov 2026 02:17:17 +0000 (21:17 -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 2326ae14c10a75df296a8372ad690abfe1e7a02f..e14cddb83c8a3090c4e21b4c99aad35b6452a078 100644 (file)
@@ -131,6 +131,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 931fd4b5a6559b78d4337ba2fa4656717042cb1d..16912c8f4f9e6248639f62d0b39006ad594e4970 100644 (file)
@@ -1996,6 +1996,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 14c17a38a77576cba1e931337c4f6147e02065e3..c19183f8184c4a3a57badcd9152f15fb9bd64106 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,
@@ -6006,6 +6007,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
@@ -6020,6 +6026,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 3ad70980a53f17110e135dc176dd30f3d4bb2839..035b7385622bbc989795d8145fb02a2803e19f66 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 */