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 <[email protected]> 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/[email protected]?part=2
