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

From: Jiayuan Chen

Date: Thu Jul 02 2026 - 08:57:07 EST



On 7/2/26 8:02 PM, Jiayuan Chen wrote:
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.



The issuse reported by Ai is benign:
https://sashiko.dev/#/patchset/20260702120235.376752-1-jiayuan.chen%40linux.dev

We have multiple break points to return in try_to_free_pages::do_try_to_free_pages
'''

    static unsigned long do_try_to_free_pages()
    {

        retry:
            do {

                shrink_zones(zonelist, sc);

                // break 1
                if (sc->nr_reclaimed >= sc->nr_to_reclaim)
                    break;

            } while (--sc->priority >= 0); // at most 12 times(DEF_PRIORITY)


            // break 2
            if (sc->nr_reclaimed)
                return sc->nr_reclaimed;

            // retry twice logic
            ...
    }
'''