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 03/11] drm/ttm: Add TTM_NUMA_POLICY_INTERLEAVE
Date: Tue, 24 Nov 2026 06:32:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-230599@kernel.org> (raw)
In-Reply-To: <20261124062123.2431244-16-himal.prasad.ghimiray@intel.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/ttm: broken interleave node rotation on order decrease in
__ttm_pool_alloc()
- [Medium] drm/ttm: unconstrained order-0 fallback and reclaim in
ttm_pool_alloc_interleave()
- [Medium] drm/ttm: cross-node pool take in
ttm_pool_type_take_interleave() before alloc
--
commit 99e6c53830405c25271c091f8f19cad519333639
Author: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
drm/ttm: Add TTM_NUMA_POLICY_INTERLEAVE
This commit adds TTM_NUMA_POLICY_INTERLEAVE to rotate TTM page allocations
and pool lookups across the NUMA nodes in ttm_operation_ctx.numa_info.nodes.
> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index 8976de3a552d1..210d443185644 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> @@ -373,6 +373,38 @@ static struct page *ttm_pool_type_take(struct ttm_pool_type *pt, int nid)
> return p;
> }
>
> +/* Return the node in @nodes nearest to @from, lowest node id on ties */
> +static int ttm_pool_nearest_node(int from, const nodemask_t *nodes)
> +{
> + int n, nid = first_node(*nodes);
> +
> + for_each_node_mask(n, *nodes) {
> + if (node_distance(from, n) < node_distance(from, nid))
> + nid = n;
> + }
> +
> + return nid;
> +}
> +
> +/* Take from @nid first, then from the other nodes nearest to @nid first */
> +static struct page *ttm_pool_type_take_interleave(struct ttm_pool_type *pt,
> + int nid, const nodemask_t *nodes)
> +{
> + nodemask_t todo = *nodes;
> + struct page *p;
> +
> + p = ttm_pool_type_take(pt, nid);
> + node_clear(nid, todo);
> + while (!p && !nodes_empty(todo)) {
> + int n = ttm_pool_nearest_node(nid, &todo);
> +
> + node_clear(n, todo);
> + p = ttm_pool_type_take(pt, n);
> + }
> +
> + return p;
> +}
[Severity: Medium]
Does ttm_pool_type_take_interleave() take cached pool pages from other nodes
in @nodes before trying a fresh page allocation on @nid?
When @nid's pool for a write-combined or uncached order is empty,
__ttm_pool_alloc() drains pooled pages from sibling policy nodes even when
@nid has free system memory. Because ttm_pool_free() returns freed pages to
the pool of page_to_nid(p), @nid's pool remains empty and interleaved WC/UC
allocations collapse onto whichever node already had cached pool pages.
[ ... ]
> @@ -830,6 +873,31 @@ static struct page *ttm_pool_alloc_bind(struct ttm_pool *pool, gfp_t gfp_flags,
> return p;
> }
>
> +/*
> + * Allocate pages of size 1 << order for TTM_NUMA_POLICY_INTERLEAVE. Try the
> + * interleaved node @nid first, then the other nodes in @nodes nearest to @nid
> + * first, as the per-node zonelist fallback of core mm does, before the caller
> + * lowers the order.
> + */
> +static struct page *ttm_pool_alloc_interleave(struct ttm_pool *pool,
> + gfp_t gfp_flags, unsigned int order,
> + int nid, const nodemask_t *nodes)
> +{
> + nodemask_t todo = *nodes;
> + struct page *p;
> +
> + p = ttm_pool_alloc_page(pool, gfp_flags, order, nid);
> + node_clear(nid, todo);
> + while (!p && !nodes_empty(todo)) {
> + int n = ttm_pool_nearest_node(nid, &todo);
> +
> + node_clear(n, todo);
> + p = ttm_pool_alloc_page(pool, gfp_flags, order, n);
> + }
> +
> + return p;
> +}
[Severity: Medium]
Does ttm_pool_alloc_interleave() fall back outside @nodes on order-0
allocations and stall in reclaim before trying other policy nodes?
ttm_pool_alloc_page() only sets __GFP_THISNODE when order > 0. At order 0,
the first ttm_pool_alloc_page() call walks @nid's unfiltered fallback
zonelist, which can allocate from a node outside @nodes before the remaining
nodes in @todo are tried, and if all zones are exhausted the while loop
repeats system-wide direct reclaim once for each remaining node in @todo.
In addition, unlike ttm_pool_alloc_bind(), ttm_pool_alloc_interleave() does
not try a non-reclaim pass across @nodes first, so a depleted @nid enters
direct reclaim and compaction even when another node in @nodes has free
pages of that order.
[ ... ]
> @@ -893,11 +961,24 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> order = ttm_pool_alloc_find_order(order, alloc)) {
> struct ttm_pool_type *pt;
>
> + if (policy == TTM_NUMA_POLICY_INTERLEAVE) {
> + unsigned int slot = tt->num_pages - alloc->remaining_pages;
> +
> + alloc_nid = ttm_pool_policy_nth_node(ctx->numa_info.nodes,
> + slot >> order);
> + take_nid = alloc_nid;
> + }
[Severity: High]
Does computing the node index as slot >> order fail to rotate across
ctx->numa_info.nodes whenever the allocation order decreases?
In __ttm_pool_alloc(), order is monotonically non-increasing, and slot is the
sum of 1 << prev_order for all prior chunks. Whenever a chunk has a smaller
order than the chunks before it, every prior chunk contributed an even
multiple of 1 << order pages to slot, so slot >> order is always even. When
nodes_weight(*ctx->numa_info.nodes) is even, such as a 2-node mask,
(slot >> order) % nodes_weight(...) is always 0 on every decreased order.
For example, a 3 MiB buffer (orders 9 and 8) or any buffer smaller than
8 MiB whose size is not a multiple of 4 MiB places all of its chunks on the
first policy node instead of interleaving them. Counting allocated chunks
with a separate counter that increments once per allocated page would rotate
across nodes regardless of order changes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124062123.2431244-13-himal.prasad.ghimiray@intel.com?part=3
next prev parent reply other threads:[~2026-11-24 6:32 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
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 [this message]
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-230599@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