* [PATCH] mm: khugepaged: make scan loops suspend aware
@ 2026-02-11 2:59 Sergey Senozhatsky
2026-02-11 3:04 ` Baolin Wang
0 siblings, 1 reply; 3+ messages in thread
From: Sergey Senozhatsky @ 2026-02-11 2:59 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Zi Yan, Baolin Wang
Cc: Liam R . Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, linux-mm, linux-kernel, Sergey Senozhatsky
A number of khugepaaged's loops, e.g. khugepaged_scan_mm_slot(),
are time unbound, which can become problematic during system
suspend:
PM: suspend entry (s2idle)
Filesystems sync: 0.003 seconds
Freezing user space processes
Freezing user space processes completed (elapsed 0.003 seconds)
OOM killer disabled.
Freezing remaining freezable tasks
Freezing remaining freezable tasks failed after 20.004 seconds (1 tasks refusing to freeze, wq_busy=0):
task:khugepaged state:D stack:0 pid:1345 ppid:2 flags:0x00004000
Call Trace:
<TASK>
schedule+0x523/0x16a0
schedule_timeout+0x23b/0x6e0
io_schedule_timeout+0x3f/0x80
wait_for_completion_io_timeout+0xe4/0x170
submit_bio_wait+0x79/0xc0
swap_readpage+0x150/0x2d0
swap_cluster_readahead+0x3be/0x750
shmem_swapin+0xa7/0x100
shmem_swapin_folio+0xcd/0x2e0
shmem_get_folio+0x237/0x580
collapse_file+0x247/0x1280
hpage_collapse_scan_file+0x26e/0x380
khugepaged+0x43b/0x810
kthread+0xfb/0x120
</TASK>
Make hpage_collapse_test_exit_or_disable() suspend aware so
that khugepaaged's scan loops can terminate in a timely manner
and let system enter the sleep state.
Co-developed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
mm/khugepaged.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index eff9e3061925..9b3201fb6840 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -392,10 +392,18 @@ static inline int hpage_collapse_test_exit(struct mm_struct *mm)
return atomic_read(&mm->mm_users) == 0;
}
-static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm)
+static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm,
+ struct collapse_control *cc)
{
+ bool was_frozen = false;
+
+ if (cc->is_khugepaged &&
+ unlikely(kthread_freezable_should_stop(&was_frozen)))
+ return 1;
+
return hpage_collapse_test_exit(mm) ||
- mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm);
+ mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) ||
+ was_frozen;
}
static bool hugepage_pmd_enabled(void)
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mm: khugepaged: make scan loops suspend aware
2026-02-11 2:59 [PATCH] mm: khugepaged: make scan loops suspend aware Sergey Senozhatsky
@ 2026-02-11 3:04 ` Baolin Wang
2026-02-11 3:10 ` Sergey Senozhatsky
0 siblings, 1 reply; 3+ messages in thread
From: Baolin Wang @ 2026-02-11 3:04 UTC (permalink / raw)
To: Sergey Senozhatsky, Andrew Morton, David Hildenbrand,
Lorenzo Stoakes, Zi Yan
Cc: Liam R . Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, linux-mm, linux-kernel
Hi Sergey,
On 2/11/26 10:59 AM, Sergey Senozhatsky wrote:
> A number of khugepaaged's loops, e.g. khugepaged_scan_mm_slot(),
> are time unbound, which can become problematic during system
> suspend:
>
> PM: suspend entry (s2idle)
> Filesystems sync: 0.003 seconds
> Freezing user space processes
> Freezing user space processes completed (elapsed 0.003 seconds)
> OOM killer disabled.
> Freezing remaining freezable tasks
> Freezing remaining freezable tasks failed after 20.004 seconds (1 tasks refusing to freeze, wq_busy=0):
> task:khugepaged state:D stack:0 pid:1345 ppid:2 flags:0x00004000
> Call Trace:
> <TASK>
> schedule+0x523/0x16a0
> schedule_timeout+0x23b/0x6e0
> io_schedule_timeout+0x3f/0x80
> wait_for_completion_io_timeout+0xe4/0x170
> submit_bio_wait+0x79/0xc0
> swap_readpage+0x150/0x2d0
> swap_cluster_readahead+0x3be/0x750
> shmem_swapin+0xa7/0x100
> shmem_swapin_folio+0xcd/0x2e0
> shmem_get_folio+0x237/0x580
> collapse_file+0x247/0x1280
> hpage_collapse_scan_file+0x26e/0x380
> khugepaged+0x43b/0x810
> kthread+0xfb/0x120
> </TASK>
>
> Make hpage_collapse_test_exit_or_disable() suspend aware so
> that khugepaaged's scan loops can terminate in a timely manner
> and let system enter the sleep state.
>
> Co-developed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
I just provided some sample code. Please make sure your patch can be
built before submitting a formal patch.
Obviously, you should also modify the callers to pass in the 'cc' pointer.
> mm/khugepaged.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index eff9e3061925..9b3201fb6840 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -392,10 +392,18 @@ static inline int hpage_collapse_test_exit(struct mm_struct *mm)
> return atomic_read(&mm->mm_users) == 0;
> }
>
> -static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm)
> +static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm,
> + struct collapse_control *cc)
> {
> + bool was_frozen = false;
> +
> + if (cc->is_khugepaged &&
> + unlikely(kthread_freezable_should_stop(&was_frozen)))
> + return 1;
> +
> return hpage_collapse_test_exit(mm) ||
> - mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm);
> + mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) ||
> + was_frozen;
> }
>
> static bool hugepage_pmd_enabled(void)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mm: khugepaged: make scan loops suspend aware
2026-02-11 3:04 ` Baolin Wang
@ 2026-02-11 3:10 ` Sergey Senozhatsky
0 siblings, 0 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2026-02-11 3:10 UTC (permalink / raw)
To: Baolin Wang
Cc: Sergey Senozhatsky, Andrew Morton, David Hildenbrand,
Lorenzo Stoakes, Zi Yan, Liam R . Howlett, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, linux-mm,
linux-kernel
On (26/02/11 11:04), Baolin Wang wrote:
> I just provided some sample code. Please make sure your patch can be built
> before submitting a formal patch.
Oh... Sorry about that! I forgot to squash the commits.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-11 3:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-11 2:59 [PATCH] mm: khugepaged: make scan loops suspend aware Sergey Senozhatsky
2026-02-11 3:04 ` Baolin Wang
2026-02-11 3:10 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox