mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>,
	christian.koenig@amd.com, matthew.auld@intel.com,
	peterz@infradead.org, dri-devel@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Cc: alexander.deucher@amd.com,
	Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Subject: Re: [PATCH v5 1/2] drm/buddy: Optimize free block management with RB tree
Date: Tue, 02 Sep 2025 13:23:20 +0300	[thread overview]
Message-ID: <23142157adbc54a6e2f03a2ebaf209c9bd89439e@intel.com> (raw)
In-Reply-To: <20250901185604.2222-1-Arunpravin.PaneerSelvam@amd.com>

On Tue, 02 Sep 2025, Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> 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.
>
> v4(Jani Nikula):
>   - The kernel-doc comment should be "/**"
>   - Move all the rbtree macros to rbtree.h and add parens to ensure
>     correct precedence.
>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> ---
>  drivers/gpu/drm/drm_buddy.c | 142 ++++++++++++++++++++++--------------
>  include/drm/drm_buddy.h     |   9 ++-
>  include/linux/rbtree.h      |  56 ++++++++++++++
>  3 files changed, 152 insertions(+), 55 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index a94061f373de..978cabfbcf0f 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c

...

> +static inline struct drm_buddy_block *
> +rbtree_last_entry(struct drm_buddy *mm, unsigned int order)

Drive-by reminder that "inline" in a .c file is, in absense of evidence
to the contrary, superfluous. Please just let the compiler do its job.

BR,
Jani.


-- 
Jani Nikula, Intel

  parent reply	other threads:[~2025-09-02 10:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-01 18:56 Arunpravin Paneer Selvam
2025-09-01 19:41 ` Peter Zijlstra
2025-09-02  6:09   ` Arunpravin Paneer Selvam
2025-09-09  6:22     ` Arunpravin Paneer Selvam
2025-09-02 10:23 ` Jani Nikula [this message]
2025-09-02 10:35   ` Arunpravin Paneer Selvam

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=23142157adbc54a6e2f03a2ebaf209c9bd89439e@intel.com \
    --to=jani.nikula@linux.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 \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.auld@intel.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®