Re: [PATCH 0/6] memcg: group struct fields by access pattern
From: Andrew Morton
Date: Sat Sep 05 2026 - 19:34:26 EST
On Fri, 4 Sep 2026 20:05:16 -0700 Shakeel Butt <shakeel.butt@xxxxxxxxx> wrote:
> 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.
>
> ...
>
> 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.
Sounds smart.
Significant repair work was needed for the struct mem_cgroup_per_node
and struct mem_cgroup alterations, due to the below pending changes. I
think I got it all, please check.
--- linux-7.3-rc1/include/linux/memcontrol.h 2026-08-30 04:44:06.000000000 -0700
+++ 25/include/linux/memcontrol.h 2026-09-05 16:31:03.119571612 -0700
@@ -95,25 +95,12 @@ struct mem_cgroup_per_node {
struct lruvec_stats *lruvec_stats;
struct shrinker_info __rcu *shrinker_info;
-#ifdef CONFIG_MEMCG_V1
- /*
- * Memcg-v1 only stuff in middle as buffer between read mostly fields
- * and update often fields to avoid false sharing. If v1 stuff is
- * not present, an explicit padding is needed.
- */
-
- struct rb_node tree_node; /* RB tree node */
- unsigned long usage_in_excess;/* Set to the value by which */
- /* the soft limit is exceeded*/
- bool on_tree;
-#else
CACHELINE_PADDING(_pad1_);
-#endif
/* Fields which get updated often at the end. */
struct lruvec lruvec;
CACHELINE_PADDING(_pad2_);
- unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS];
+ long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS];
struct mem_cgroup_reclaim_iter iter;
/*
@@ -293,8 +280,6 @@ struct mem_cgroup {
struct memcg1_events_percpu __percpu *events_percpu;
- unsigned long soft_limit;
-
/* protected by memcg_oom_lock */
bool oom_lock;
int under_oom;