The patch titled Subject: mm: khugepaged: reorg some khugepaged helpers has been added to the -mm mm-unstable branch. Its filename is mm-khugepaged-reorg-some-khugepaged-helpers.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-khugepaged-reorg-some-khugepaged-helpers.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Yang Shi <shy828301@xxxxxxxxx> Subject: mm: khugepaged: reorg some khugepaged helpers Date: Wed, 15 Jun 2022 10:29:25 -0700 The khugepaged_{enabled|always|req_madv} are not khugepaged only anymore, move them to huge_mm.h and rename to hugepage_flags_xxx, and remove khugepaged_req_madv due to no users. Also move khugepaged_defrag to khugepaged.c since its only caller is in that file, it doesn't have to be in a header file. Link: https://lkml.kernel.org/r/20220615172926.546974-7-shy828301@xxxxxxxxx Signed-off-by: Yang Shi <shy828301@xxxxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: Miaohe Lin <linmiaohe@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Cc: Zach O'Keefe <zokeefe@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/huge_mm.h | 8 ++++++++ include/linux/khugepaged.h | 14 -------------- mm/huge_memory.c | 4 ++-- mm/khugepaged.c | 18 +++++++++++------- 4 files changed, 21 insertions(+), 23 deletions(-) --- a/include/linux/huge_mm.h~mm-khugepaged-reorg-some-khugepaged-helpers +++ a/include/linux/huge_mm.h @@ -116,6 +116,14 @@ extern struct kobj_attribute shmem_enabl extern unsigned long transparent_hugepage_flags; +#define hugepage_flags_enabled() \ + (transparent_hugepage_flags & \ + ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \ + (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))) +#define hugepage_flags_always() \ + (transparent_hugepage_flags & \ + (1<<TRANSPARENT_HUGEPAGE_FLAG)) + /* * Do the below checks: * - For file vma, check if the linear page offset of vma is --- a/include/linux/khugepaged.h~mm-khugepaged-reorg-some-khugepaged-helpers +++ a/include/linux/khugepaged.h @@ -24,20 +24,6 @@ static inline void collapse_pte_mapped_t } #endif -#define khugepaged_enabled() \ - (transparent_hugepage_flags & \ - ((1<<TRANSPARENT_HUGEPAGE_FLAG) | \ - (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))) -#define khugepaged_always() \ - (transparent_hugepage_flags & \ - (1<<TRANSPARENT_HUGEPAGE_FLAG)) -#define khugepaged_req_madv() \ - (transparent_hugepage_flags & \ - (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)) -#define khugepaged_defrag() \ - (transparent_hugepage_flags & \ - (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG)) - static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) { if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags)) --- a/mm/huge_memory.c~mm-khugepaged-reorg-some-khugepaged-helpers +++ a/mm/huge_memory.c @@ -117,11 +117,11 @@ bool hugepage_vma_check(struct vm_area_s if (!in_pf && shmem_file(vma->vm_file)) return shmem_huge_enabled(vma); - if (!khugepaged_enabled()) + if (!hugepage_flags_enabled()) return false; /* THP settings require madvise. */ - if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) + if (!(vm_flags & VM_HUGEPAGE) && !hugepage_flags_always()) return false; /* Only regular file is valid */ --- a/mm/khugepaged.c~mm-khugepaged-reorg-some-khugepaged-helpers +++ a/mm/khugepaged.c @@ -465,7 +465,7 @@ void khugepaged_enter_vma(struct vm_area unsigned long vm_flags) { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && - khugepaged_enabled()) { + hugepage_flags_enabled()) { if (hugepage_vma_check(vma, vm_flags, false, false)) __khugepaged_enter(vma->vm_mm); } @@ -757,6 +757,10 @@ static bool khugepaged_scan_abort(int ni return false; } +#define khugepaged_defrag() \ + (transparent_hugepage_flags & \ + (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG)) + /* Defrag for khugepaged will enter direct reclaim/compaction if necessary */ static inline gfp_t alloc_hugepage_khugepaged_gfpmask(void) { @@ -854,7 +858,7 @@ static struct page *khugepaged_alloc_hug khugepaged_alloc_sleep(); } else count_vm_event(THP_COLLAPSE_ALLOC); - } while (unlikely(!hpage) && likely(khugepaged_enabled())); + } while (unlikely(!hpage) && likely(hugepage_flags_enabled())); return hpage; } @@ -2173,7 +2177,7 @@ breakouterloop_mmap_lock: static int khugepaged_has_work(void) { return !list_empty(&khugepaged_scan.mm_head) && - khugepaged_enabled(); + hugepage_flags_enabled(); } static int khugepaged_wait_event(void) @@ -2238,7 +2242,7 @@ static void khugepaged_wait_work(void) return; } - if (khugepaged_enabled()) + if (hugepage_flags_enabled()) wait_event_freezable(khugepaged_wait, khugepaged_wait_event()); } @@ -2269,7 +2273,7 @@ static void set_recommended_min_free_kby int nr_zones = 0; unsigned long recommended_min; - if (!khugepaged_enabled()) { + if (!hugepage_flags_enabled()) { calculate_min_free_kbytes(); goto update_wmarks; } @@ -2319,7 +2323,7 @@ int start_stop_khugepaged(void) int err = 0; mutex_lock(&khugepaged_mutex); - if (khugepaged_enabled()) { + if (hugepage_flags_enabled()) { if (!khugepaged_thread) khugepaged_thread = kthread_run(khugepaged, NULL, "khugepaged"); @@ -2345,7 +2349,7 @@ fail: void khugepaged_min_free_kbytes_update(void) { mutex_lock(&khugepaged_mutex); - if (khugepaged_enabled() && khugepaged_thread) + if (hugepage_flags_enabled() && khugepaged_thread) set_recommended_min_free_kbytes(); mutex_unlock(&khugepaged_mutex); } _ Patches currently in -mm which might be from shy828301@xxxxxxxxx are mm-rmap-use-the-correct-parameter-name-for-define_page_vma_walk.patch mm-pvmw-check-possible-huge-pmd-map-by-transhuge_vma_suitable.patch mm-khugepaged-check-thp-flag-in-hugepage_vma_check.patch mm-thp-consolidate-vma-size-check-to-transhuge_vma_suitable.patch mm-khugepaged-better-comments-for-anon-vma-check-in-hugepage_vma_revalidate.patch mm-thp-kill-transparent_hugepage_active.patch mm-thp-kill-__transhuge_page_enabled.patch mm-khugepaged-reorg-some-khugepaged-helpers.patch doc-proc-fix-the-description-to-thpeligible.patch