mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: hannes@cmpxchg.org, mhocko@kernel.org
Cc: roman.gushchin@linux.dev, shakeel.butt@linux.dev,
	muchun.song@linux.dev, cgroups@vger.kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	cui.tao@linux.dev, Tao Cui <cuitao@kylinos.cn>
Subject: [PATCH 1/3] mm, memcg: introduce struct mem_cgroup_v1
Date: Wed, 16 Sep 2026 20:57:35 +0800	[thread overview]
Message-ID: <20260916125737.1095414-2-cui.tao@linux.dev> (raw)
In-Reply-To: <20260916125737.1095414-1-cui.tao@linux.dev>

From: Tao Cui <cuitao@kylinos.cn>

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 <cuitao@kylinos.cn>
---
 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


  reply	other threads:[~2026-09-16 12:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 12:57 [RFC PATCH 0/3] mm, memcg: isolate deprecated v1 state from struct mem_cgroup Tao Cui
2026-09-16 12:57 ` Tao Cui [this message]
2026-09-16 12:57 ` [PATCH 2/3] mm, memcg: move v1-only members into mem_cgroup_v1 Tao Cui
2026-09-16 12:57 ` [PATCH 3/3] docs: cgroup-v1: note the v1 memory controller implementation boundary Tao Cui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916125737.1095414-2-cui.tao@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=cuitao@kylinos.cn \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®