On Wed, Sep 10, 2025 at 1:11 PM Lance Yang <lance.yang@xxxxxxxxx> wrote: > > Hey Yafang, > > On 2025/9/10 10:44, Yafang Shao wrote: > > Since a task with MMF_DISABLE_THP_COMPLETELY cannot use THP, remove it from > > the khugepaged_mm_slot to stop khugepaged from processing it. > > > > After this change, the following semantic relationship always holds: > > > > MMF_VM_HUGEPAGE is set == task is in khugepaged mm_slot > > MMF_VM_HUGEPAGE is not set == task is not in khugepaged mm_slot > > > > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> > > Cc: Lance Yang <ioworker0@xxxxxxxxx> > > --- > > include/linux/khugepaged.h | 1 + > > kernel/sys.c | 6 ++++++ > > mm/khugepaged.c | 19 +++++++++---------- > > 3 files changed, 16 insertions(+), 10 deletions(-) > > > > diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h > > index eb1946a70cff..6cb9107f1006 100644 > > --- a/include/linux/khugepaged.h > > +++ b/include/linux/khugepaged.h > > @@ -19,6 +19,7 @@ extern void khugepaged_min_free_kbytes_update(void); > > extern bool current_is_khugepaged(void); > > extern int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, > > bool install_pmd); > > +bool hugepage_pmd_enabled(void); > > > > static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) > > { > > diff --git a/kernel/sys.c b/kernel/sys.c > > index a46d9b75880b..a1c1e8007f2d 100644 > > --- a/kernel/sys.c > > +++ b/kernel/sys.c > > @@ -8,6 +8,7 @@ > > #include <linux/export.h> > > #include <linux/mm.h> > > #include <linux/mm_inline.h> > > +#include <linux/khugepaged.h> > > #include <linux/utsname.h> > > #include <linux/mman.h> > > #include <linux/reboot.h> > > @@ -2493,6 +2494,11 @@ static int prctl_set_thp_disable(bool thp_disable, unsigned long flags, > > mm_flags_clear(MMF_DISABLE_THP_COMPLETELY, mm); > > mm_flags_clear(MMF_DISABLE_THP_EXCEPT_ADVISED, mm); > > } > > + > > + if (!mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) && > > + !mm_flags_test(MMF_VM_HUGEPAGE, mm) && > > + hugepage_pmd_enabled()) > > + __khugepaged_enter(mm); > > mmap_write_unlock(current->mm); > > One minor style suggestion for prctl_set_thp_disable(): > > static int prctl_set_thp_disable(bool thp_disable, unsigned long flags, > unsigned long arg4, unsigned long arg5) > { > struct mm_struct *mm = current->mm; > > [...] > if (mmap_write_lock_killable(current->mm)) > return -EINTR; > [...] > mmap_write_unlock(current->mm); > return 0; > } > > It initializes struct mm_struct *mm = current->mm; at the beginning, but > then uses both mm and current->mm. Could you change the calls using > current->mm to use the local mm variable for consistency? Just a nit ;) Nice catch Hello Andrew, David, The original commit "prctl: extend PR_SET_THP_DISABLE to optionally exclude VM_HUGEPAGE" is still in mm-new branch. The change below is a minor cleanup for it. Could we please fold this change directly into the original commit to keep the history clean? diff --git a/kernel/sys.c b/kernel/sys.c index a46d9b7..2250a32 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2479,7 +2479,7 @@ static int prctl_set_thp_disable(bool thp_disable, unsigned long flags, /* Flags are only allowed when disabling. */ if ((!thp_disable && flags) || (flags & ~PR_THP_DISABLE_EXCEPT_ADVISED)) return -EINVAL; - if (mmap_write_lock_killable(current->mm)) + if (mmap_write_lock_killable(mm)) return -EINTR; if (thp_disable) { if (flags & PR_THP_DISABLE_EXCEPT_ADVISED) { @@ -2493,7 +2493,7 @@ static int prctl_set_thp_disable(bool thp_disable, unsigned long flags, mm_flags_clear(MMF_DISABLE_THP_COMPLETELY, mm); mm_flags_clear(MMF_DISABLE_THP_EXCEPT_ADVISED, mm); } - mmap_write_unlock(current->mm); + mmap_write_unlock(mm); return 0; } -- Regards Yafang