On Mon, Jun 30, 2025 at 02:49:21PM +1000, Dave Airlie wrote: > From: Dave Airlie <[email protected]> > > This uses the newly introduced per-node gpu tracking stats, > to track GPU memory allocated via TTM and reclaimable memory in > the TTM page pools. > > These stats will be useful later for system information and > later when mem cgroups are integrated. > > Cc: Christian Koenig <[email protected]> > Cc: Matthew Brost <[email protected]> > Cc: Johannes Weiner <[email protected]> > Cc: [email protected] > Cc: Andrew Morton <[email protected]> > Signed-off-by: Dave Airlie <[email protected]> > > --- > v2: add reclaim parameters and adjust the right counters. > --- > drivers/gpu/drm/ttm/ttm_pool.c | 34 ++++++++++++++++++++++++++++------ > 1 file changed, 28 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c > index baf27c70a419..11a5777b4a85 100644 > --- a/drivers/gpu/drm/ttm/ttm_pool.c > +++ b/drivers/gpu/drm/ttm/ttm_pool.c > @@ -131,6 +131,16 @@ static struct list_head shrinker_list; > static struct shrinker *mm_shrinker; > static DECLARE_RWSEM(pool_shrink_rwsem); > > +/* helper to get a current valid node id from a pool */ > +static int ttm_pool_nid(struct ttm_pool *pool) { > + int nid = NUMA_NO_NODE; > + if (pool) > + nid = pool->nid; > + if (nid == NUMA_NO_NODE) > + nid = numa_node_id(); > + return nid; > +} > + > /* Allocate pages of size 1 << order with the given gfp_flags */ > static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t > gfp_flags, > unsigned int order) > @@ -150,8 +160,10 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool > *pool, gfp_t gfp_flags, > > if (!pool->use_dma_alloc) { > p = alloc_pages_node(pool->nid, gfp_flags, order); > - if (p) > + if (p) { > p->private = order; > + mod_node_page_state(NODE_DATA(ttm_pool_nid(pool)), > NR_GPU_ACTIVE, (1 << order));
Use mod_lruvec_page_state(), it will handle both cases of charged and uncharged pages.
