[PATCH v2 2/2] gpu/tests/buddy: add range-biased allocation performance test

From: William Palacek

Date: Mon Nov 09 2026 - 08:59:37 EST


Fill a 1 GiB range of a 4 GiB manager top-down with 64 KiB range-biased
allocations that request cleared memory, as amdgpu does for KFD VRAM on
NPS4 partitions, check that each one is placed directly below the
previous one, and report the time taken: 1190 ms with the full-range
walk, 3 ms with the free tree lookup.

Cc: Matthew Auld <matthew.auld@xxxxxxxxx>
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@xxxxxxx>
Signed-off-by: William Palacek <William.Palacek@xxxxxxx>
---
drivers/gpu/tests/gpu_buddy_test.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

diff --git a/drivers/gpu/tests/gpu_buddy_test.c b/drivers/gpu/tests/gpu_buddy_test.c
index 2c6f1da1a6d1c..ef4176b4baa39 100644
--- a/drivers/gpu/tests/gpu_buddy_test.c
+++ b/drivers/gpu/tests/gpu_buddy_test.c
@@ -283,6 +283,32 @@ static void gpu_test_buddy_fragmentation_performance(struct kunit *test)
gpu_buddy_fini(&mm);
}

+static void gpu_test_buddy_range_bias_performance(struct kunit *test)
+{
+ struct gpu_buddy_block *block;
+ LIST_HEAD(allocated);
+ struct gpu_buddy mm;
+ ktime_t t0;
+ u64 i;
+
+ /* Fill one NPS4-like quarter top-down with cleared 64 KiB allocations. */
+ KUNIT_ASSERT_FALSE(test, gpu_buddy_init(&mm, SZ_4G, SZ_4K));
+ t0 = ktime_get();
+ for (i = 1; i <= SZ_1G / SZ_64K; i++) {
+ KUNIT_ASSERT_FALSE(test, gpu_buddy_alloc_blocks(&mm, SZ_1G, SZ_2G, SZ_64K,
+ SZ_64K, &allocated,
+ GPU_BUDDY_RANGE_ALLOCATION |
+ GPU_BUDDY_CLEAR_ALLOCATION |
+ GPU_BUDDY_TOPDOWN_ALLOCATION));
+ block = list_last_entry(&allocated, struct gpu_buddy_block, link);
+ KUNIT_ASSERT_EQ(test, gpu_buddy_block_offset(block), SZ_2G - i * SZ_64K);
+ }
+ kunit_info(test, "Range-biased fill took %lld ms\n",
+ ktime_ms_delta(ktime_get(), t0));
+ gpu_buddy_free_list(&mm, &allocated, 0);
+ gpu_buddy_fini(&mm);
+}
+
static void gpu_test_buddy_dirty_tracker_performance(struct kunit *test)
{
struct gpu_buddy_block *block, *tmp;
@@ -1617,6 +1643,7 @@ static struct kunit_case gpu_buddy_tests[] = {
KUNIT_CASE(gpu_test_buddy_alloc_range_bias),
KUNIT_CASE_SLOW(gpu_test_buddy_fragmentation_performance),
KUNIT_CASE_SLOW(gpu_test_buddy_dirty_tracker_performance),
+ KUNIT_CASE_SLOW(gpu_test_buddy_range_bias_performance),
KUNIT_CASE(gpu_test_buddy_alloc_exceeds_max_order),
KUNIT_CASE(gpu_test_buddy_offset_aligned_allocation),
KUNIT_CASE(gpu_test_buddy_subtree_offset_alignment_stress),
--
2.43.0