[PATCH v3 2/4] memcg: bail out memory.max when memcg is dying
From: Jiayuan Chen
Date: Thu Jul 02 2026 - 08:31:58 EST
From: Jiayuan Chen <jiayuan.chen@xxxxxxxxxx>
memory.max has the same high-latency reclaim loop as memory.high, and
may additionally invoke the OOM killer on a cgroup that is already going
away, further delaying its removal.
Mitigate this by bailing out of the loop once memcg_is_dying().
Cc: Jiayuan Chen <jiayuan.chen@xxxxxxxxx>
Reported-by: Zhou Yingfu <yingfu.zhou@xxxxxxxxxx>
Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>
Signed-off-by: Jiayuan Chen <jiayuan.chen@xxxxxxxxxx>
---
mm/memcontrol.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4519dc9eae33..938f190a98fe 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4849,6 +4849,10 @@ static ssize_t memory_max_write(struct kernfs_open_file *of,
if (signal_pending(current))
break;
+ /* cgroup_rmdir() waits for us with cgroup_mutex held. */
+ if (memcg_is_dying(memcg))
+ break;
+
if (!drained) {
drain_all_stock(memcg);
drained = true;
--
2.43.0