[PATCH 00/11] mm/cma: charge cma allocation to memcg using per area counters
From: Eric Chanudet
Date: Fri Aug 21 2026 - 14:57:59 EST
CMA allocations are currently unaccounted for by cgroup memory
controllers. As system resources, they should fall under memcg, but CMA
areas partition the available space for different purposes and memcg
doesn't have a good representation for that.
Add a memory_cma_accounting cgroupfs option in preparation for the
following new behavior. Make it disabled by default since it will
account for CMA allocations in memcg which may affect existing systems.
Provide CMA charge/uncharge functions to memcg that introduce a CMA area
specific counter per CMA area. Charges are issued to memcg and to a page
counter for the CMA area used. The allocation's folios are marked with
the cgroup via commit_charge() (once for large folios, per-page for
0-order ones) so they can be later uncharged correctly.
Add the new memcg calls into the cma allocator under __cma_alloc_frozen,
for both cma and hugetlb_cma allocations accounting.
Finally register the per-area usage counters in the cgroupfs. Each CMA
area creates a memory.cma.<area>.{current,max} pair for reporting and
limitation for each area.
Selftests and a vmtest script are added to this series for convenience.
The tests are simple accounting and limit enforcement verification using
the default reserved CMA area (cma=) and hugetlb_cma.
Signed-off-by: Eric Chanudet <echanude@xxxxxxxxxx>
---
Eric Chanudet (11):
mm/cma: drop const for struct page on release API
mm/cma: include linux/cma.h in cma.h
cgroup: add memory_cma_accounting mount option
memcg: add cma charge/uncharge functions for area counters
mm/cma: charge cma allocation to memcg per area counters
memcg: register per-area usage counters in cgroupfs
selftests: cgroup: add cma configs for cgroup selftest suite
selftests: cgroup: add memcg cma tests
selftests: cgroup: add a vmtest script for memcg
selftests: cgroup: add memcg hugetlb_cma tests
selftests: cgroup: amend vmtest-memcg to run the hugetlb cma tests
Documentation/admin-guide/cgroup-v2.rst | 35 +++
include/linux/cgroup-defs.h | 5 +
include/linux/cma.h | 4 +-
include/linux/memcontrol.h | 19 ++
kernel/cgroup/cgroup.c | 15 +-
mm/cma.c | 14 +-
mm/cma.h | 6 +
mm/cma_debug.c | 1 -
mm/cma_sysfs.c | 1 -
mm/memcontrol.c | 205 ++++++++++++
tools/testing/selftests/cgroup/.gitignore | 1 +
tools/testing/selftests/cgroup/Makefile | 2 +
tools/testing/selftests/cgroup/config | 5 +
tools/testing/selftests/cgroup/test_cma_memcg.c | 402 ++++++++++++++++++++++++
tools/testing/selftests/cgroup/vmtest-memcg.sh | 197 ++++++++++++
15 files changed, 903 insertions(+), 9 deletions(-)
---
base-commit: 98f21c54f99519329c18e2625b0ea6db14524d09
change-id: 20260706-cma-memcg-regions-696cb5ef7998
Best regards,
--
Eric Chanudet <echanude@xxxxxxxxxx>