Re: [stable-6.6.y] mm: khugepaged refuses to freeze
From: Sergey Senozhatsky
Date: Tue Feb 10 2026 - 05:16:03 EST
On (26/02/10 18:07), Baolin Wang wrote:
> > > > 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?
I guess try_to_freeze() should work.
> or pass the cc->is_khugepaged to check if current thread is khugepaged.
Or I guess I can check `current->flags & PF_KTHREAD` in
hpage_collapse_test_exit_or_disable().