[PATCH 02/17] drm/ttm: use gpu mm stats to track gpu memory allocations. (v2)
David Airlie
airlied at redhat.com
Tue Jul 1 01:41:31 UTC 2025
On Mon, Jun 30, 2025 at 8:04 PM Christian König
<christian.koenig at amd.com> wrote:
>
> On 30.06.25 06:49, Dave Airlie wrote:
> > From: Dave Airlie <airlied at redhat.com>
> >
> > 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 <christian.koenig at amd.com>
> > Cc: Matthew Brost <matthew.brost at intel.com>
> > Cc: Johannes Weiner <hannes at cmpxchg.org>
> > Cc: linux-mm at kvack.org
> > Cc: Andrew Morton <akpm at linux-foundation.org>
> > Signed-off-by: Dave Airlie <airlied at redhat.com>
> >
> > ---
> > 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();
>
> That isn't correct.
>
> The NUMA node in the pool is just a hint where to allocate from, but the memory can come from somewhere else as well.
>
> You need to look at the allocated page to figure out to which NUMA node that belongs.
Indeed, I've killed this from here, using page_to_nid is correct.
This helper is needed later to figure out what nid to ask the list_lru
for pages from, but I've move it forward into that patch locally.
Dave.
More information about the dri-devel
mailing list