On Fri, Jun 05, 2026 at 10:14:17AM -0600, Nico Pache wrote:
> Add collapse_possible_orders() to generalize THP order eligibility. The
> function determines which THP orders are permitted based on collapse
> context (khugepaged vs madv_collapse). We also add collapse_possible()
> as a thin wrapper around collapse_possible_orders() that returns a bool
> rather than the whole bitmap.
>
> This consolidates collapse configuration logic and provides a clean
> interface for future mTHP collapse support where the orders may be
> different.
>
> Acked-by: David Hildenbrand (Arm) <[email protected]>
> Reviewed-by: Baolin Wang <[email protected]>
> Signed-off-by: Nico Pache <[email protected]>

LGTM, so:

Reviewed-by: Lorenzo Stoakes <[email protected]>

> ---
>  mm/khugepaged.c | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 26c343a6fa3d..ec886a031952 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -554,12 +554,30 @@ void __khugepaged_enter(struct mm_struct *mm)
>               wake_up_interruptible(&khugepaged_wait);
>  }
>
> +/*
> + * Check what orders are possible based on the vma and collapse type.
> + * This is used to determine if mTHP collapse is a viable option.
> + */
> +static unsigned long collapse_possible_orders(struct vm_area_struct *vma,
> +             vm_flags_t vm_flags, enum tva_type tva_flags)
> +{
> +     const unsigned long orders = BIT(HPAGE_PMD_ORDER);
> +
> +     return thp_vma_allowable_orders(vma, vm_flags, tva_flags, orders);
> +}
> +
> +static bool collapse_possible(struct vm_area_struct *vma,
> +             vm_flags_t vm_flags, enum tva_type tva_flags)
> +{
> +     return collapse_possible_orders(vma, vm_flags, tva_flags);
> +}
> +
>  void khugepaged_enter_vma(struct vm_area_struct *vma,
>                         vm_flags_t vm_flags)
>  {
>       if (!mm_flags_test(MMF_VM_HUGEPAGE, vma->vm_mm) &&
>           hugepage_pmd_enabled()) {
> -             if (thp_vma_allowable_order(vma, vm_flags, TVA_KHUGEPAGED, 
> PMD_ORDER))
> +             if (collapse_possible(vma, vm_flags, TVA_KHUGEPAGED))
>                       __khugepaged_enter(vma->vm_mm);
>       }
>  }
> @@ -2700,7 +2718,7 @@ static void collapse_scan_mm_slot(unsigned int 
> progress_max,
>                       cc->progress++;
>                       break;
>               }
> -             if (!thp_vma_allowable_order(vma, vma->vm_flags, 
> TVA_KHUGEPAGED, PMD_ORDER)) {
> +             if (!collapse_possible(vma, vma->vm_flags, TVA_KHUGEPAGED)) {
>                       cc->progress++;
>                       continue;
>               }
> @@ -3010,7 +3028,7 @@ int madvise_collapse(struct vm_area_struct *vma, 
> unsigned long start,
>       BUG_ON(vma->vm_start > start);
>       BUG_ON(vma->vm_end < end);
>
> -     if (!thp_vma_allowable_order(vma, vma->vm_flags, TVA_FORCED_COLLAPSE, 
> PMD_ORDER))
> +     if (!collapse_possible(vma, vma->vm_flags, TVA_FORCED_COLLAPSE))
>               return -EINVAL;
>
>       cc = kmalloc_obj(*cc);
> --
> 2.54.0
>

Reply via email to