[PATCH v3 3/4] memcg: bail out proactive reclaim when memcg is dying

From: Jiayuan Chen

Date: Thu Jul 02 2026 - 08:14:18 EST


From: Jiayuan Chen <jiayuan.chen@xxxxxxxxxx>

Proactive reclaim via memory.reclaim can run for a long time - swap I/O
or thrashing again dominating the latency - and delays cgroup removal in
the same way.

Mitigate this by stopping the reclaim 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/vmscan.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 754c5f5d716a..6ae61be2fab8 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -7912,6 +7912,10 @@ int user_proactive_reclaim(char *buf,
if (signal_pending(current))
return -EINTR;

+ /* cgroup_rmdir() waits for us with cgroup_mutex held. */
+ if (memcg && memcg_is_dying(memcg))
+ return -EAGAIN;
+
/*
* This is the final attempt, drain percpu lru caches in the
* hope of introducing more evictable pages.
--
2.43.0