Skip to content

Commit 322458c

Browse files
author
Thomas Hellström
committed
drm/ttm: Reduce the number of used allocation orders for TTM pages
When swapping out, we will split multi-order pages both in order to move them to the swap-cache and to be able to return memory to the swap cache as soon as possible on a page-by-page basis. Reduce the page max order to the system PMD size, as we can then be nicer to the system and avoid splitting gigantic pages. Looking forward to when we might be able to swap out PMD size folios without splitting, this will also be a benefit. v2: - Include all orders up to the PMD size (Christian König) v3: - Avoid compilation errors for architectures with special PFN_SHIFTs Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230404200650.11043-3-thomas.hellstrom@linux.intel.com
1 parent 379989e commit 322458c

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

drivers/gpu/drm/ttm/ttm_pool.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747

4848
#include "ttm_module.h"
4949

50+
#define TTM_MAX_ORDER (PMD_SHIFT - PAGE_SHIFT)
51+
#define __TTM_DIM_ORDER (TTM_MAX_ORDER + 1)
52+
/* Some architectures have a weird PMD_SHIFT */
53+
#define TTM_DIM_ORDER (__TTM_DIM_ORDER <= MAX_ORDER ? __TTM_DIM_ORDER : MAX_ORDER)
54+
5055
/**
5156
* struct ttm_pool_dma - Helper object for coherent DMA mappings
5257
*
@@ -65,11 +70,11 @@ module_param(page_pool_size, ulong, 0644);
6570

6671
static atomic_long_t allocated_pages;
6772

68-
static struct ttm_pool_type global_write_combined[MAX_ORDER];
69-
static struct ttm_pool_type global_uncached[MAX_ORDER];
73+
static struct ttm_pool_type global_write_combined[TTM_DIM_ORDER];
74+
static struct ttm_pool_type global_uncached[TTM_DIM_ORDER];
7075

71-
static struct ttm_pool_type global_dma32_write_combined[MAX_ORDER];
72-
static struct ttm_pool_type global_dma32_uncached[MAX_ORDER];
76+
static struct ttm_pool_type global_dma32_write_combined[TTM_DIM_ORDER];
77+
static struct ttm_pool_type global_dma32_uncached[TTM_DIM_ORDER];
7378

7479
static spinlock_t shrinker_lock;
7580
static struct list_head shrinker_list;
@@ -444,7 +449,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
444449
else
445450
gfp_flags |= GFP_HIGHUSER;
446451

447-
for (order = min_t(unsigned int, MAX_ORDER - 1, __fls(num_pages));
452+
for (order = min_t(unsigned int, TTM_MAX_ORDER, __fls(num_pages));
448453
num_pages;
449454
order = min_t(unsigned int, order, __fls(num_pages))) {
450455
struct ttm_pool_type *pt;
@@ -563,7 +568,7 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
563568

564569
if (use_dma_alloc) {
565570
for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i)
566-
for (j = 0; j < MAX_ORDER; ++j)
571+
for (j = 0; j < TTM_DIM_ORDER; ++j)
567572
ttm_pool_type_init(&pool->caching[i].orders[j],
568573
pool, i, j);
569574
}
@@ -583,7 +588,7 @@ void ttm_pool_fini(struct ttm_pool *pool)
583588

584589
if (pool->use_dma_alloc) {
585590
for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i)
586-
for (j = 0; j < MAX_ORDER; ++j)
591+
for (j = 0; j < TTM_DIM_ORDER; ++j)
587592
ttm_pool_type_fini(&pool->caching[i].orders[j]);
588593
}
589594

@@ -637,7 +642,7 @@ static void ttm_pool_debugfs_header(struct seq_file *m)
637642
unsigned int i;
638643

639644
seq_puts(m, "\t ");
640-
for (i = 0; i < MAX_ORDER; ++i)
645+
for (i = 0; i < TTM_DIM_ORDER; ++i)
641646
seq_printf(m, " ---%2u---", i);
642647
seq_puts(m, "\n");
643648
}
@@ -648,7 +653,7 @@ static void ttm_pool_debugfs_orders(struct ttm_pool_type *pt,
648653
{
649654
unsigned int i;
650655

651-
for (i = 0; i < MAX_ORDER; ++i)
656+
for (i = 0; i < TTM_DIM_ORDER; ++i)
652657
seq_printf(m, " %8u", ttm_pool_type_count(&pt[i]));
653658
seq_puts(m, "\n");
654659
}
@@ -751,13 +756,16 @@ int ttm_pool_mgr_init(unsigned long num_pages)
751756
{
752757
unsigned int i;
753758

759+
BUILD_BUG_ON(TTM_DIM_ORDER > MAX_ORDER);
760+
BUILD_BUG_ON(TTM_DIM_ORDER < 1);
761+
754762
if (!page_pool_size)
755763
page_pool_size = num_pages;
756764

757765
spin_lock_init(&shrinker_lock);
758766
INIT_LIST_HEAD(&shrinker_list);
759767

760-
for (i = 0; i < MAX_ORDER; ++i) {
768+
for (i = 0; i < TTM_DIM_ORDER; ++i) {
761769
ttm_pool_type_init(&global_write_combined[i], NULL,
762770
ttm_write_combined, i);
763771
ttm_pool_type_init(&global_uncached[i], NULL, ttm_uncached, i);
@@ -790,7 +798,7 @@ void ttm_pool_mgr_fini(void)
790798
{
791799
unsigned int i;
792800

793-
for (i = 0; i < MAX_ORDER; ++i) {
801+
for (i = 0; i < TTM_DIM_ORDER; ++i) {
794802
ttm_pool_type_fini(&global_write_combined[i]);
795803
ttm_pool_type_fini(&global_uncached[i]);
796804

0 commit comments

Comments
 (0)