]> 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:06:49 +0000 (21:06 -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 8bd52a31e1a08d64cc7224b736620915fd811f3e..2a0e481953ebe781141b42c899edcdebdc2fc857 100644 (file)
@@ -129,6 +129,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 36db4c227f897e8d447cdf9c7243ff68b46a05e7..461edef9e906cb68bf054eb03cf7af160b526118 100644 (file)
@@ -2150,6 +2150,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 1cd461eb62d4badce38579a5cd4ded99e6b64313..1d2fe73dd17fd54afd7a0da2c6d3ad750f1ac4f0 100644 (file)
@@ -195,6 +195,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 */
@@ -5637,7 +5638,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 f004ab4341537f92a8bfb9ddaea04799a41cb3a7..c32a3be41dc909c58c265ffcbd17a12d1c69cbfd 100644 (file)
@@ -595,6 +595,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 */