Skip to content

memcg: group struct fields by access pattern

Shakeel Butt cgroups linux-mm lkml 1 version Applied

Status from this message: [merged mm-stable] memcg-group-the-fields-of-struct-mem_cgroup_per_node.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 1 replyApplied 6/6

Patches in v1 All 6 applied

#Subject and filesSizeRepliesApplied
1/6memcg: move per-node objcg to the read-mostly fieldsinclude/linux/memcontrol.h+2 -30 repliesApplied
2/6memcg: split mem_cgroup_private_id into two fieldsinclude/linux/memcontrol.h mm/memcontrol.c+12 -160 repliesApplied
3/6memcg: group the write-hot fields of struct mem_cgroupinclude/linux/memcontrol.h mm/memcontrol.c+66 -250 repliesApplied
4/6memcg: group the cold fields of struct mem_cgroupinclude/linux/memcontrol.h mm/memcontrol.c+53 -210 repliesApplied
5/6memcg: group the read-mostly fields of struct mem_cgroupinclude/linux/memcontrol.h mm/memcontrol.c+52 -270 repliesApplied
6/6memcg: group the fields of struct mem_cgroup_per_nodeinclude/linux/memcontrol.h mm/memcontrol.c+52 -100 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/6] memcg: group struct fields by access pattern

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

Signature · 1 line
2.53.0-Meta