]> git.hungrycats.org Git - linux/commitdiff
btrfs: add allocator_hint for no allocation preferred
authorKai Krakow <kai@kaishome.de>
Fri, 10 Jul 2026 22:09:55 +0000 (00:09 +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 avoid new allocations of chunks on a
disk which is going to be removed from the pool anyways, e.g. due to
bad blocks or because it's slow.

The preference applies to non-mixed block groups. Mixed data and
metadata block groups intentionally ignore allocator hints.

v2:
- Clarify that mixed block groups are outside the allocator-hints
  scope.

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 0d62e844053179bc9e4bc0cca4d3c9f4275dd5ab..7c812924309cf21a0ebbea63760d085af29f02bf 100644 (file)
@@ -127,6 +127,9 @@ config BTRFS_ALLOCATOR_HINTS
                       chunks will ever be allocated from this device
          - type = 3 - allocate only data chunks from this ID, no meta data
                       chunks will ever be allocated from this device
+         - 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
 
          If unsure, say N.
 
index d22d563e6ead81975ccf63b74705415d72a89a31..0cc67225bf4ab00f47572b411efbc5095d29a7fc 100644 (file)
@@ -2110,6 +2110,7 @@ static bool btrfs_dev_allocation_hint_valid(u64 type)
        case BTRFS_DEV_ALLOCATION_PREFERRED_METADATA:
        case BTRFS_DEV_ALLOCATION_METADATA_ONLY:
        case BTRFS_DEV_ALLOCATION_DATA_ONLY:
+       case BTRFS_DEV_ALLOCATION_PREFERRED_NONE:
                return true;
        default:
                return false;
index 7986fb914bbc3e4612822328355999d0d4878907..1eee9cad877124844bb9114aa485518a6f5c29e4 100644 (file)
@@ -196,6 +196,7 @@ static const int alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
        [BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
        [BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
        [BTRFS_DEV_ALLOCATION_METADATA_ONLY] = 2,
+       [BTRFS_DEV_ALLOCATION_PREFERRED_NONE] = 99,
        /* the other values are set to 0 */
 };
 #endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
@@ -5973,7 +5974,10 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
                         * sort also by hint (metadata hint
                         * higher priority)
                         */
-                       devices_info[ndevs].alloc_hint = alloc_hint_map[hint];
+                       if (BTRFS_DEV_ALLOCATION_PREFERRED_NONE == hint)
+                               devices_info[ndevs].alloc_hint = -alloc_hint_map[hint];
+                       else
+                               devices_info[ndevs].alloc_hint = alloc_hint_map[hint];
                }
 #endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
 
index d48aa6112ef9279e06693f77893f73625f172cb2..7a940eb91dc680b82a079addee2fa58d20ff53dd 100644 (file)
@@ -602,6 +602,8 @@ struct btrfs_node {
 #define BTRFS_DEV_ALLOCATION_METADATA_ONLY     (2ULL)
 /* only data chunk allowed */
 #define BTRFS_DEV_ALLOCATION_DATA_ONLY         (3ULL)
+/* avoid chunk allocation if possible */
+#define BTRFS_DEV_ALLOCATION_PREFERRED_NONE    (4ULL)
 /* 5..7 are unused values */
 
 #endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */