[PATCH 0/6] memcg: group struct fields by access pattern
From: Shakeel Butt
Date: Fri Sep 04 2026 - 23:07:53 EST
Every so often we get a memcg performance regression caused by nothing
more than a field moving. Someone adds a field, removes one, or puts a
few behind a config option. The layout shifts, fields with different
access patterns land on the same cache line, and a bot reports a
regression.
Two examples. commit 98c9daf5ae6b ("mm: memcg: guard memcg1-specific
members of struct mem_cgroup_per_node") moved lruvec next to
lru_zone_size[] and needed commit f59adcf59332 ("mm: memcg: add
cacheline padding after lruvec in mem_cgroup_per_node") to fix it.
commit c1afbd5de131 ("mm/memcontrol: avoid false sharing between
vmstats and events") had to add ____cacheline_aligned_in_smp for the
same reason.
Each fix was correct but nothing stops the next field addition
from undoing it.
This series makes the layout a contract the compiler checks, the same
way struct net_device does it. Fields are sorted into named cache line
groups by access pattern, and memcg_struct_check() verifies at build
time that every field sits in its group. A field added in the wrong
place now breaks the build instead of quietly costing a few percent.
struct mem_cgroup gets three groups:
memcg_write_hot written on the charge, reclaim and socket paths
memcg_cold only the cgroup control paths touch these
memcg_read_mostly set when the memcg is created, then only read
Testing
=======
The cgroup selftests give identical results with and without the series.
For performance, two identical 30 core Xeon machines each ran both
kernels, with the boot order swapped between them so that machine and
order effects cancel. The useful tests run two workloads at once in one
cgroup, because false sharing only shows up when one side reads a field
that the other side writes.
slab allocs + page faults, slab side +1.2%
page faults + memory.stat readers, fault side +1.3%
page faults + memory.stat readers, reader side +0.8%
everything else no change
No test regressed. The gains are small but the point of the series is
the build time contract.
Shakeel Butt (6):
memcg: move per-node objcg to the read-mostly fields
memcg: split mem_cgroup_private_id into two fields
memcg: group the write-hot fields of struct mem_cgroup
memcg: group the cold fields of struct mem_cgroup
memcg: group the read-mostly fields of struct mem_cgroup
memcg: group the fields of struct mem_cgroup_per_node
include/linux/memcontrol.h | 169 ++++++++++++++++++++++---------------
mm/memcontrol.c | 122 ++++++++++++++++++++++++--
2 files changed, 213 insertions(+), 78 deletions(-)
base-commit: 817d340204c513316223ba084615f5906ac49ddb
--
2.53.0-Meta