Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Himal Prasad Ghimiray" <himal.prasad.ghimiray@intel.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org
Subject: Re: [RFC v2 02/11] drm/ttm: Add TTM_NUMA_POLICY_BIND
Date: Tue, 24 Nov 2026 06:29:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-230596@kernel.org> (raw)
In-Reply-To: <20261124062123.2431244-15-himal.prasad.ghimiray@intel.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/ttm: __ttm_pool_alloc() only checks first_node() in pool
  for BIND policy
- [Medium] drm/ttm: ttm_pool_alloc_bind_pass() omits __GFP_NOWARN on
  non-final nodes
- [Low] drm/ttm: inaccurate node order in TTM_NUMA_POLICY_BIND
  kernel-doc comment
--

commit a807e823bf27ab4c849adb0b91f8553524818abe
Author: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>

drm/ttm: Add TTM_NUMA_POLICY_BIND

This commit adds TTM_NUMA_POLICY_BIND to enum ttm_numa_policy to restrict
system page allocations to the nodes in ttm_operation_ctx.numa_info.nodes,
trying them in nearest-first order from the pool's local node.

> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index e9e6ee266c2ff..8976de3a552d1 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> @@ -780,6 +780,56 @@ static unsigned int ttm_pool_alloc_find_order(unsigned int highest,
>  	return min_t(unsigned int, highest, __fls(alloc->remaining_pages));
>  }
>  
> +/*
> + * Try the nodes in @nodes once each, nearest first from the local node.
> + * __GFP_THISNODE prevents fallback to nodes outside the policy.
> + */
> +static struct page *ttm_pool_alloc_bind_pass(struct ttm_pool *pool,
> +					     gfp_t gfp_flags, unsigned int order,
> +					     const nodemask_t *nodes)
> +{
> +	int local = ttm_pool_nid(pool);
> +	nodemask_t todo = *nodes;
> +	struct page *p = NULL;
> +
> +	while (!nodes_empty(todo)) {
> +		int nid = first_node(todo), n;
> +
> +		for_each_node_mask(n, todo) {
> +			if (node_distance(local, n) < node_distance(local, nid))
> +				nid = n;
> +		}
> +		node_clear(nid, todo);
> +
> +		p = ttm_pool_alloc_page(pool, gfp_flags | __GFP_THISNODE, order,
> +					nid);
> +		if (p)
> +			break;
> +	}
> +
> +	return p;
> +}

[Severity: Medium]
Can ttm_pool_alloc_bind_pass() emit a spurious warn_alloc() splat when
direct reclaim fails on an earlier node in todo even though a later node in
the bind mask succeeds?

In the second pass of ttm_pool_alloc_bind(), gfp_flags lacks __GFP_NOWARN
for order-0 allocations when !ctx->gfp_retry_mayfail, and
ttm_pool_alloc_page() only adds __GFP_NOWARN when order != 0.  Passing
__GFP_NOWARN while !nodes_empty(todo) would avoid warning before all bound
nodes have been tried.

[ ... ]

> @@ -858,8 +908,12 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
>  		if (!p) {
>  			page_caching = ttm_cached;
>  			allow_pools = false;
> -			p = ttm_pool_alloc_page(pool, gfp_flags, order,
> -						alloc_nid);
> +			if (policy == TTM_NUMA_POLICY_BIND)
> +				p = ttm_pool_alloc_bind(pool, gfp_flags, order,
> +							ctx->numa_info.nodes);
> +			else
> +				p = ttm_pool_alloc_page(pool, gfp_flags, order,
> +							alloc_nid);
>  		}
>  		/* If that fails, lower the order if possible and retry. */
>  		if (!p) {

[Severity: High]
Does the TTM pool lookup above this fallback only check
first_node(*ctx->numa_info.nodes) for TTM_NUMA_POLICY_BIND instead of
trying the bound nodes in nearest-first order?

drivers/gpu/drm/ttm/ttm_pool.c:__ttm_pool_alloc() {
	...
	if (policy != TTM_NUMA_POLICY_NONE) {
		/* Start at the single node of the policy */
		alloc_nid = first_node(*ctx->numa_info.nodes);
		take_nid = alloc_nid;
	}
	...
		pt = ttm_pool_select_type(pool, page_caching, order);
		if (pt && allow_pools)
			p = ttm_pool_type_take(pt, take_nid);
	...
}

For ttm_write_combined or ttm_uncached allocations with a multi-node bind
mask (for example {0, 1} when ttm_pool_nid(pool) is node 1),
ttm_pool_type_take() takes pooled pages from remote node 0 ahead of local
node 1.

When node 0's pool is empty, ttm_pool_type_take(pt, 0) fails without
checking node 1's pool, disables pool usage for the order, allocates fresh
write-back pages on nearest node 1 via ttm_pool_alloc_bind(), and pays for
cross-CPU set_pages_array_wc() or set_pages_array_uc() TLB shootdowns.
When those pages are later freed, ttm_pool_type_give() returns them to node
1's LRU, where subsequent BIND allocations with mask {0, 1} never check.

> diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
> index 5289c17cd4496..e7605e7e97ecc 100644
> --- a/include/drm/ttm/ttm_bo.h
> +++ b/include/drm/ttm/ttm_bo.h
> @@ -58,10 +58,14 @@ struct ttm_tt;
>   * @TTM_NUMA_POLICY_NONE: No policy. Use the pool default node.
>   * @TTM_NUMA_POLICY_PREFERRED: Prefer the single node in
>   *	ttm_operation_ctx.numa_info.nodes. Falls back to other nodes.
> + * @TTM_NUMA_POLICY_BIND: Allocate only from the nodes in
> + *	ttm_operation_ctx.numa_info.nodes, in ascending node order. Never falls
> + *	back to other nodes.
>   */
>  enum ttm_numa_policy {
>  	TTM_NUMA_POLICY_NONE = 0,
>  	TTM_NUMA_POLICY_PREFERRED,
> +	TTM_NUMA_POLICY_BIND,
>  };

[Severity: Low]
This comment says nodes are tried "in ascending node order", whereas
ttm_pool_alloc_bind_pass() orders nodes nearest-first from ttm_pool_nid()
by node_distance() and only uses ascending node ID to break ties.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124062123.2431244-13-himal.prasad.ghimiray@intel.com?part=2

  reply	other threads:[~2026-11-24  6:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  6:21 [RFC v2 00/11] drm/ttm, drm/xe: Per-BO host NUMA memory policy Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 01/11] drm/ttm: Add NUMA placement policy to ttm_operation_ctx Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 02/11] drm/ttm: Add TTM_NUMA_POLICY_BIND Himal Prasad Ghimiray
2026-11-24  6:29   ` sashiko-bot [this message]
2026-11-24  6:21 ` [RFC v2 03/11] drm/ttm: Add TTM_NUMA_POLICY_INTERLEAVE Himal Prasad Ghimiray
2026-11-24  6:32   ` sashiko-bot
2026-11-24  6:21 ` [RFC v2 04/11] drm/ttm/pool: enforce per-node cache limits on free Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 05/11] drm/amdgpu: Use ttm_operation_ctx numa_info instead of per-partition pools Himal Prasad Ghimiray
2026-11-24  6:31   ` sashiko-bot
2026-11-24  6:21 ` [RFC v2 06/11] drm/ttm/pool: Drop the nid argument from ttm_pool_init() Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 07/11] drm/xe/uapi: Add GEM_CREATE host NUMA mempolicy extension Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 08/11] drm/xe/bo: Carry a per-BO host NUMA mempolicy Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 09/11] drm/xe/uapi: Wire up GEM_CREATE mempolicy extension handler Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 10/11] drm/xe/uapi: Add device query for supported host NUMA mempolicy modes Himal Prasad Ghimiray
2026-11-24  6:21 ` [RFC v2 11/11] drm/xe: Implement the host NUMA mempolicy device query Himal Prasad Ghimiray
2026-11-24  6:26 ` ✗ CI.KUnit: failure for drm/ttm, drm/xe: Per-BO host NUMA memory policy Patchwork

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=sashiko-outbox-230596@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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