]> 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>
Mon, 2 Nov 2026 02:17:16 +0000 (21:17 -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 e2b0e1cc28d0e13e0836eeefe32e7a217af2b5ad..2326ae14c10a75df296a8372ad690abfe1e7a02f 100644 (file)
@@ -128,6 +128,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 a3ccfe3dbcafc55b30628f69d07debef7b07ac94..931fd4b5a6559b78d4337ba2fa4656717042cb1d 100644 (file)
@@ -1995,6 +1995,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 7db28908203d1f31376685bccf88310750963c3e..14c17a38a77576cba1e931337c4f6147e02065e3 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 */
@@ -6024,7 +6025,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 a8da0a23b70a2e991e8c1181840ef39ba9c21929..3ad70980a53f17110e135dc176dd30f3d4bb2839 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 */