Skip to content

Commit ed43af5

Browse files
Christian KönigSasha Levin
authored andcommitted
drm/ttm: stop pooling cached NUMA pages v2
[ Upstream commit b6976f3 ] We only pool write combined and uncached allocations because they require extra overhead on allocation and release. If we also pool cached NUMA it not only means some extra unnecessary overhead, but also that under memory pressure it can happen that pages from the wrong NUMA node enters the pool and are re-used over and over again. This can lead to performance reduction after running into memory pressure. v2: restructure and cleanup the code a bit from the internal hack to test this. Signed-off-by: Christian König <christian.koenig@amd.com> Fixes: 4482d3c ("drm/ttm: add NUMA node id to the pool") CC: stable@vger.kernel.org Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240415134821.1919-1-christian.koenig@amd.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 93353d6 commit ed43af5

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

drivers/gpu/drm/ttm/ttm_pool.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool,
287287
enum ttm_caching caching,
288288
unsigned int order)
289289
{
290-
if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE)
290+
if (pool->use_dma_alloc)
291291
return &pool->caching[caching].orders[order];
292292

293293
#ifdef CONFIG_X86
294294
switch (caching) {
295295
case ttm_write_combined:
296+
if (pool->nid != NUMA_NO_NODE)
297+
return &pool->caching[caching].orders[order];
298+
296299
if (pool->use_dma32)
297300
return &global_dma32_write_combined[order];
298301

299302
return &global_write_combined[order];
300303
case ttm_uncached:
304+
if (pool->nid != NUMA_NO_NODE)
305+
return &pool->caching[caching].orders[order];
306+
301307
if (pool->use_dma32)
302308
return &global_dma32_uncached[order];
303309

@@ -563,11 +569,17 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
563569
pool->use_dma_alloc = use_dma_alloc;
564570
pool->use_dma32 = use_dma32;
565571

566-
if (use_dma_alloc || nid != NUMA_NO_NODE) {
567-
for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i)
568-
for (j = 0; j < NR_PAGE_ORDERS; ++j)
569-
ttm_pool_type_init(&pool->caching[i].orders[j],
570-
pool, i, j);
572+
for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) {
573+
for (j = 0; j < NR_PAGE_ORDERS; ++j) {
574+
struct ttm_pool_type *pt;
575+
576+
/* Initialize only pool types which are actually used */
577+
pt = ttm_pool_select_type(pool, i, j);
578+
if (pt != &pool->caching[i].orders[j])
579+
continue;
580+
581+
ttm_pool_type_init(pt, pool, i, j);
582+
}
571583
}
572584
}
573585
EXPORT_SYMBOL(ttm_pool_init);
@@ -584,10 +596,16 @@ void ttm_pool_fini(struct ttm_pool *pool)
584596
{
585597
unsigned int i, j;
586598

587-
if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) {
588-
for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i)
589-
for (j = 0; j < NR_PAGE_ORDERS; ++j)
590-
ttm_pool_type_fini(&pool->caching[i].orders[j]);
599+
for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) {
600+
for (j = 0; j < NR_PAGE_ORDERS; ++j) {
601+
struct ttm_pool_type *pt;
602+
603+
pt = ttm_pool_select_type(pool, i, j);
604+
if (pt != &pool->caching[i].orders[j])
605+
continue;
606+
607+
ttm_pool_type_fini(pt);
608+
}
591609
}
592610

593611
/* We removed the pool types from the LRU, but we need to also make sure

0 commit comments

Comments
 (0)