]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/ttm: Allow drivers to specify maximum beneficial TTM pool size
authorTvrtko Ursulin <tvrtko.ursulin@igalia.com>
Mon, 20 Oct 2025 11:54:09 +0000 (12:54 +0100)
committerTvrtko Ursulin <tursulin@ursulin.net>
Fri, 31 Oct 2025 09:14:50 +0000 (09:14 +0000)
GPUs typically benefit from contiguous memory via reduced TLB pressure and
improved caching performance, where the maximum size of contiguous block
which adds a performance benefit is related to hardware design.

TTM pool allocator by default tries (hard) to allocate up to the system
MAX_PAGE_ORDER blocks. This varies by the CPU platform and can also be
configured via Kconfig.

If that limit was set to be higher than the GPU can make an extra use of,
lets allow the individual drivers to let TTM know over which allocation
order can the pool allocator afford to make a little bit less effort with.

We implement this by disabling direct reclaim for those allocations, which
reduces the allocation latency and lowers the demands on the page
allocator, in cases where expending this effort is not critical for the
GPU in question.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://lore.kernel.org/r/20251020115411.36818-5-tvrtko.ursulin@igalia.com
drivers/gpu/drm/ttm/ttm_pool.c
drivers/gpu/drm/ttm/ttm_pool_internal.h
include/drm/ttm/ttm_allocation.h

index 4fc69447060cdc28026327b966585d472ab9cf7e..97e9ce505cf68dd308790d867390ba9fc3843ccf 100644 (file)
@@ -136,6 +136,7 @@ static DECLARE_RWSEM(pool_shrink_rwsem);
 static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
                                        unsigned int order)
 {
+       const unsigned int beneficial_order = ttm_pool_beneficial_order(pool);
        unsigned long attr = DMA_ATTR_FORCE_CONTIGUOUS;
        struct ttm_pool_dma *dma;
        struct page *p;
@@ -149,6 +150,13 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
                gfp_flags |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN |
                        __GFP_THISNODE;
 
+       /*
+        * Do not add latency to the allocation path for allocations orders
+        * device tolds us do not bring them additional performance gains.
+        */
+       if (beneficial_order && order > beneficial_order)
+               gfp_flags &= ~__GFP_DIRECT_RECLAIM;
+
        if (!ttm_pool_uses_dma_alloc(pool)) {
                p = alloc_pages_node(pool->nid, gfp_flags, order);
                if (p)
index 96b7f21514fb483044ef719c38f915eb5f1969d4..82c4b7e56a99d5dc1781cf80ca51eb08b2bf28ca 100644 (file)
@@ -17,4 +17,9 @@ static inline bool ttm_pool_uses_dma32(struct ttm_pool *pool)
        return pool->alloc_flags & TTM_ALLOCATION_POOL_USE_DMA32;
 }
 
+static inline bool ttm_pool_beneficial_order(struct ttm_pool *pool)
+{
+       return pool->alloc_flags & 0xff;
+}
+
 #endif
index 7869dc32bd910451c74b9ecbc88c8b173d860fe1..8f85447603067006c375d2859ef65abd7cd3c7e6 100644 (file)
@@ -4,7 +4,8 @@
 #ifndef _TTM_ALLOCATION_H_
 #define _TTM_ALLOCATION_H_
 
-#define TTM_ALLOCATION_POOL_USE_DMA_ALLOC      BIT(0) /* Use coherent DMA allocations. */
-#define TTM_ALLOCATION_POOL_USE_DMA32          BIT(1) /* Use GFP_DMA32 allocations. */
+#define TTM_ALLOCATION_POOL_BENEFICIAL_ORDER(n)        ((n) & 0xff) /* Max order which caller can benefit from */
+#define TTM_ALLOCATION_POOL_USE_DMA_ALLOC      BIT(8) /* Use coherent DMA allocations. */
+#define TTM_ALLOCATION_POOL_USE_DMA32          BIT(9) /* Use GFP_DMA32 allocations. */
 
 #endif