Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/ttm: Fix GPU MM stats during pool shrinking

TTM pool shrinking frees pages by calling __free_pages() directly,
which bypasses updates to NR_GPU_ACTIVE and leaves GPU MM accounting
out of sync.

Introduce a helper, __free_pages_gpu_account(), and use it for all page
frees in ttm_pool.c so GPU MM statistics are updated consistently.

Reported-by: Kenneth Crudup <kenny@panix.com>
Fixes: ae80122f3896 ("drm/ttm: use gpu mm stats to track gpu memory allocations. (v4)")
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: David Airlie <airlied@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Tested-by: Kenneth Crudup <kenny@panix.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: https://patch.msgid.link/20260502065338.2720646-1-matthew.brost@intel.com

+12 -6
+12 -6
drivers/gpu/drm/ttm/ttm_pool.c
··· 206 206 return NULL; 207 207 } 208 208 209 + static void __free_pages_gpu_account(struct page *p, unsigned int order, 210 + bool reclaim) 211 + { 212 + mod_lruvec_page_state(p, reclaim ? NR_GPU_RECLAIM : NR_GPU_ACTIVE, 213 + -(1 << order)); 214 + __free_pages(p, order); 215 + } 216 + 209 217 /* Reset the caching and pages of size 1 << order */ 210 218 static void ttm_pool_free_page(struct ttm_pool *pool, enum ttm_caching caching, 211 219 unsigned int order, struct page *p, bool reclaim) ··· 231 223 #endif 232 224 233 225 if (!pool || !ttm_pool_uses_dma_alloc(pool)) { 234 - mod_lruvec_page_state(p, reclaim ? NR_GPU_RECLAIM : NR_GPU_ACTIVE, 235 - -(1 << order)); 236 - __free_pages(p, order); 226 + __free_pages_gpu_account(p, order, reclaim); 237 227 return; 238 228 } 239 229 ··· 612 606 */ 613 607 ttm_pool_split_for_swap(restore->pool, p); 614 608 copy_highpage(restore->alloced_page + i, p); 615 - __free_pages(p, 0); 609 + __free_pages_gpu_account(p, 0, false); 616 610 } 617 611 618 612 restore->restored_pages++; ··· 1074 1068 if (flags->purge) { 1075 1069 shrunken += num_pages; 1076 1070 page->private = 0; 1077 - __free_pages(page, order); 1071 + __free_pages_gpu_account(page, order, false); 1078 1072 memset(tt->pages + i, 0, 1079 1073 num_pages * sizeof(*tt->pages)); 1080 1074 } ··· 1115 1109 } 1116 1110 handle = shandle; 1117 1111 tt->pages[i] = ttm_backup_handle_to_page_ptr(handle); 1118 - put_page(page); 1112 + __free_pages_gpu_account(page, 0, false); 1119 1113 shrunken++; 1120 1114 } 1121 1115