mm: vmscan: abort proactive reclaim early when freezing
Subsystems (3)
PATCH 1/1 mm: vmscan: abort proactive reclaim early when freezing
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups in shrink_many() and evicting folios in try_to_shrink_lruvec() can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.
This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Add a signal_pending() check to should_abort_scan() for proactive reclaim paths. Since should_abort_scan() is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.
This check is limited to proactive reclaim (sc->proactive) to avoid affecting reactive reclaim paths, and wrapped in unlikely() as it is a slow path.
--- mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)
mm/vmscan.c +3 -0
@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;
Signature · 1 line
2.55.0.rc2.803.g1fd1e6609c-goog
Barry Song
reviewerQuoted 32 lines · Richard Chang
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.This check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.Signed-off-by Richard Chang <[email protected]>--- mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)mm/vmscan.c +0
-0
mm/vmscan.c static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc) · line 4934
Quoted 6 lines
mm/vmscan.c +3
-0@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +
Seems reasonable to me. I wonder if you have a script to reproduce the issue. I'd like to test it.
Best Regards
Barry
Hi Barry,
I use the following commands to test. The CGROUP_PATH depends on the platform settings.
echo 1000 > /sys/power/pm_freeze_timeout
echo freezer > /sys/power/pm_test
while true; do echo 1024M > /sys/fs/cgroup/$CGROUP_PATH/memory.reclaim; sleep 1; done echo mem > /sys/power/state
BR,
Richard
Quoted 46 lines · Barry Song
Quoted 32 lines · Richard Chang
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.This check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.Signed-off-by Richard Chang <[email protected]>--- mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)mm/vmscan.c +0
-0mm/vmscan.c static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc) · line 4934
Quoted 6 lines
mm/vmscan.c +3
-0@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +Seems reasonable to me. I wonder if you have a script to reproduce the issue. I'd like to test it.
Best Regards
Barry
Andrew Morton
maintainerQuoted 17 lines · On Mon, 6 Jul 2026 08:12:18 +0000 Richard Chang <[email protected]> wrote:
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.
Quoted 3 lines
This check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.
There are a number of ways of getting into proactive reclaim. Have you checked that all of them appropriately check and handle signal_pending()?
AI review thinks that classic LRU might need the same fix:
https://sashiko.dev/#/patchset/[email protected]
Hi Andrew,
I believe there are three ways to trigger proactive reclaim:
1. Cgroup Proactive Reclaim: memory_reclaim() -> user_proactive_reclaim()
2. Node Proactive Reclaim: reclaim_store() -> user_proactive_reclaim()
3. Debugfs lru_gen: lru_gen_seq_write() -> run_cmd() -> run_eviction()
Methods (1) and (2) are covered by this patch, while (3) already includes a while (!signal_pending(current)) check in run_eviction().
Regarding the AI feedback on the Classic LRU path, that is a valid point. Since we have only observed this issue with MGLRU, I suspect it is because in Classic LRU, the scan target per iteration is strictly bounded by get_scan_count(), which ensures it returns to the outer loop (where signals are checked) much more frequently.
Quoted 29 lines · Andrew Morton
Quoted 17 lines · On Mon, 6 Jul 2026 08:12:18 +0000 Richard Chang <[email protected]> wrote:
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.Quoted 3 lines
This check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.There are a number of ways of getting into proactive reclaim. Have you checked that all of them appropriately check and handle
signal_pending()?AI review thinks that classic LRU might need the same fix:
https://sashiko.dev/#/patchset/[email protected]
Quoted 11 lines · Richard Chang
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Quoted 5 lines
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.
Do we still need the check in the outer loop?
Quoted 28 lines
This check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.Signed-off-by Richard Chang <[email protected]>--- mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)mm/vmscan.c +3
-0@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;Signature · 1 line
2.55.0.rc2.803.g1fd1e6609c-goog
Hi Yosry,
I believe we still need the outer loop check. Otherwise, we will waste CPU cycles entering the inner loop only to bail out.
Quoted 49 lines · Yosry Ahmed
Quoted 11 lines · Richard Chang
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Quoted 5 lines
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.Do we still need the check in the outer loop?
Quoted 28 lines
This check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.Signed-off-by Richard Chang <[email protected]>--- mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)mm/vmscan.c +3
-1@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true; --2.55.0.rc2.803.g1fd1e6609c-goog
Quoted 20 lines · Yosry Ahmed
Quoted 19 lines · Richard Chang
Quoted 16 lines
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator in a timely manner.
Quoted 4 lines
Quoted 1 line
Do we still need the check in the outer loop?
I believe we still need the outer loop check. Otherwise, we will waste CPU cycles entering the inner loop only to bail out.
(Moving your reply after the relevant text, please avoid top-posting:
https://subspace.kernel.org/etiquette.html#do-not-top-post-when-replying).
My question was whether or not it matters in practice, sure we'll waste some cycles but I don't think it would ultimately matter. That being said, seems like this change only covers MGLRU, so we still need the outer check at least for classic LRU.
Shakeel Butt
reviewerQuoted 11 lines · Richard Chang
Proactive reclaim (via memory.reclaim or node reclaim) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—scanning cgroups inshrink_many()and evicting folios intry_to_shrink_lruvec()can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.This latency in responding to signals can block the freezer (both cgroup freezer and system suspend), leading to freezer timeouts. This issue was specifically observed on Android when attempting to freeze background cgroups while proactive reclaim was active.
Can you please explain how freezing operation was delayed due to proactive reclaim?
Quoted 4 lines · Shakeel Butt
Can you please explain how freezing operation was delayed due to proactive reclaim?
Hi Shakeel,
When system suspend is initiated, the Power Management (PM) freezer attempts to freeze all user-space processes by calling freeze_processes(), signaling user space processes to enter the refrigerator. When a user-space task writes to memory.reclaim to trigger proactive reclaim, it executes in kernel context and enters the reclaim loop. Currently the task does not check signal_pending() within the inner loops, it cannot abort the reclaim pass early. It continues reclaiming memory, ignoring the freeze request. The PM freezer waits for all tasks to freeze. If the proactive reclaim task remains in the inner loops longer than the freeze timeout, the freezer times out, and suspend fails.
Shakeel Butt
reviewerQuoted 7 lines · Richard Chang
Quoted 4 lines · Shakeel Butt
Can you please explain how freezing operation was delayed due to proactive reclaim?
Hi Shakeel,
Quoted 11 lines
When system suspend is initiated, the Power Management (PM) freezer attempts to freeze all user-space processes by calling
freeze_processes(), signaling user space processes to enter the refrigerator. When a user-space task writes to memory.reclaim to trigger proactive reclaim, it executes in kernel context and enters the reclaim loop. Currently the task does not checksignal_pending()within the inner loops, it cannot abort the reclaim pass early. It continues reclaiming memory, ignoring the freeze request. The PM freezer waits for all tasks to freeze. If the proactive reclaim task remains in the inner loops longer than the freeze timeout, the freezer times out, and suspend fails.
What's so special about proactive reclaim? Why the same situation can not happen for global or memcg reclaim?
Quoted 4 lines · Shakeel Butt
What's so special about proactive reclaim? Why the same situation can not happen for global or memcg reclaim?
The target batch size of the global/memcg reclaim is typically very small -- usually SWAP_CLUSTER_MAX (32 pages), allowing the task to yield or check signals between attempts.
Furthermore, kswapd is a kernel thread designed to be freezable, it explicitly checks kthread_freezable_should_stop() in the main loop. In contrast, the target batch size in proactive reclaim is user-defined and can be extremely large. Without signal checks in the inner loops, the task may continue scanning and evicting pages for seconds at a time.
Shakeel Butt
reviewerQuoted 6 lines · Richard Chang
Quoted 4 lines · Shakeel Butt
What's so special about proactive reclaim? Why the same situation can not happen for global or memcg reclaim?
Quoted 9 lines
The target batch size of the global/memcg reclaim is typically very small -- usually
SWAP_CLUSTER_MAX(32 pages), allowing the task to yield or check signals between attempts.
Furthermore, kswapd is a kernel thread designed to be freezable, it explicitly checkskthread_freezable_should_stop()in the main loop. In contrast, the target batch size in proactive reclaim is user-defined and can be extremely large. Without signal checks in the inner loops, the task may continue scanning and evicting pages for seconds at a time.
Why can't the proactive reclaim use the same batch size as memcg and global reclaim?
Quoted 18 lines · Shakeel Butt
Quoted 6 lines · Richard Chang
Quoted 4 lines · Shakeel Butt
What's so special about proactive reclaim? Why the same situation can not happen for global or memcg reclaim?
Quoted 9 lines
The target batch size of the global/memcg reclaim is typically very small -- usually
SWAP_CLUSTER_MAX(32 pages), allowing the task to yield or check signals between attempts.
Furthermore, kswapd is a kernel thread designed to be freezable, it explicitly checkskthread_freezable_should_stop()in the main loop. In contrast, the target batch size in proactive reclaim is user-defined and can be extremely large. Without signal checks in the inner loops, the task may continue scanning and evicting pages for seconds at a time.
Quoted 2 lines
Why can't the proactive reclaim use the same batch size as memcg and global reclaim?
Because it is very slow:
https://lore.kernel.org/all/[email protected]/
Shakeel Butt
reviewerQuoted 19 lines · T.J. Mercier
Quoted 18 lines · Shakeel Butt
Quoted 15 lines · Richard Chang
Quoted 4 lines · Shakeel Butt
What's so special about proactive reclaim? Why the same situation can not happen for global or memcg reclaim?
The target batch size of the global/memcg reclaim is typically very small -- usually
SWAP_CLUSTER_MAX(32 pages), allowing the task to yield or check signals between attempts.
Furthermore, kswapd is a kernel thread designed to be freezable, it explicitly checkskthread_freezable_should_stop()in the main loop. In contrast, the target batch size in proactive reclaim is user-defined and can be extremely large. Without signal checks in the inner loops, the task may continue scanning and evicting pages for seconds at a time.
Quoted 5 lines
Quoted 2 lines
Why can't the proactive reclaim use the same batch size as memcg and global reclaim?
Because it is very slow:
https://lore.kernel.org/all/[email protected]/
Yes, we should fix reclaim and preferrably have single solution for all types of reclaim. Though that is orthogonal and out of scope for this patch.
The reason behind my questioning is that the commit message should have all of this information from the start instead of requiring readers to extract all of this.
PATCH v2 1/1 mm: vmscan: abort proactive reclaim early when freezing for suspend
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups in shrink_many() and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.
During system suspend, the PM freezer attempts to freeze all the tasks by sending signals. Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.
This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit 287d5fedb377 ("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the reclaim loop with a large target for a single syscall invocation. In contrast, reactive reclaim (global/memcg) has small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing to yield or check signals between attempts quickly.
To fix this, add a signal_pending() check to should_abort_scan() for proactive reclaim paths. Since should_abort_scan() is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator and allow suspend to proceed.
The check is limited to proactive reclaim (sc->proactive) to avoid affecting reactive reclaim paths, and wrapped in unlikely() as it is a slow path.
---
v2: Update the commit message
mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)
mm/vmscan.c +3 -0
@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 31 lines · Richard Chang
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups inshrink_many()and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.During system suspend, the PM freezer attempts to freeze all the tasks by sending signals. Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.
This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit
287d5fedb377("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the reclaim loop with a large target for a single syscall invocation. In contrast, reactive reclaim (global/memcg) has small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing to yield or check signals between attempts quickly.To fix this, add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop, ensuring the task can enter the refrigerator and allow suspend to proceed.
Quoted 3 lines
The check is limited to proactive reclaim (
sc->proactive) to avoid affecting reactive reclaim paths, and wrapped inunlikely()as it is a slow path.
The changelog doesn't explain whether this is MGRLU specific problem as the fix is MGRLU specific AFAICS.
Also do I get it right that freezing a task while doing the pro-active reclaim will force EINTR early return even if no real signal was delivered to the task?
Quoted 23 lines
Signed-off-by Richard Chang <[email protected]>---
v2: Update the commit messagemm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+)mm/vmscan.c +3
-0@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;Signature · 1 line
2.55.0.795.g602f6c329a-goog
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Michal,
Quoted 4 lines · Michal Hocko
The changelog doesn't explain whether this is MGRLU specific problem as the fix is MGRLU specific AFAICS.
I will prepare the v3 changelog update. Thanks.
Quoted 4 lines
Also do I get it right that freezing a task while doing the pro-active reclaim will force EINTR early return even if no real signal was delivered to the task?
Yes, that is correct.
The PM freezer ( freeze_task() ) calls fake_signal_wake_up(), which sets TIF_SIGPENDING on the target task.
Returning -EINTR when checking by signal_pending(current) is already the existing behavior of user_proactive_reclaim().
This patch does not change the behavior, it just allows the task to exit the inner loop quickly.
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 13 lines · Richard Chang
Hi Michal,
Quoted 4 lines · Michal Hocko
The changelog doesn't explain whether this is MGRLU specific problem as the fix is MGRLU specific AFAICS.
I will prepare the v3 changelog update. Thanks.
Quoted 4 lines
Also do I get it right that freezing a task while doing the pro-active reclaim will force EINTR early return even if no real signal was delivered to the task?
Quoted 7 lines
Yes, that is correct.
The PM freezer (freeze_task()) callsfake_signal_wake_up(), which setsTIF_SIGPENDINGon the target task.
Returning-EINTRwhen checking bysignal_pending(current)is already the existing behavior ofuser_proactive_reclaim().
This patch does not change the behavior, it just allows the task to exit the inner loop quickly.
I believe this is a wrong behavior. Freezer should be invisible from the userspace POV. Your patch makes the pre-existing problem much more visible. I believe we need a slightly different approach. Should we try_to_freeze in well defined places in the reclaim and turn user_proactive_reclaim to fatal_signal_pending?
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Michal,
Quoted 7 lines · Michal Hocko
I believe this is a wrong behavior. Freezer should be invisible from the userspace POV. Your patch makes the pre-existing problem much more visible. I believe we need a slightly different approach. Should we
try_to_freezein well defined places in the reclaim and turnuser_proactive_reclaimtofatal_signal_pending?
I believe your perspective is that we should avoid -EINTR during suspend by transparently pausing and resuming the task rather than aborting the system call.
However, this approach faces a few constraints:
1. fatal_signal_pending() only addresses SIGKILL, leaving us to still handle standard non-fatal signals, such as SIGINT/Ctrl+C, for userspace callers.
2. Calling try_to_freeze() deep within the reclaim path is complex, as it may hold various locks (such as RCU, page, or cgroup locks) while suspended.
3. Since -EINTR is already the established return behavior in user_proactive_reclaim() when interrupted by signal_pending(), robust userspace callers should already be equipped to handle this early return.
On the other hand, the freezer timeout/suspend failure is a genuine bug currently impacting Android devices in the field. The proposed patch safely addresses this immediate issue by leveraging the pre-existing -EINTR exit path in user_proactive_reclaim(). Could we focus on the current patch and open a separate discussion for a more ideal, long-term design regarding freezer invisibility as a follow-up?
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 11 lines · Richard Chang
Hi Michal,
Quoted 7 lines · Michal Hocko
I believe this is a wrong behavior. Freezer should be invisible from the userspace POV. Your patch makes the pre-existing problem much more visible. I believe we need a slightly different approach. Should we
try_to_freezein well defined places in the reclaim and turnuser_proactive_reclaimtofatal_signal_pending?
Quoted 3 lines
I believe your perspective is that we should avoid
-EINTRduring suspend by transparently pausing and resuming the task rather than aborting the system call.
Correct.
Quoted 4 lines
However, this approach faces a few constraints:
1.fatal_signal_pending()only addresses SIGKILL, leaving us to still handle standard non-fatal signals, such as SIGINT/Ctrl+C, for userspace callers.
fatal_signal_pending takes care of all fatal signals - i.e. when tasks doesn't really return to userspace because it dies along the way so it doesn't realize there was a kernel internal signal ever triggered.
Quoted 3 lines
2. Calling
try_to_freeze()deep within the reclaim path is complex, as it may hold various locks (such as RCU, page, or cgroup locks) while suspended.
True the placement would need to be done very carefully.
Quoted 4 lines
3. Since
-EINTRis already the established return behavior inuser_proactive_reclaim()when interrupted bysignal_pending(), robust userspace callers should already be equipped to handle this early return.
This is relatively new code and a broken one I would say.
Quoted 6 lines
On the other hand, the freezer timeout/suspend failure is a genuine bug currently impacting Android devices in the field. The proposed patch safely addresses this immediate issue by leveraging the pre-existing
-EINTRexit path inuser_proactive_reclaim(). Could we focus on the current patch and open a separate discussion for a more ideal, long-term design regarding freezer invisibility as a follow-up?
I am not insisting both to be addressed in the same patch. But building more on top of a broken behavior is not healthy either.
In the current state this should be as easy as turning signal_pending into fatal_signal_pending and try_to_freeze at the pro-active reclaim entry point which should be safe from the freezer POV.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 1 line · Michal Hocko
On Tue 14-07-26 17:00:37, Richard Chang wrote:
[...]
Quoted 7 lines
Quoted 6 lines
On the other hand, the freezer timeout/suspend failure is a genuine bug currently impacting Android devices in the field. The proposed patch safely addresses this immediate issue by leveraging the pre-existing
-EINTRexit path inuser_proactive_reclaim(). Could we focus on the current patch and open a separate discussion for a more ideal, long-term design regarding freezer invisibility as a follow-up?
Quoted 5 lines
I am not insisting both to be addressed in the same patch. But building more on top of a broken behavior is not healthy either.
In the current state this should be as easy as turningsignal_pendingintofatal_signal_pendingandtry_to_freezeat the pro-active reclaim entry point which should be safe from the freezer POV.
Something like the following on top of your early break from reclaim patch. Maybe there is a better way. Freezer has always been quite confusing to me but this should work AFAICT.
mm/vmscan.c +7 -1
@@ -7909,9 +7909,15 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; -if (signal_pending (current)) +if (fatal_signal_pending (current))return -EINTR ; +/* +* Make sure this potentially costly operation doesn't block +* freezer for too long. +*/ +try_to_freeze (); +/* * This is the final attempt, drain percpu lru caches in the * hope of introducing more evictable pages.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Michal,
Thanks for the patch.
Yes, inserting try_to_freeze() at that point carries low risk. However, there are still a few issues:
1. As I understand it, fatal_signal_pending() only checks for SIGKILL (via sigismember(..., SIGKILL)).
It does not return true for SIGINT (Ctrl+C), even if the signal is unhandled and will eventually terminate the task.
If we switch to fatal_signal_pending, a large proactive reclaim task will continue reclaiming until the loop finishes.
2. try_to_freeze() does not clear the TIF_SIGPENDING flag. When the task resumes and continues the user_proactive_reclaim() loop, the next iteration of the inner loop will immediately abort.
I think it requires a more complex implementation in the outer loop. Eg:
if (signal_pending(current)) {
if (freezing(current)) {
try_to_freeze();
// After thawing, clear the fake signal TIF_SIGPENDING flag
...
} else {
// real signal like SIGINT
return -EINTR;
}
}Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
[Add Oleg]
Quoted 11 lines · Richard Chang
Hi Michal,
Thanks for the patch.
Yes, insertingtry_to_freeze()at that point carries low risk. However, there are still a few issues:1. As I understand it,
fatal_signal_pending()only checks for SIGKILL (viasigismember(..., SIGKILL)).
It does not return true for SIGINT (Ctrl+C), even if the signal is unhandled and will eventually terminate the task.
If we switch tofatal_signal_pending, a large proactive reclaim task will continue reclaiming until the loop finishes.
OK, I see you concern now. The code is a bit confusing in this respect. You are right that fatal_signal_pending returns true only if SIGKILL is flagged. You need to have a look at the signal delivery path though. If there is a terminating signal sent and there is a default handler (sig_fatal) then complete_signal will add SIGKILL to kill the whole process group.
Quoted 3 lines
2.
try_to_freeze()does not clear theTIF_SIGPENDINGflag. When the task resumes and continues theuser_proactive_reclaim()loop, the next iteration of the inner loop will immediately abort.
You are right. I forgot that try_to_freeze is not really aimed to be used for user processes. Rather than trying to enforce explicit try_to_freeze and dealing with pending signals I believe the right approach would be to instead simply do the following.
Oleg you haven't been CCed from the top of the thread but TL;DR is that we need to freeze a user task performing pro-active memory reclaim that might take long. Currently we are calling signal_pending to bail out but that leaks EINTR which is bad as freezing task has a side effect of terminating it.
mm/vmscan.c +6 -1
@@ -7909,8 +7909,13 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; +/* +* Make sure that we enter freezer without delaying much and +* leaking EINTR when that happens but also take care of +* fatal signals to terminate. +*/ if (signal_pending (current)) -return -EINTR ; +return -ERESTARTSYS ;/* * This is the final attempt, drain percpu lru caches in the
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Michal,
Quoted 6 lines · Michal Hocko
Oleg you haven't been CCed from the top of the thread but TL;DR is that we need to freeze a user task performing pro-active memory reclaim that might take long. Currently we are calling
signal_pendingto bail out but that leaks EINTR which is bad as freezing task has a side effect of terminating it.
Sorry, I guess I don't understand the problem...
Yes, unlike EINTR, ERESTARTSYS should not leak to the caller (just in case, debugger can see this error code).
But I am sure you know this. And the patch looks fine to me.
Oleg.
Quoted 24 lines
mm/vmscan.c +6
-1@@ -7909,8 +7909,13 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; +/* +* Make sure that we enter freezer without delaying much and +* leaking EINTR when that happens but also take care of +* fatal signals to terminate. +*/ if (signal_pending (current)) -return -EINTR ; +return -ERESTARTSYS ;/* * This is the final attempt, drain percpu lru caches in the Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 11 lines · Oleg Nesterov
Hi Michal,
Quoted 6 lines · Michal Hocko
Oleg you haven't been CCed from the top of the thread but TL;DR is that we need to freeze a user task performing pro-active memory reclaim that might take long. Currently we are calling
signal_pendingto bail out but that leaks EINTR which is bad as freezing task has a side effect of terminating it.Sorry, I guess I don't understand the problem...
the problem is that `echo $AMOUNT > $CGROUP/memory.reclaim' can take quite some time and therefore block freezer. Appart from Richard's fix to bail out on pending_signal deep in the MGLRU reclaim we have this signal_pending in user_proactive_reclaim which would leak EINTR if the source of the signal was freezer. This is IMHO undesirable. The proposed change below tries to address that problem.
Makes more sense now?
Quoted 3 lines
Yes, unlike EINTR, ERESTARTSYS should not leak to the caller (just in case, debugger can see this error code).
Yes, I guess this is a general constrain to any signal_pending() caller.
Quoted 3 lines
But I am sure you know this. And the patch looks fine to me.
Oleg.
Thanks!
Quoted 25 lines
Quoted 25 lines
mm/vmscan.c +6
-1@@ -7909,8 +7909,13 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; +/* +* Make sure that we enter freezer without delaying much and +* leaking EINTR when that happens but also take care of +* fatal signals to terminate. +*/ if (signal_pending (current)) -return -EINTR ; +return -ERESTARTSYS ;/* * This is the final attempt, drain percpu lru caches in the Signature · 2 lines
Michal Hocko SUSE Labs
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Michal,
Returning -ERESTARTSYS in user_proactive_reclaim() is a great suggestion. I will update the patch to use -ERESTARTSYS in user_proactive_reclaim() alongside the should_abort_scan() check. Thank you!
PATCH v3 1/1 mm: vmscan: abort proactive reclaim early when freezing for suspend
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups in shrink_many() and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.
During system suspend, the PM freezer attempts to freeze all tasks by sending fake signals (setting TIF_SIGPENDING). Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.
This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit 287d5fedb377 ("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the inner reclaim loop for extended periods. In contrast, reactive reclaim (global/memcg) uses small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing it to return to the outer loop and check signals frequently.
To fix this, add a signal_pending() check to should_abort_scan() for proactive reclaim paths. Since should_abort_scan() is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop in user_proactive_reclaim().
Additionally, return -ERESTARTSYS instead of -EINTR in user_proactive_reclaim(). When interrupted by system suspend, returning -ERESTARTSYS allows the task to enter the refrigerator and automatically restart the syscall upon resume, making the freezer transparent to userspace. If interrupted by an unhandled real signal (e.g. SIGINT), the kernel signal layer automatically converts -ERESTARTSYS to -EINTR.
This fix specifically targets Multi-Gen LRU (MGLRU). Classic LRU's scan targets per iteration are strictly bounded by get_scan_count(), which ensures it returns to the outer loop more frequently.
The check in should_abort_scan() is limited to proactive reclaim (sc->proactive) to avoid inadvertently affecting reactive reclaim paths, and is wrapped in unlikely() as it is a slow path.
---
v2: Update the commit message
v3: Return -ERESTARTSYS instead of -EINTR in user_proactive_reclaim
mm/vmscan.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
mm/vmscan.c +10 -1
@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;
@@ -7909,8 +7912,14 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; +/* +* Return -ERESTARTSYS to allow the freezer to interrupt the +* task. The syscall will be transparently restarted upon +* resume. Real signals (e.g. SIGINT) will be automatically +* converted to -EINTR by the signal layer. +*/ if (signal_pending (current)) -return -EINTR ; +return -ERESTARTSYS ;/* * This is the final attempt, drain percpu lru caches in the
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Re: [PATCH v3] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 2 lines · Richard Chang
v3: Return
-ERESTARTSYSinstead of-EINTRinuser_proactive_reclaim
Yes, this change LGTM, but ...
mm/vmscan.c int user_proactive_reclaim(char *buf, · line 7920
Quoted 6 lines
mm/vmscan.c +6
-0+/* +* Return -ERESTARTSYS to allow the freezer to interrupt the +* task. The syscall will be transparently restarted upon +* resume. Real signals (e.g. SIGINT) will be automatically +* converted to -EINTR by the signal layer. +*/
... the comment looks a bit misleading...
So, if the signal is "real" and has a handler, handle_signal() does
case -ERESTARTSYS:
if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
regs->ax = -EINTR;
break;
}
fallthrough;
case -ERESTARTNOINTR:
regs->ax = regs->orig_ax;
regs->ip -= 2;
break;If SA_RESTART is set, the syscall will be restarted after return from signal handler.
Oleg.
Re: [PATCH v3] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Oleg,
You are right, and this is a great catch.
I am updating v4 to accurately reflect the SA_RESTART semantics. Thanks!
PATCH v4 1/1 mm: vmscan: abort proactive reclaim early when freezing for suspend
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups in shrink_many() and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.
During system suspend, the PM freezer attempts to freeze all tasks by sending fake signals (setting TIF_SIGPENDING). Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.
This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit 287d5fedb377 ("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the inner reclaim loop for extended periods. In contrast, reactive reclaim (global/memcg) uses small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing it to return to the outer loop and check signals frequently.
To fix this, add a signal_pending() check to should_abort_scan() for proactive reclaim paths. Since should_abort_scan() is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop in user_proactive_reclaim().
Additionally, return -ERESTARTSYS instead of -EINTR in user_proactive_reclaim(). When interrupted by system suspend, returning -ERESTARTSYS allows the task to enter the refrigerator and automatically restart the syscall upon resume, making the freezer transparent to userspace. For real signals, the signal layer will either restart the syscall (if SA_RESTART is set) or return -EINTR to userspace.
This fix specifically targets Multi-Gen LRU (MGLRU). Classic LRU's scan targets per iteration are strictly bounded by get_scan_count(), which ensures it returns to the outer loop more frequently.
The check in should_abort_scan() is limited to proactive reclaim (sc->proactive) to avoid inadvertently affecting reactive reclaim paths, and is wrapped in unlikely() as it is a slow path.
---
v2: Update the commit message
v3: Return -ERESTARTSYS instead of -EINTR in user_proactive_reclaim
v4: Clarify -ERESTARTSYS vs SA_RESTART behavior
mm/vmscan.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
mm/vmscan.c +11 -1
@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;
@@ -7909,8 +7912,15 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; +/* +* Return -ERESTARTSYS to allow the freezer to interrupt the +* task. The syscall will be transparently restarted upon +* resume. For real signals, it either restarts the syscall +* (if SA_RESTART is set) or is converted to -EINTR by the +* signal layer. +*/ if (signal_pending (current)) -return -EINTR ; +return -ERESTARTSYS ;/* * This is the final attempt, drain percpu lru caches in the
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Andrew Morton
maintainerRe: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 14 lines · On Mon, 20 Jul 2026 04:41:03 +0000 Richard Chang <[email protected]> wrote:
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups inshrink_many()and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.During system suspend, the PM freezer attempts to freeze all tasks by sending fake signals (setting
TIF_SIGPENDING). Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.
Quoted 9 lines
This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit
287d5fedb377("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the inner reclaim loop for extended periods. In contrast, reactive reclaim (global/memcg) uses small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing it to return to the outer loop and check signals frequently.
So 287d5fedb377 led to suspend failures on MGLRU-using kernels.
That's a regression which justifies a Fixes: and a cc:stable, don't people agree?
AI review asked a couple of serious-sounding questions:
https://sashiko.dev/#/patchset/[email protected]
Quoted 20 lines
To fix this, add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop inuser_proactive_reclaim().Additionally, return
-ERESTARTSYSinstead of-EINTRinuser_proactive_reclaim(). When interrupted by system suspend, returning-ERESTARTSYSallows the task to enter the refrigerator and automatically restart the syscall upon resume, making the freezer transparent to userspace. For real signals, the signal layer will either restart the syscall (ifSA_RESTARTis set) or return-EINTRto userspace.This fix specifically targets Multi-Gen LRU (MGLRU). Classic LRU's scan targets per iteration are strictly bounded by
get_scan_count(), which ensures it returns to the outer loop more frequently.The check in
should_abort_scan()is limited to proactive reclaim (sc->proactive) to avoid inadvertently affecting reactive reclaim paths, and is wrapped inunlikely()as it is a slow path.
Re: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend
Hi Andrew,
Thanks for pointing that out.
Quoted 9 lines · Andrew Morton
So
287d5fedb377led to suspend failures on MGLRU-using kernels.That's a regression which justifies a Fixes: and a cc:stable, don't people agree?
AI review asked a couple of serious-sounding questions:
https://sashiko.dev/#/patchset/[email protected]
Hi Michal and Oleg,
The -ERESTARTSYS concern raised during the AI review seems reasonable:
1. Over-Reclaim: If a task has already reclaimed 900MB of a 1GB request before being interrupted by a suspend, an -ERESTARTSYS would attempt to reclaim another 1GB when resuming, resulting in up to 1.9GB of over-reclaim.
2. Incompatibility Node-Reclaim: Since reclaim_store() unconditionally converts any non-zero return value from user_proactive_reclaim() into -EAGAIN, it will not restart the syscall for node reclaim. Given these constraints, do you think we should keep -EINTR in user_proactive_reclaim()?
Andrew Morton
maintainerRe: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend
Quoted 16 lines · On Mon, 20 Jul 2026 20:04:30 +0800 Richard Chang <[email protected]> wrote:
Hi Andrew,
Thanks for pointing that out.Quoted 9 lines · Andrew Morton
So
287d5fedb377led to suspend failures on MGLRU-using kernels.That's a regression which justifies a Fixes: and a cc:stable, don't people agree?
AI review asked a couple of serious-sounding questions:
https://sashiko.dev/#/patchset/[email protected]Hi Michal and Oleg,
Quoted 10 lines
The
-ERESTARTSYSconcern raised during the AI review seems reasonable:
1. Over-Reclaim: If a task has already reclaimed 900MB of a 1GB request before being interrupted by a suspend, an-ERESTARTSYSwould attempt to reclaim another 1GB when resuming, resulting in up to 1.9GB of over-reclaim.
2. Incompatibility Node-Reclaim: Sincereclaim_store()unconditionally converts any non-zero return value fromuser_proactive_reclaim()into-EAGAIN, it will not restart the syscall for node reclaim. Given these constraints, do you think we should keep-EINTRinuser_proactive_reclaim()?
It's been a long time. Did the above two issues receive consideration?
Thanks.
Re: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend
In reply to Andrew MortonQuoted 26 lines · Andrew Morton
Quoted 14 lines · On Mon, 20 Jul 2026 04:41:03 +0000 Richard Chang <[email protected]> wrote:
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups inshrink_many()and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.During system suspend, the PM freezer attempts to freeze all tasks by sending fake signals (setting
TIF_SIGPENDING). Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.Quoted 9 lines
This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit
287d5fedb377("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the inner reclaim loop for extended periods. In contrast, reactive reclaim (global/memcg) uses small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing it to return to the outer loop and check signals frequently.
Quoted 4 lines
So
287d5fedb377led to suspend failures on MGLRU-using kernels.That's a regression which justifies a Fixes: and a cc:stable, don't people agree?
I believe this should have both Fixes: 287d5fedb377 and 94968384dde1.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend
In reply to Richard ChangQuoted 40 lines · Richard Chang
Proactive reclaim (triggered via memory.reclaim or node sysfs) checks for pending signals in its outer loop in
user_proactive_reclaim(). However, the inner reclaim loops—specifically scanning cgroups inshrink_many()and evicting/aging folios in try_to_shrink_lruvec()—can run for a long time before returning to the outer loop, especially on systems with many cgroups or large memory sizes.During system suspend, the PM freezer attempts to freeze all tasks by sending fake signals (setting
TIF_SIGPENDING). Because the inner loops do not check for pending signals, the proactive reclaim task can remain stuck in kernel space for seconds, failing to enter the refrigerator in a timely manner. This leads to suspend failures due to freeze timeouts, a behavior observed on Android devices.This latency issue is specific to proactive reclaim because of its large, user-defined reclaim targets (could be gigabytes). Since commit
287d5fedb377("mm: memcg: use larger batches for proactive reclaim"), proactive reclaim uses larger decaying batch sizes (starting at 1/4 of the remaining target) to maintain throughput. This keeps the task in the inner reclaim loop for extended periods. In contrast, reactive reclaim (global/memcg) uses small targets (SWAP_CLUSTER_MAX, typically 32 pages), allowing it to return to the outer loop and check signals frequently.To fix this, add a
signal_pending()check toshould_abort_scan()for proactive reclaim paths. Sinceshould_abort_scan()is called within the inner scanning and eviction loops, this allows proactive reclaim to abort early and return to the outer loop inuser_proactive_reclaim().Additionally, return
-ERESTARTSYSinstead of-EINTRinuser_proactive_reclaim(). When interrupted by system suspend, returning-ERESTARTSYSallows the task to enter the refrigerator and automatically restart the syscall upon resume, making the freezer transparent to userspace. For real signals, the signal layer will either restart the syscall (ifSA_RESTARTis set) or return-EINTRto userspace.This fix specifically targets Multi-Gen LRU (MGLRU). Classic LRU's scan targets per iteration are strictly bounded by
get_scan_count(), which ensures it returns to the outer loop more frequently.
Quoted 7 lines
The check in
should_abort_scan()is limited to proactive reclaim (sc->proactive) to avoid inadvertently affecting reactive reclaim paths, and is wrapped inunlikely()as it is a slow path.Suggested-by Michal Hocko <[email protected]>Suggested-by Oleg Nesterov <[email protected]>Signed-off-by Richard Chang <[email protected]>
Thanks
Quoted 41 lines
---
v2: Update the commit message
v3: Return-ERESTARTSYSinstead of-EINTRinuser_proactive_reclaim
v4: Clarify-ERESTARTSYSvsSA_RESTARTbehaviormm/vmscan.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)mm/vmscan.c +11
-1@@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)int i;enum zone_watermarks mark; +if (unlikely (sc->proactive &&signal_pending (current))) +return true; +if (sc->nr_reclaimed >=max (sc->nr_to_reclaim,compact_gap (sc->order)))return true;@@ -7909,8 +7912,15 @@ int user_proactive_reclaim(char *buf,unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) /4 ;unsigned long reclaimed; +/* +* Return -ERESTARTSYS to allow the freezer to interrupt the +* task. The syscall will be transparently restarted upon +* resume. For real signals, it either restarts the syscall +* (if SA_RESTART is set) or is converted to -EINTR by the +* signal layer. +*/ if (signal_pending (current)) -return -EINTR ; +return -ERESTARTSYS ;/* * This is the final attempt, drain percpu lru caches in the Signature · 1 line
2.55.0.229.g6434b31f56-goog
Signature · 2 lines
Michal Hocko SUSE Labs