drm/ttm: stop pooling cached NUMA pages v2
Subsystems (3)
PATCH 1/1 drm/ttm: stop pooling cached NUMA pages v2
From: Christian König <[email protected]>
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.
--- drivers/gpu/drm/ttm/ttm_pool.c | 38 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_pool.c +28 -10
@@ -288,17 +288,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, enum ttm_caching caching, unsigned int order) { - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) + if (pool->use_dma_alloc) return &pool->caching[caching].orders[order]; #ifdef CONFIG_X86 switch (caching) { case ttm_write_combined: + if (pool->nid != NUMA_NO_NODE) + return &pool->caching[caching].orders[order]; + if (pool->use_dma32) return &global_dma32_write_combined[order]; return &global_write_combined[order]; case ttm_uncached: + if (pool->nid != NUMA_NO_NODE) + return &pool->caching[caching].orders[order]; + if (pool->use_dma32) return &global_dma32_uncached[order];
@@ -566,11 +572,17 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev, pool->use_dma_alloc = use_dma_alloc; pool->use_dma32 = use_dma32; -if (use_dma_alloc || nid !=NUMA_NO_NODE ) { -for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) -for (j =0 ; j <NR_PAGE_ORDERS ; ++j) -ttm_pool_type_init (&pool->caching[i].orders[j], - pool, i, j); +for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) { +for (j =0 ; j <NR_PAGE_ORDERS ; ++j) { +struct ttm_pool_type *pt; + +/* Initialize only pool types which are actually used */ + pt =ttm_pool_select_type (pool, i, j); +if (pt != &pool->caching[i].orders[j]) +continue ; + +ttm_pool_type_init (pt, pool, i, j); + } } }EXPORT_SYMBOL (ttm_pool_init);
@@ -599,10 +611,16 @@ void ttm_pool_fini(struct ttm_pool *pool) {unsigned int i, j; -if (pool->use_dma_alloc || pool->nid !=NUMA_NO_NODE ) { -for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) -for (j =0 ; j <NR_PAGE_ORDERS ; ++j) -ttm_pool_type_fini (&pool->caching[i].orders[j]); +for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) { +for (j =0 ; j <NR_PAGE_ORDERS ; ++j) { +struct ttm_pool_type *pt; + + pt =ttm_pool_select_type (pool, i, j); +if (pt != &pool->caching[i].orders[j]) +continue ; + +ttm_pool_type_fini (pt); + } }/* We removed the pool types from the LRU, but we need to also make sure
Signature · 1 line
2.34.1
Quoted 30 lines · Christian König
From: Christian König <[email protected]>
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 <[email protected]>Fixes 4482d3c94d7f ("drm/ttm: add NUMA node id to the pool")--- drivers/gpu/drm/ttm/ttm_pool.c | 38 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_pool.c +0
-0@@ -288,17 +288,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool,enum ttm_caching caching, unsigned int order)
drivers/gpu/drm/ttm/ttm_pool.c static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, · line 298
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_pool.c +3
-1{ -if (pool->use_dma_alloc || pool->nid !=NUMA_NO_NODE ) +if (pool->use_dma_alloc)return &pool->caching[caching].orders[order];#ifdef CONFIG_X86 switch (caching) {case ttm_write_combined: +if (pool->nid !=NUMA_NO_NODE ) +return &pool->caching[caching].orders[order];
Doesn't this break USWC allocations on NUMA systems, where we set a NUMA node for the default pool (at least we were planning to at some point)?
Regards,
Felix
Quoted 56 lines
drivers/gpu/drm/ttm/ttm_pool.c +25
-9+if (pool->use_dma32)return &global_dma32_write_combined[order];return &global_write_combined[order];case ttm_uncached: +if (pool->nid !=NUMA_NO_NODE ) +return &pool->caching[caching].orders[order]; +if (pool->use_dma32)return &global_dma32_uncached[order];@@ -566,11 +572,17 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev, pool->use_dma_alloc = use_dma_alloc; pool->use_dma32 = use_dma32; -if (use_dma_alloc || nid !=NUMA_NO_NODE ) { -for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) -for (j =0 ; j <NR_PAGE_ORDERS ; ++j) -ttm_pool_type_init (&pool->caching[i].orders[j], - pool, i, j); +for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) { +for (j =0 ; j <NR_PAGE_ORDERS ; ++j) { +struct ttm_pool_type *pt; + +/* Initialize only pool types which are actually used */ + pt =ttm_pool_select_type (pool, i, j); +if (pt != &pool->caching[i].orders[j]) +continue ; + +ttm_pool_type_init (pt, pool, i, j); + } } }EXPORT_SYMBOL (ttm_pool_init);@@ -599,10 +611,16 @@ void ttm_pool_fini(struct ttm_pool *pool) {unsigned int i, j; -if (pool->use_dma_alloc || pool->nid !=NUMA_NO_NODE ) { -for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) -for (j =0 ; j <NR_PAGE_ORDERS ; ++j) -ttm_pool_type_fini (&pool->caching[i].orders[j]); +for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i) { +for (j =0 ; j <NR_PAGE_ORDERS ; ++j) { +struct ttm_pool_type *pt; + + pt =ttm_pool_select_type (pool, i, j); +if (pt != &pool->caching[i].orders[j]) +continue ; + +ttm_pool_type_fini (pt); + } }/* We removed the pool types from the LRU, but we need to also make sure
Am 15.04.24 um 15:53 schrieb Felix Kuehling:
Quoted 35 lines · Christian König
Quoted 34 lines
From: Christian König <[email protected]>
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 <[email protected]>Fixes 4482d3c94d7f ("drm/ttm: add NUMA node id to the pool")---
drivers/gpu/drm/ttm/ttm_pool.c| 38 +++++++++++++++++++++++++---------1 file changed, 28 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_pool.c +1
-1@@ -288,17 +288,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, enum ttm_caching caching, unsigned int order) { - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) + if (pool->use_dma_alloc)
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_pool.c +0
-0return &pool->caching[caching].orders[order]; #ifdef CONFIG_X86 switch (caching) {case
ttm_write_combined:
+ if (pool->nid!=NUMA_NO_NODE)
+ return &pool->caching[caching].orders[order];Doesn't this break USWC allocations on NUMA systems, where we set a NUMA node for the default pool (at least we were planning to at some point)?
I don't think so, but I might have missed something. Why do you think that would break?
I mean the idea is basically if the pool is associated with a NUMA id we should rather use this pool instead of the global one.
And that is true for both cases, the default pool and the specialized ones.
Regards,
Christian.
Quoted 56 lines
Regards,
FelixQuoted 51 lines
+
if (pool->use_dma32)
return &global_dma32_write_combined[order];
return &global_write_combined[order];
casettm_uncached:
+ if (pool->nid!=NUMA_NO_NODE)
+ return &pool->caching[caching].orders[order];
+
if (pool->use_dma32)
return &global_dma32_uncached[order];
@@ -566,11 +572,17 @@ void ttm_pool_init(structttm_pool*pool, struct device *dev,pool->use_dma_alloc=use_dma_alloc;
pool->use_dma32=use_dma32;
- if (use_dma_alloc|| nid !=NUMA_NO_NODE) {
- for (i = 0; i <TTM_NUM_CACHING_TYPES; ++i)
- for (j = 0; j <NR_PAGE_ORDERS; ++j)
- ttm_pool_type_init(&pool->caching[i].orders[j],
- pool, i, j);
+ for (i = 0; i <TTM_NUM_CACHING_TYPES; ++i) {
+ for (j = 0; j <NR_PAGE_ORDERS; ++j) {
+ structttm_pool_type*pt;drivers/gpu/drm/ttm/ttm_pool.c +8
-0+ + /* Initialize only pool types which are actually used */ + pt = ttm_pool_select_type(pool, i, j); + if (pt != &pool->caching[i].orders[j]) + continue; + + ttm_pool_type_init(pt, pool, i, j); + }}
}
EXPORT_SYMBOL(ttm_pool_init);drivers/gpu/drm/ttm/ttm_pool.c +10
-3@@ -599,10 +611,16 @@ void ttm_pool_fini(struct ttm_pool *pool) { unsigned int i, j; - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) { - for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) - for (j = 0; j < NR_PAGE_ORDERS; ++j) -ttm_pool_type_fini (&pool->caching[i].orders[j]); + for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) { + for (j = 0; j < NR_PAGE_ORDERS; ++j) { + struct ttm_pool_type *pt; + + pt = ttm_pool_select_type(pool, i, j); + if (pt != &pool->caching[i].orders[j]) + continue; + + ttm_pool_type_fini(pt); + } } /* We removed the pool types from the LRU, but we need to also make sure
Felix Kuehling
Reviewed-byQuoted 46 lines · Christian König
Am 15.04.24 um 15:53 schrieb Felix Kuehling:
Quoted 36 lines · Christian König
Quoted 35 lines
From: Christian König <[email protected]>
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 <[email protected]>Fixes 4482d3c94d7f ("drm/ttm: add NUMA node id to the pool")---
drivers/gpu/drm/ttm/ttm_pool.c| 38
+++++++++++++++++++++++++---------1 file changed, 28 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_pool.c +1
-1@@ -288,17 +288,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, enum ttm_caching caching, unsigned int order) { - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) + if (pool->use_dma_alloc)Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_pool.c +0
-0return &pool->caching[caching].orders[order]; #ifdef CONFIG_X86 switch (caching) {case
ttm_write_combined:
+ if (pool->nid!=NUMA_NO_NODE)
+ return &pool->caching[caching].orders[order];Doesn't this break USWC allocations on NUMA systems, where we set a NUMA node for the default pool (at least we were planning to at some point)?
Quoted 5 lines
I don't think so, but I might have missed something. Why do you think that would break?
I mean the idea is basically if the pool is associated with a NUMA id we should rather use this pool instead of the global one.
And that is true for both cases, the default pool and the specialized ones.
OK, I think I misunderstood what I was reading. It looked to me like it would always use a "caching" pool if nid was set. But caching here is a variable; each node still has specialized pools for write combining etc.
Then the concern you stated in the commit message "under memory pressure it can happen that pages from the wrong NUMA node enters the pool and are re-used over and over again" is still possible for uncached and wc pages. Anyway, it's better than not having NUMA, I guess.
The patch is
Quoted 61 lines
Regards,
Christian.Quoted 56 lines
Regards,
FelixQuoted 51 lines
+
if (pool->use_dma32)
return &global_dma32_write_combined[order];
return &global_write_combined[order];
casettm_uncached:
+ if (pool->nid!=NUMA_NO_NODE)
+ return &pool->caching[caching].orders[order];
+
if (pool->use_dma32)
return &global_dma32_uncached[order];
@@ -566,11 +572,17 @@ void ttm_pool_init(structttm_pool*pool, struct device *dev,pool->use_dma_alloc=use_dma_alloc;
pool->use_dma32=use_dma32;
- if (use_dma_alloc|| nid !=NUMA_NO_NODE) {
- for (i = 0; i <TTM_NUM_CACHING_TYPES; ++i)
- for (j = 0; j <NR_PAGE_ORDERS; ++j)
- ttm_pool_type_init(&pool->caching[i].orders[j],
- pool, i, j);
+ for (i = 0; i <TTM_NUM_CACHING_TYPES; ++i) {
+ for (j = 0; j <NR_PAGE_ORDERS; ++j) {
+ structttm_pool_type*pt;drivers/gpu/drm/ttm/ttm_pool.c +8
-0+ + /* Initialize only pool types which are actually used */ + pt = ttm_pool_select_type(pool, i, j); + if (pt != &pool->caching[i].orders[j]) + continue; + + ttm_pool_type_init(pt, pool, i, j); + }}
}
EXPORT_SYMBOL(ttm_pool_init);drivers/gpu/drm/ttm/ttm_pool.c +10
-3@@ -599,10 +611,16 @@ void ttm_pool_fini(struct ttm_pool *pool) { unsigned int i, j; - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) { - for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) - for (j = 0; j < NR_PAGE_ORDERS; ++j) -ttm_pool_type_fini (&pool->caching[i].orders[j]); + for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) { + for (j = 0; j < NR_PAGE_ORDERS; ++j) { + struct ttm_pool_type *pt; + + pt = ttm_pool_select_type(pool, i, j); + if (pt != &pool->caching[i].orders[j]) + continue; + + ttm_pool_type_fini(pt); + } } /* We removed the pool types from the LRU, but we need to also make sure
Am 15.04.24 um 16:32 schrieb Felix Kuehling:
Quoted 49 lines · Christian König
Quoted 48 lines
Am 15.04.24 um 15:53 schrieb Felix Kuehling:
Quoted 36 lines · Christian König
Quoted 35 lines
From: Christian König <[email protected]>
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 <[email protected]>Fixes 4482d3c94d7f ("drm/ttm: add NUMA node id to the pool")---
drivers/gpu/drm/ttm/ttm_pool.c| 38
+++++++++++++++++++++++++---------1 file changed, 28 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_pool.c +1
-1@@ -288,17 +288,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, enum ttm_caching caching, unsigned int order) { - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) + if (pool->use_dma_alloc)Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_pool.c +0
-0return &pool->caching[caching].orders[order]; #ifdef CONFIG_X86 switch (caching) {case
ttm_write_combined:
+ if (pool->nid!=NUMA_NO_NODE)
+ return &pool->caching[caching].orders[order];Doesn't this break USWC allocations on NUMA systems, where we set a NUMA node for the default pool (at least we were planning to at some point)?
I don't think so, but I might have missed something. Why do you think that would break?
Quoted 7 lines
Quoted 3 lines
I mean the idea is basically if the pool is associated with a NUMA id we should rather use this pool instead of the global one.
And that is true for both cases, the default pool and the specialized ones.
OK, I think I misunderstood what I was reading. It looked to me like it would always use a "caching" pool if nid was set. But caching here is a variable; each node still has specialized pools for write combining etc.
Then the concern you stated in the commit message "under memory pressure it can happen that pages from the wrong NUMA node enters the pool and are re-used over and over again" is still possible for uncached and wc pages. Anyway, it's better than not having NUMA, I guess.
Yes, correct. But since KFD doesn't use USWC that much I don't think this will cause an issue.
If we really start to see issues with that we can always re-consider using __GFP_THIS_NODE.
Quoted 4 lines
The patch is
Reviewed-by Felix Kuehling <[email protected]>
Thanks, going to push to drm-misc-fixes now.
Regards,
Christian.
Quoted 63 lines
Quoted 63 lines
Regards,
Christian.Quoted 56 lines
Regards,
FelixQuoted 51 lines
+
if (pool->use_dma32)
return &global_dma32_write_combined[order];
return &global_write_combined[order];
casettm_uncached:
+ if (pool->nid!=NUMA_NO_NODE)
+ return &pool->caching[caching].orders[order];
+
if (pool->use_dma32)
return &global_dma32_uncached[order];
@@ -566,11 +572,17 @@ void ttm_pool_init(structttm_pool*pool, struct device *dev,pool->use_dma_alloc=use_dma_alloc;
pool->use_dma32=use_dma32;
- if (use_dma_alloc|| nid !=NUMA_NO_NODE) {
- for (i = 0; i <TTM_NUM_CACHING_TYPES; ++i)
- for (j = 0; j <NR_PAGE_ORDERS; ++j)
- ttm_pool_type_init(&pool->caching[i].orders[j],
- pool, i, j);
+ for (i = 0; i <TTM_NUM_CACHING_TYPES; ++i) {
+ for (j = 0; j <NR_PAGE_ORDERS; ++j) {
+ structttm_pool_type*pt;drivers/gpu/drm/ttm/ttm_pool.c +8
-0+ + /* Initialize only pool types which are actually used */ + pt = ttm_pool_select_type(pool, i, j); + if (pt != &pool->caching[i].orders[j]) + continue; + + ttm_pool_type_init(pt, pool, i, j); + }}
}
EXPORT_SYMBOL(ttm_pool_init);drivers/gpu/drm/ttm/ttm_pool.c +10
-3@@ -599,10 +611,16 @@ void ttm_pool_fini(struct ttm_pool *pool) { unsigned int i, j; - if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) { - for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) - for (j = 0; j < NR_PAGE_ORDERS; ++j) -ttm_pool_type_fini (&pool->caching[i].orders[j]); + for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) { + for (j = 0; j < NR_PAGE_ORDERS; ++j) { + struct ttm_pool_type *pt; + + pt = ttm_pool_select_type(pool, i, j); + if (pt != &pool->caching[i].orders[j]) + continue; + + ttm_pool_type_fini(pt); + } } /* We removed the pool types from the LRU, but we need to also make sure