[PATCH v4 2/3] gpu/buddy: drop subtree_max_free_order
From: William Palacek
Date: Wed Nov 18 2026 - 15:17:42 EST
__alloc_range_bias() no longer walks the buddy tree, so nothing reads
subtree_max_free_order. Stop maintaining it on every allocation and
free, and restore the original order in gpu_buddy_block_trim(), where
the block was detached early only to keep that field consistent.
Cc: Matthew Auld <matthew.auld@xxxxxxxxx>
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@xxxxxxx>
Cc: Sanjay Yadav <sanjay.kumar.yadav@xxxxxxxxx>
Signed-off-by: William Palacek <William.Palacek@xxxxxxx>
---
Notes:
v4:
- new patch
drivers/gpu/buddy.c | 39 ++++-----------------------------------
include/linux/gpu_buddy.h | 7 -------
2 files changed, 4 insertions(+), 42 deletions(-)
diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
index 26af5428ff76..95f98830b787 100644
--- a/drivers/gpu/buddy.c
+++ b/drivers/gpu/buddy.c
@@ -602,7 +602,6 @@ static struct gpu_buddy_block *gpu_block_alloc(struct gpu_buddy *mm,
block->header = offset;
block->header |= order;
block->parent = parent;
- block->subtree_max_free_order = GPU_BUDDY_NO_FREE_ORDER;
RB_CLEAR_NODE(&block->rb);
@@ -783,27 +782,6 @@ static void rbtree_remove(struct gpu_buddy *mm,
RB_CLEAR_NODE(&block->rb);
}
-static void update_subtree_max_free_order(struct gpu_buddy_block *block)
-{
- while (block) {
- s8 max_free;
-
- if (gpu_buddy_block_is_free(block))
- max_free = gpu_buddy_block_order(block);
- else if (gpu_buddy_block_is_split(block))
- max_free = max(block->left->subtree_max_free_order,
- block->right->subtree_max_free_order);
- else
- max_free = GPU_BUDDY_NO_FREE_ORDER;
-
- if (block->subtree_max_free_order == max_free)
- break;
-
- block->subtree_max_free_order = max_free;
- block = block->parent;
- }
-}
-
static void mark_allocated(struct gpu_buddy *mm,
struct gpu_buddy_block *block)
{
@@ -816,7 +794,6 @@ static void mark_allocated(struct gpu_buddy *mm,
mm->used_scoreboard[gpu_buddy_block_order(block)]++;
rbtree_remove(mm, block);
- update_subtree_max_free_order(block);
}
static void __mark_free(struct gpu_buddy *mm,
@@ -838,7 +815,6 @@ static void __mark_free(struct gpu_buddy *mm,
mm->free_scoreboard[gpu_buddy_block_order(block)]++;
rbtree_insert(mm, block);
- update_subtree_max_free_order(block);
}
static void mark_free(struct gpu_buddy *mm,
@@ -958,8 +934,6 @@ int gpu_buddy_init(struct gpu_buddy *mm, u64 size, u64 chunk_size)
size = round_down(size, chunk_size);
- BUILD_BUG_ON(GPU_BUDDY_MAX_ORDER > S8_MAX);
-
mm->size = size;
mm->avail = size;
mm->chunk_size = chunk_size;
@@ -2025,17 +1999,13 @@ int gpu_buddy_block_trim(struct gpu_buddy *mm,
gpu_buddy_block_offset(block),
gpu_buddy_block_size(mm, block));
- /*
- * Detach the block to prevent recursively freeing this node, and to
- * keep free-order updates from propagating above it until the trim
- * is done.
- */
- parent = block->parent;
- block->parent = NULL;
-
__mark_free(mm, block, was_clear ? GPU_BLOCK_CLEAR : GPU_BLOCK_DIRTY);
mm->avail += gpu_buddy_block_size(mm, block);
+ /* Prevent recursively freeing this node */
+ parent = block->parent;
+ block->parent = NULL;
+
list_add(&block->tmp_link, &dfs);
err = __alloc_range(mm, &dfs, new_start, new_size,
was_clear ? GPU_BUDDY_CLEAR_ALLOCATION : 0,
@@ -2054,7 +2024,6 @@ int gpu_buddy_block_trim(struct gpu_buddy *mm,
}
block->parent = parent;
- update_subtree_max_free_order(parent);
return err;
}
EXPORT_SYMBOL(gpu_buddy_block_trim);
diff --git a/include/linux/gpu_buddy.h b/include/linux/gpu_buddy.h
index 8037f5a0feb1..ddc4eca84175 100644
--- a/include/linux/gpu_buddy.h
+++ b/include/linux/gpu_buddy.h
@@ -141,15 +141,8 @@ struct gpu_buddy_block {
unsigned int subtree_max_alignment;
struct list_head tmp_link;
bool has_clear;
- /*
- * Largest order of any FREE block in this block's buddy subtree, or
- * GPU_BUDDY_NO_FREE_ORDER if none. Protected by the driver lock.
- */
- s8 subtree_max_free_order;
};
-#define GPU_BUDDY_NO_FREE_ORDER (-1)
-
/* Order-zero must be at least SZ_4K */
#define GPU_BUDDY_MAX_ORDER (63 - 12)
--
2.43.0