From: Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>
To: Matthew Auld <matthew.auld@intel.com>,
christian.koenig@amd.com, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org
Cc: alexander.deucher@amd.com
Subject: Re: [PATCH v3 1/2] drm/buddy: Optimize free block management with RB tree
Date: Mon, 25 Aug 2025 17:10:50 +0530 [thread overview]
Message-ID: <954a19f5-899d-42fd-8b45-e32680817fae@amd.com> (raw)
In-Reply-To: <0353c333-2673-4157-bf93-08c6435e5827@intel.com>
On 8/22/2025 5:58 PM, Matthew Auld wrote:
> On 22/08/2025 09:37, Matthew Auld wrote:
>> On 21/08/2025 16:06, Arunpravin Paneer Selvam wrote:
>>> Replace the freelist (O(n)) used for free block management with a
>>> red-black tree, providing more efficient O(log n) search, insert,
>>> and delete operations. This improves scalability and performance
>>> when managing large numbers of free blocks per order (e.g., hundreds
>>> or thousands).
>>>
>>> In the VK-CTS memory stress subtest, the buddy manager merges
>>> fragmented memory and inserts freed blocks into the freelist. Since
>>> freelist insertion is O(n), this becomes a bottleneck as fragmentation
>>> increases. Benchmarking shows list_insert_sorted() consumes ~52.69% CPU
>>> with the freelist, compared to just 0.03% with the RB tree
>>> (rbtree_insert.isra.0), despite performing the same sorted insert.
>>>
>>> This also improves performance in heavily fragmented workloads,
>>> such as games or graphics tests that stress memory.
>>>
>>> v3(Matthew):
>>> - Remove RB_EMPTY_NODE check in force_merge function.
>>> - Rename rb for loop macros to have less generic names and move to
>>> .c file.
>>> - Make the rb node rb and link field as union.
>>>
>>> Signed-off-by: Arunpravin Paneer Selvam
>>> <Arunpravin.PaneerSelvam@amd.com>
>>
>> CI is reporting a crash in rb_erase when running the drm_buddy kunit,
>> somewhere in drm_test_buddy_alloc_clear it seems.
>
> Found one bug in the second patch:
>
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -507,6 +507,8 @@ static int split_block(struct drm_buddy *mm,
> return -ENOMEM;
> }
>
> + mark_split(mm, block);
> +
> if (drm_buddy_block_is_clear(block)) {
> mark_cleared(block->left);
> mark_cleared(block->right);
> @@ -516,8 +518,6 @@ static int split_block(struct drm_buddy *mm,
> mark_free(mm, block->left);
> mark_free(mm, block->right);
>
> - mark_split(mm, block);
> -
> return 0;
> }
>
> Otherwise the mark_split might get the wrong rb root if we reset the
> clear state first. Might help with this crash.
Thanks, I think I missed updating here when we removed the new tree
field and modified it to use the existing dirty/free bit in the
drm_buddy_block struct in v3 patches.
I will add this fix in v4.
Regards,
Arun.
prev parent reply other threads:[~2025-08-25 11:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 15:06 [PATCH v3 1/2] drm/buddy: Optimize free block management with RB tree Arunpravin Paneer Selvam
2025-08-21 15:06 ` [PATCH v3 2/2] drm/buddy: Separate clear and dirty free block trees Arunpravin Paneer Selvam
2025-08-22 12:02 ` Matthew Auld
2025-08-25 11:31 ` Arunpravin Paneer Selvam
2025-08-26 14:32 ` Matthew Auld
2025-08-22 8:37 ` [PATCH v3 1/2] drm/buddy: Optimize free block management with RB tree Matthew Auld
2025-08-22 12:28 ` Matthew Auld
2025-08-25 11:40 ` Arunpravin Paneer Selvam [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=954a19f5-899d-42fd-8b45-e32680817fae@amd.com \
--to=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 \
--cc=matthew.auld@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).