From: Matthew Auld <matthew.auld@intel.com>
To: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>,
christian.koenig@amd.com, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org
Cc: alexander.deucher@amd.com
Subject: Re: [PATCH v4 1/2] drm/buddy: Improve offset-aligned allocation handling
Date: Tue, 24 Feb 2026 17:35:15 +0000 [thread overview]
Message-ID: <76588674-affb-478e-8a4a-35e7cf94f58f@intel.com> (raw)
In-Reply-To: <20260217113900.10675-1-Arunpravin.PaneerSelvam@amd.com>
On 17/02/2026 11:38, Arunpravin Paneer Selvam wrote:
> Large alignment requests previously forced the buddy allocator to search by
> alignment order, which often caused higher-order free blocks to be split even
> when a suitably aligned smaller region already existed within them. This led
> to excessive fragmentation, especially for workloads requesting small sizes
> with large alignment constraints.
>
> This change prioritizes the requested allocation size during the search and
> uses an augmented RB-tree field (subtree_max_alignment) to efficiently locate
> free blocks that satisfy both size and offset-alignment requirements. As a
> result, the allocator can directly select an aligned sub-region without
> splitting larger blocks unnecessarily.
>
> A practical example is the VKCTS test
> dEQP-VK.memory.allocation.basic.size_8KiB.reverse.count_4000, which repeatedly
> allocates 8 KiB buffers with a 256 KiB alignment. Previously, such allocations
> caused large blocks to be split aggressively, despite smaller aligned regions
> being sufficient. With this change, those aligned regions are reused directly,
> significantly reducing fragmentation.
>
> This improvement is visible in the amdgpu VRAM buddy allocator state
> (/sys/kernel/debug/dri/1/amdgpu_vram_mm). After the change, higher-order blocks
> are preserved and the number of low-order fragments is substantially reduced.
>
> Before:
> order- 5 free: 1936 MiB, blocks: 15490
> order- 4 free: 967 MiB, blocks: 15486
> order- 3 free: 483 MiB, blocks: 15485
> order- 2 free: 241 MiB, blocks: 15486
> order- 1 free: 241 MiB, blocks: 30948
>
> After:
> order- 5 free: 493 MiB, blocks: 3941
> order- 4 free: 246 MiB, blocks: 3943
> order- 3 free: 123 MiB, blocks: 4101
> order- 2 free: 61 MiB, blocks: 4101
> order- 1 free: 61 MiB, blocks: 8018
>
> By avoiding unnecessary splits, this change improves allocator efficiency and
> helps maintain larger contiguous free regions under heavy offset-aligned
> allocation workloads.
>
> v2:(Matthew)
> - Update augmented information along the path to the inserted node.
>
> v3:
> - Move the patch to gpu/buddy.c file.
>
> v4:(Matthew)
> - Use the helper instead of calling _ffs directly
> - Remove gpu_buddy_block_order(block) >= order check and drop order
> - Drop !node check as all callers handle this already
> - Return larger than any other possible alignment for __ffs64(0)
> - Replace __ffs with __ffs64
>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> Suggested-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/buddy.c | 275 +++++++++++++++++++++++++++++++-------
> include/linux/gpu_buddy.h | 2 +
> 2 files changed, 232 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
> index 603c59a2013a..542131992763 100644
> --- a/drivers/gpu/buddy.c
> +++ b/drivers/gpu/buddy.c
> @@ -14,6 +14,25 @@
>
> static struct kmem_cache *slab_blocks;
>
> +static unsigned int gpu_buddy_block_offset_alignment(struct gpu_buddy_block *block)
> +{
> + u64 offset = gpu_buddy_block_offset(block);
> +
> + if (!offset)
> + /*
> + * __ffs64(0) is undefined; offset 0 is maximally aligned, so return
> + * a value greater than any possible alignment.
> + */
> + return 64 + 1;
> +
> + return __ffs64(offset);
> +}
> +
> +RB_DECLARE_CALLBACKS_MAX(static, gpu_buddy_augment_cb,
> + struct gpu_buddy_block, rb,
> + unsigned int, subtree_max_alignment,
> + gpu_buddy_block_offset_alignment);
> +
> static struct gpu_buddy_block *gpu_block_alloc(struct gpu_buddy *mm,
> struct gpu_buddy_block *parent,
> unsigned int order,
> @@ -31,6 +50,9 @@ static struct gpu_buddy_block *gpu_block_alloc(struct gpu_buddy *mm,
> block->header |= order;
> block->parent = parent;
>
> + block->subtree_max_alignment =
> + gpu_buddy_block_offset_alignment(block);
> +
I think we can drop this now?
prev parent reply other threads:[~2026-02-24 17:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 11:38 [PATCH v4 1/2] drm/buddy: Improve offset-aligned allocation handling Arunpravin Paneer Selvam
2026-02-17 11:39 ` [PATCH v4 2/2] drm/buddy: Add KUnit test for offset-aligned allocations Arunpravin Paneer Selvam
2026-02-24 17:32 ` Matthew Auld
2026-02-17 11:45 ` ✗ CI.checkpatch: warning for series starting with [v4,1/2] drm/buddy: Improve offset-aligned allocation handling Patchwork
2026-02-17 11:47 ` ✓ CI.KUnit: success " Patchwork
2026-02-17 12:05 ` ✗ CI.checksparse: warning " Patchwork
2026-02-17 12:36 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-02-17 14:23 ` ✓ Xe.CI.FULL: success " Patchwork
2026-02-23 7:00 ` [PATCH v4 1/2] " Arunpravin Paneer Selvam
2026-02-23 16:47 ` Matthew Auld
2026-02-24 17:35 ` Matthew Auld [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76588674-affb-478e-8a4a-35e7cf94f58f@intel.com \
--to=matthew.auld@intel.com \
--cc=Arunpravin.PaneerSelvam@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox