From: Tao Cui The legacy cgroup v1 memory controller keeps its state as individual members guarded by CONFIG_MEMCG_V1 inside struct mem_cgroup. While the v1 implementation already lives in mm/memcontrol-v1.c and its interface is behind CONFIG_MEMCG_V1, its data is still intermixed with the shared layout of struct mem_cgroup. Group the v1-only members into a dedicated struct mem_cgroup_v1 and embed it via a union whose anonymous side reproduces the historical layout. All existing memcg->X accesses keep compiling and the binary layout is unchanged. The anonymous side is dropped by the next patch once the access sites are converted. No functional change. Signed-off-by: Tao Cui --- include/linux/memcontrol.h | 97 ++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 46bf724cae7a..beb68f39c321 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -193,6 +193,43 @@ struct obj_cgroup { * statistics based on the statistics developed by Rik Van Riel for clock-pro, * to help the administrator determine what knobs to tune. */ +/* + * Legacy cgroup v1 memory controller state, used only by the v1 + * interface (mm/memcontrol-v1.c). + */ +struct mem_cgroup_v1 { + struct page_counter kmem; + struct page_counter tcpmem; + + struct memcg1_events_percpu __percpu *events_percpu; + + /* protected by memcg_oom_lock */ + bool oom_lock; + int under_oom; + + int oom_kill_disable; + + struct mutex thresholds_lock; + + /* RCU-protected */ + struct mem_cgroup_thresholds thresholds; + + /* RCU-protected */ + struct mem_cgroup_thresholds memsw_thresholds; + + /* For oom notifier event fd */ + struct list_head oom_notify; + + bool tcpmem_active; + int tcpmem_pressure; + + /* List of events which userspace want to receive */ + struct list_head event_list; + spinlock_t event_list_lock; + + int swappiness; +}; + struct mem_cgroup { struct cgroup_subsys_state css; @@ -271,42 +308,50 @@ struct mem_cgroup { __cacheline_group_end_aligned(memcg_cold); #ifdef CONFIG_MEMCG_V1 - /* v1 only. Not grouped: v1 is legacy, sorting it is not worth it. */ + /* + * Transitional: the anonymous struct reproduces the historical layout + * so existing memcg->X accesses keep compiling; it is removed once the + * access sites are converted to memcg->v1.X. + */ + union { + struct mem_cgroup_v1 v1; + struct { + /* Legacy consumer-oriented counters */ + struct page_counter kmem; /* v1 only */ + struct page_counter tcpmem; /* v1 only */ - /* Legacy consumer-oriented counters */ - struct page_counter kmem; /* v1 only */ - struct page_counter tcpmem; /* v1 only */ + struct memcg1_events_percpu __percpu *events_percpu; - struct memcg1_events_percpu __percpu *events_percpu; + /* protected by memcg_oom_lock */ + bool oom_lock; + int under_oom; - /* protected by memcg_oom_lock */ - bool oom_lock; - int under_oom; + /* OOM-Killer disable */ + int oom_kill_disable; - /* OOM-Killer disable */ - int oom_kill_disable; + /* protect arrays of thresholds */ + struct mutex thresholds_lock; - /* protect arrays of thresholds */ - struct mutex thresholds_lock; + /* thresholds for memory usage. RCU-protected */ + struct mem_cgroup_thresholds thresholds; - /* thresholds for memory usage. RCU-protected */ - struct mem_cgroup_thresholds thresholds; - - /* thresholds for mem+swap usage. RCU-protected */ - struct mem_cgroup_thresholds memsw_thresholds; + /* thresholds for mem+swap usage. RCU-protected */ + struct mem_cgroup_thresholds memsw_thresholds; - /* For oom notifier event fd */ - struct list_head oom_notify; + /* For oom notifier event fd */ + struct list_head oom_notify; - /* Legacy tcp memory accounting */ - bool tcpmem_active; - int tcpmem_pressure; + /* Legacy tcp memory accounting */ + bool tcpmem_active; + int tcpmem_pressure; - /* List of events which userspace want to receive */ - struct list_head event_list; - spinlock_t event_list_lock; + /* List of events which userspace want to receive */ + struct list_head event_list; + spinlock_t event_list_lock; - int swappiness; + int swappiness; + }; + }; #endif /* CONFIG_MEMCG_V1 */ /* -- 2.43.0