]> 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:06:49 +0000 (21:06 -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 2a0e481953ebe781141b42c899edcdebdc2fc857..71d7d4b12dc6e0253f0f59fb0a45917bbfc5c69d 100644 (file)
@@ -132,6 +132,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 461edef9e906cb68bf054eb03cf7af160b526118..ea8fcde5cde0e5370e35f123e2fe2d5a2d8e4d9e 100644 (file)
@@ -2151,6 +2151,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 1d2fe73dd17fd54afd7a0da2c6d3ad750f1ac4f0..eb63fdacb8be63ff16028ada1f27b24dfbe1a76e 100644 (file)
@@ -191,6 +191,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,
@@ -5619,6 +5620,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
@@ -5633,6 +5639,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 c32a3be41dc909c58c265ffcbd17a12d1c69cbfd..8a6087d6e967aa60010f4ebc3d2347525f86f8df 100644 (file)
@@ -597,7 +597,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 */