Skip to contentSkip to conversation

memcg-move-memcg-private-id-refcount-to-objcg.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Oct 24

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: memcg: move memcg private ID refcount to objcg
has been removed from the -mm tree. Its filename was
memcg-move-memcg-private-id-refcount-to-objcg.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Bingfang Guo <[email protected]>
Subject: memcg: move memcg private ID refcount to objcg
Date: Mon, 21 Sep 2026 14:16:27 +0800

The memcg private ID is used by objects that can't afford storing a whole pointer and can outlive memcgs to track the memcg (notably swap entries). The current design holds a refcount to the css, preventing the memcg from being freed.

This patch unbinds the lifetime of memcgid from the memcg so it can be freed. The idea is to move the refcount of memcgid to one of the memcg's objcg. The objcg is stored in the global memcgid xarray instead and used for retrieving the online memcg from it. So swapped out pages no longer pin the dying memcg.

After the change, a memcgid can refer to a non present memcg. To handle this situation, when trying to get the original memcg from the id, compare the memcgid passed in with that of the memcg, and return NULL to indicate its death if they differ. NULL checks are added for list_lru_walk_node(), workingset_test_recent() to skip dead memcgs. For MGLRU recency test, mem_cgroup_lruvec() will substitute NULL with root_mem_cgroup.

In the earlier patch, an extra xarray lookup was introduced in swap uncharging path. Now that we have the objcg pointer in the function, the extra overhead can be removed by using it for putting directly.

---

 include/linux/memcontrol.h |    7 +--
 mm/list_lru.c              |    2 
 mm/memcontrol.c            |   73 +++++++++++++++++++++++++----------
 mm/workingset.c            |    2 
 4 files changed, 60 insertions(+), 24 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~memcg-move-memcg-private-id-refcount-to-objcg +4 -3
@@ -180,6 +180,7 @@ struct obj_cgroup {
 	struct percpu_ref refcnt;
 	struct mem_cgroup *memcg;
 	atomic_t nr_charged_bytes;
+	refcount_t private_id_ref;
 	union {
 		struct list_head list; /* protected by objcg_lock */
 		struct rcu_head rcu;
@@ -225,9 +226,6 @@ struct mem_cgroup {
 	/* vmpressure notifications. Written on every reclaim iteration. */
 	struct vmpressure vmpressure;
 
-	/* Written on every swap charge and uncharge. */
-	refcount_t private_id_ref;
-
 #ifdef CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC
 	/* MEMCG_KMEM for nmi context */
 	atomic_t		kmem_stat;
@@ -324,6 +322,9 @@ struct mem_cgroup {
 	unsigned long zswap_max;
 #endif
 
+	/* The objcg holding private memcg ID. */
+	struct obj_cgroup *private_id_objcg;
+
 	/* Private memcg ID. Used to ID objects that outlive the cgroup */
 	int private_id;
 
mm/list_lru.c renamed from mm/list_lru.c~memcg-move-memcg-private-id-refcount-to-objcg +1 -1
@@ -428,7 +428,7 @@ unsigned long list_lru_walk_node(struct
 		xa_for_each(&lru->xa, index, mlru) {
 			rcu_read_lock();
 			memcg = mem_cgroup_from_private_id(index);
-			if (!mem_cgroup_tryget(memcg)) {
+			if (!memcg || !mem_cgroup_tryget(memcg)) {
 				rcu_read_unlock();
 				continue;
 			}
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-move-memcg-private-id-refcount-to-objcg +54 -19

158 lines not on this page · raw message

mm/workingset.c renamed from mm/workingset.c~memcg-move-memcg-private-id-refcount-to-objcg +1 -1
@@ -470,7 +470,7 @@ bool workingset_test_recent(void *shadow
 	 * configurations instead.
 	 */
 	eviction_memcg = mem_cgroup_from_private_id(memcgid);
-	if (!mem_cgroup_tryget(eviction_memcg))
+	if (eviction_memcg && !mem_cgroup_tryget(eviction_memcg))
 		eviction_memcg = NULL;
 	rcu_read_unlock();
 

_

Patches currently in -mm which might be from [email protected] are