Re: [PATCH] mm/huge_memory: let special huge VMAs bypass the THP policy check

From: Matthew Wilcox

Date: Wed Aug 05 2026 - 21:47:13 EST


On Wed, Aug 05, 2026 at 11:41:46AM +0100, Lorenzo Stoakes (ARM) wrote:
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index abc65d608c23..5fa01364f089 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -111,6 +111,34 @@ static bool vma_is_special_huge(const struct vm_area_struct *vma)
> return vma_test_any(vma, VMA_PFNMAP_BIT, VMA_MIXEDMAP_BIT);
> }
>
> +static bool should_obey_thp_file_tunables(const struct vm_area_struct *vma,
> + bool forced_collapse)
> +{
> + if (forced_collapse)
> + return false;
> + VM_WARN_ON_ONCE(vma_is_anonymous(vma));
> + /* Huge PFN mappings allocate no folios so the policy doesn't apply. */
> + if (vma_test(vma, VMA_PFNMAP_BIT) && vma->vm_ops->huge_fault)
> + return false;
> + return true;
> +}
> +
> +static bool can_thp_collapse_file(const struct vm_area_struct *vma,
> + vm_flags_t vm_flags, bool forced_collapse)
> +{
> + /* Override THP tunables? */
> + if (!should_obey_thp_file_tunables(vma, forced_collapse))
> + return true;
> + /* THP=always? */
> + if (hugepage_global_always())
> + return true;
> + /* THP=madvise? */
> + if (!hugepage_global_enabled())
> + return false;
> + /* Has VMA had madvise(..., MADV_HUGEPAGE) applied to it? */
> + return vm_flags & VM_HUGEPAGE;
> +}
> +
> unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
> vm_flags_t vm_flags,
> enum tva_type type,
> @@ -188,9 +216,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
> * Enforce THP collapse requirements as necessary. Anonymous vmas
> * were already handled in thp_vma_allowable_orders().
> */
> - if (!forced_collapse &&
> - (!hugepage_global_enabled() || (!(vm_flags & VM_HUGEPAGE) &&
> - !hugepage_global_always())))
> + if (!can_thp_collapse_file(vma, vm_flags, forced_collapse))
> return 0;
>
> /*

I think 'thp_' in all of this is confusing. DAX isn't THPs. PFNMAPs
aren't THPa. There's other reasons to implement huge_fault that aren't
THPs. Can we rename all of this to drop the 'thp_' string, starting
with thp_vma_allowable_order()?