Re: [PATCH v2 0/3] dma-buf: heaps: cma: enable dmem cgroup accounting

From: Eric Chanudet

Date: Mon Feb 23 2026 - 14:40:06 EST


On Fri, Feb 20, 2026 at 10:45:08AM +0100, Christian König wrote:
> On 2/20/26 02:14, T.J. Mercier wrote:
> > On Wed, Feb 18, 2026 at 9:15 AM Eric Chanudet <echanude@xxxxxxxxxx> wrote:
> >
> > Hi Eric,
> >
> >> An earlier series[1] from Maxime introduced dmem to the cma allocator in
> >> an attempt to use it generally for dma-buf. Restart from there and apply
> >> the charge in the narrower context of the CMA dma-buf heap instead.
> >>
> >> In line with introducing cgroup to the system heap[2], this behavior is
> >> enabled based on dma_heap.mem_accounting, disabled by default.
> >>
> >> dmem is chosen for CMA heaps as it allows limits to be set for each
> >> region backing each heap. The charge is only put in the dma-buf heap for
> >> now as it guaranties it can be accounted against a userspace process
> >> that requested the allocation.
> >
> > But CMA memory is system memory, and regular (non-CMA) movable
> > allocations can occur out of these CMA areas. So this splits system
> > memory accounting between memcg (from [2]) and dmem. If I want to put
> > a limit on system memory use I have to adjust multiple limits (memcg +
> > dmems) and know how to divide the total between them all.
> >
> > How do you envision using this combination of different controllers?

We are trying to control each CMA heap use of their CMA regions.

Regular allocation would be migrated out should CMA allocation require
some space already taken in the region (bare, I suppose, if these end up
pinned...) so I didn't think it needed to account for these in dmem.

As for accounting for CMA allocations in memcg, I suppose that's the
question prior discussions explored as well.

> Yeah we have this problem pretty much everywhere.
>
> There are both use cases where you want to account device allocations to memcg and when you don't want that.
>
> From what I know at the moment it would be best if the administrator could say for each dmem if it should account additionally to memcg or not.
>
> Using module parameters to enable/disable it globally is just a workaround as far as I can see.
>

So, for example, adding a dmem knob so one can:
echo "cma/reserved $SIZE" > /sys/fs/cgroup/user.slice/dmem.max
echo "cma/reserved 1" > /sys/fs/cgroup/user.slice/dmem.charge_memcg

I'll take a look.

> Regards,
> Christian.
>
> >
> > Thanks,
> > T.J.
> >
> >> [1] https://lore.kernel.org/all/20250310-dmem-cgroups-v1-0-2984c1bc9312@xxxxxxxxxx/
> >> [2] https://lore.kernel.org/all/20260116-dmabuf-heap-system-memcg-v3-0-ecc6b62cc446@xxxxxxxxxx/
> >>
> >> Signed-off-by: Eric Chanudet <echanude@xxxxxxxxxx>
> >> ---
> >> Changes in v2:
> >> - Rebase on Maxime's introduction of dmem to the cma allocator:
> >> https://lore.kernel.org/all/20250310-dmem-cgroups-v1-0-2984c1bc9312@xxxxxxxxxx/
> >> - Remove the dmem region registration from the cma dma-buf heap
> >> - Remove the misplaced logic for the default region.
> >> - Link to v1: https://lore.kernel.org/r/20260130-dmabuf-heap-cma-dmem-v1-1-3647ea993e99@xxxxxxxxxx
> >>
> >> ---
> >> Eric Chanudet (1):
> >> dma-buf: heaps: cma: charge each cma heap's dmem
> >>
> >> Maxime Ripard (2):
> >> cma: Register dmem region for each cma region
> >> cma: Provide accessor to cma dmem region
> >>
> >> drivers/dma-buf/heaps/cma_heap.c | 15 ++++++++++++++-
> >> include/linux/cma.h | 9 +++++++++
> >> mm/cma.c | 20 +++++++++++++++++++-
> >> mm/cma.h | 3 +++
> >> 4 files changed, 45 insertions(+), 2 deletions(-)
> >> ---
> >> base-commit: 948e195dfaa56e48eabda591f97630502ff7e27e
> >> change-id: 20260128-dmabuf-heap-cma-dmem-f4120a2df4a8
> >>
> >> Best regards,
> >> --
> >> Eric Chanudet <echanude@xxxxxxxxxx>
> >>
>

--
Eric Chanudet