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

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups org.kernel.vger.stable,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <anNjdDxP5-Oq5eXk@lucifer>
On Wed, Aug 05, 2026 at 06:21:30PM +0200, Cédric Le Goater wrote:
> Thanks for the quick feedback Lorenzo !
> > So I think it should be something more like the attached.
> >
> > That way all the handling remains the same and the override is applied in
> > the right place plus smaps keeps working.
>
> LGTM, do you want me to respin a v2 with what's below ? or you'd rather
> send it yourself.

Thanks, I think as it's somewhat divergent maybe better if I send it with
Reported-by/Closes if that makes sense to you?

I'd like to get David's input on it first however!

>
> C.
>
>
>
> > ----8<----
> >  From d6537260722c8741586e6295c8eea68d06087efa Mon Sep 17 00:00:00 2001
> > From: "Lorenzo Stoakes (ARM)" <[email protected]>
> > Date: Wed, 5 Aug 2026 11:35:13 +0100
> > Subject: [PATCH] ideas
> >
> > ---
> >   mm/huge_memory.c | 32 +++++++++++++++++++++++++++++---
> >   1 file changed, 29 insertions(+), 3 deletions(-)
> >
> > 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;
> >
> >   		/*
> > --
> > 2.55.0
> >
>

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.