Skip to contentSkip to conversation

memcg-add-nmi-safe-update-for-memcg_kmem.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jun 1, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: memcg: add nmi-safe update for MEMCG_KMEM
has been removed from the -mm tree. Its filename was
memcg-add-nmi-safe-update-for-memcg_kmem.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: Shakeel Butt <[email protected]>
Subject: memcg: add nmi-safe update for MEMCG_KMEM
Date: Sun, 18 May 2025 23:31:40 -0700

The objcg based kmem charging and uncharging code path needs to update MEMCG_KMEM appropriately. Let's add support to update MEMCG_KMEM in nmi-safe way for those code paths.

Cc Alexei Starovoitov <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Muchun Song <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Tejun Heo <[email protected]>

---

 mm/memcontrol.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-add-nmi-safe-update-for-memcg_kmem +19 -2
@@ -2715,6 +2715,23 @@ struct obj_cgroup *get_obj_cgroup_from_f
 	return objcg;
 }
 
+#ifdef CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC
+static inline void account_kmem_nmi_safe(struct mem_cgroup *memcg, int val)
+{
+	if (likely(!in_nmi())) {
+		mod_memcg_state(memcg, MEMCG_KMEM, val);
+	} else {
+		/* TODO: add to cgroup update tree once it is nmi-safe. */
+		atomic_add(val, &memcg->kmem_stat);
+	}
+}
+#else
+static inline void account_kmem_nmi_safe(struct mem_cgroup *memcg, int val)
+{
+	mod_memcg_state(memcg, MEMCG_KMEM, val);
+}
+#endif
+
 /*
  * obj_cgroup_uncharge_pages: uncharge a number of kernel pages from a objcg
  * @objcg: object cgroup to uncharge
@@ -2727,7 +2744,7 @@ static void obj_cgroup_uncharge_pages(st
 
 	memcg = get_mem_cgroup_from_objcg(objcg);
 
-	mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages);
+	account_kmem_nmi_safe(memcg, -nr_pages);
 	memcg1_account_kmem(memcg, -nr_pages);
 	if (!mem_cgroup_is_root(memcg))
 		refill_stock(memcg, nr_pages);
@@ -2755,7 +2772,7 @@ static int obj_cgroup_charge_pages(struc
 	if (ret)
 		goto out;
 
-	mod_memcg_state(memcg, MEMCG_KMEM, nr_pages);
+	account_kmem_nmi_safe(memcg, nr_pages);
 	memcg1_account_kmem(memcg, nr_pages);
 out:
 	css_put(&memcg->css);

_

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