mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>
To: William Palacek <William.Palacek@amd.com>,
	dri-devel@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Sanjay Yadav" <sanjay.kumar.yadav@intel.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Christian König" <christian.koenig@amd.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/3] gpu/buddy: drop subtree_max_free_order
Date: Thu, 19 Nov 2026 10:39:36 +0530	[thread overview]
Message-ID: <14bb9b12-8224-4777-a6ec-873e54893c02@amd.com> (raw)
In-Reply-To: <ae3be752ad88e467bb05e5576af3e5ee4394041e.1795032989.git.William.Palacek@amd.com>



On 11/19/2026 1:47 AM, William Palacek wrote:
> __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@intel.com>
> Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> Cc: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
> Signed-off-by: William Palacek <William.Palacek@amd.com>
> ---
>
> Notes:
>      v4:
>      - new patch
Please squash patches 1 and 2, so the new approach directly replaces the 
existing one within the same patch.

Regards,
Arun.
>
>   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)
>   


  reply	other threads:[~2026-11-19  5:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 20:16 [PATCH v4 0/3] gpu/buddy: find range-biased blocks in the free trees William Palacek
2026-11-18 20:16 ` [PATCH v4 1/3] " William Palacek
2026-11-18 20:17 ` [PATCH v4 2/3] gpu/buddy: drop subtree_max_free_order William Palacek
2026-11-19  5:09   ` Arunpravin Paneer Selvam [this message]
2026-11-18 20:17 ` [PATCH v4 3/3] gpu/tests/buddy: add range-biased allocation tests William Palacek

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=14bb9b12-8224-4777-a6ec-873e54893c02@amd.com \
    --to=arunpravin.paneerselvam@amd.com \
    --cc=William.Palacek@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.auld@intel.com \
    --cc=sanjay.kumar.yadav@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

all inboxes | Powered by JetHome®