Re: [stable-6.6.y] mm: khugepaged refuses to freeze

From: Baolin Wang

Date: Tue Feb 10 2026 - 05:08:16 EST




On 2/10/26 11:21 AM, Sergey Senozhatsky wrote:
On (26/02/06 10:00), David Hildenbrand (Arm) wrote:
I recall that there is a notifier when the system is preparing to
sleep (pm notifier or something). Could we simply hook into that to
tell khugepaged to suspend+resume?

Do you mean “struct dev_pm_ops”, which is used to register PM callbacks
for devices? However, I don’t know how to use it with a kernel thread.

Also look at how kswapd does it, kswapd also uses
kthread_freezable_should_stop() to check the freeze state.

Right, mimicking what kswapd does sound reasonable!

I may be missing something, as I'm not seeing dev_pm_ops in vmscan code.
Would something like this work?

---

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index fa6a018b20a8..c5d89ec223d3 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -394,8 +394,12 @@ static inline int hpage_collapse_test_exit(struct mm_struct *mm)
static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm)
{
+ bool was_frozen;
+ int ret = kthread_freezable_should_stop(&was_frozen);
+
return hpage_collapse_test_exit(mm) ||
- mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm);
+ mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) ||
+ was_frozen || ret;
}

Since the hpage_collapse_test_exit_or_disable() can be called by madvise_callapse(), which is not a kernel thread. So I think using the try_to_freeze() is enough? or pass the cc->is_khugepaged to check if current thread is khugepaged.