[PATCH 08/17] memcg: add support for GPU page counters.

David Airlie airlied at redhat.com
Thu Jul 3 05:43:35 UTC 2025


On Thu, Jul 3, 2025 at 2:06 AM Shakeel Butt <shakeel.butt at linux.dev> wrote:
>
> On Mon, Jun 30, 2025 at 02:49:27PM +1000, Dave Airlie wrote:
> > From: Dave Airlie <airlied at redhat.com>
> >
> > This introduces 2 new statistics and 3 new memcontrol APIs for dealing
> > with GPU system memory allocations.
> >
> > The stats corresponds to the same stats in the global vmstat,
> > for number of active GPU pages, and number of pages in pools that
> > can be reclaimed.
> >
> > The first API charges a order of pages to a objcg, and sets
> > the objcg on the pages like kmem does, and updates the active/reclaim
> > statistic.
> >
> > The second API uncharges a page from the obj cgroup it is currently charged
> > to.
> >
> > The third API allows moving a page to/from reclaim and between obj cgroups.
> > When pages are added to the pool lru, this just updates accounting.
> > When pages are being removed from a pool lru, they can be taken from
> > the parent objcg so this allows them to be uncharged from there and transferred
> > to a new child objcg.
> >
> > Signed-off-by: Dave Airlie <airlied at redhat.com>
> > ---
> >  Documentation/admin-guide/cgroup-v2.rst |   6 ++
> >  include/linux/memcontrol.h              |  14 +++
> >  mm/memcontrol.c                         | 110 ++++++++++++++++++++++++
> >  3 files changed, 130 insertions(+)
> >
> > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
> > index 0cc35a14afbe..d6f057c4fe2e 100644
> > --- a/Documentation/admin-guide/cgroup-v2.rst
> > +++ b/Documentation/admin-guide/cgroup-v2.rst
> > @@ -1542,6 +1542,12 @@ The following nested keys are defined.
> >         vmalloc (npn)
> >               Amount of memory used for vmap backed memory.
> >
> > +       gpu (npn)
> > +             Amount of system memory used for GPU devices.
> > +
> > +       gpu_reclaim (npn)
> > +             Amount of system memory cached for GPU devices.
> > +
> >         shmem
> >               Amount of cached filesystem data that is swap-backed,
> >               such as tmpfs, shm segments, shared anonymous mmap()s
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 87b6688f124a..ff82d603910d 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -36,6 +36,8 @@ enum memcg_stat_item {
> >       MEMCG_SOCK,
> >       MEMCG_PERCPU_B,
> >       MEMCG_VMALLOC,
> > +     MEMCG_GPU,
> > +     MEMCG_GPU_RECLAIM,
>
> You already added node level counters i.e. GPUActive & GPUReclaim, just
> use those instead of these. Add them to memcg_node_stat_items[].
>

Thanks for the pointer, yes I did mess that up, I've rewrote it
locally today and it makes more sense now.

Dave.



More information about the dri-devel mailing list