All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, Peter Xu <peterx@redhat.com>,
	David Hildenbrand <david@kernel.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	Jason Gunthorpe <jgg@nvidia.com>, Zi Yan <ziy@nvidia.com>,
	stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/huge_memory: let special huge VMAs bypass the THP policy check
Date: Wed, 5 Aug 2026 18:21:30 +0200	[thread overview]
Message-ID: <4ddc95f2-8868-4be3-9839-e2d14cf35fef@redhat.com> (raw)
In-Reply-To: <anL-NZkNMSSxN0YN@lucifer>

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.

C.



> ----8<----
>  From d6537260722c8741586e6295c8eea68d06087efa Mon Sep 17 00:00:00 2001
> From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
> 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
> 



  reply	other threads:[~2026-08-05 16:21 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  5:55 [PATCH] mm/huge_memory: let special huge VMAs bypass the THP policy check Cédric Le Goater
2026-08-05 10:41 ` Lorenzo Stoakes (ARM)
2026-08-05 16:21   ` Cédric Le Goater [this message]
2026-08-05 16:26     ` Lorenzo Stoakes (ARM)
2026-08-05 16:29       ` Cédric Le Goater
2026-08-06  1:44   ` Matthew Wilcox
2026-08-06  6:29     ` Lorenzo Stoakes (ARM)
2026-08-06 16:19   ` David Hildenbrand (Arm)
2026-08-06 16:34     ` Cédric Le Goater
2026-08-06 16:45       ` David Hildenbrand (Arm)
2026-08-05 12:15 ` Jason Gunthorpe
2026-08-05 16:29   ` Lorenzo Stoakes (ARM)
2026-08-05 16:52     ` Jason Gunthorpe
2026-08-05 16:54       ` Lorenzo Stoakes (ARM)
2026-08-06 14:26 ` David Hildenbrand (Arm)
2026-08-06 14:28   ` Lorenzo Stoakes (ARM)
2026-08-06 14:42     ` Cédric Le Goater
2026-08-06 14:47       ` David Hildenbrand (Arm)
2026-08-06 14:53         ` Cédric Le Goater
2026-08-06 14:59           ` David Hildenbrand (Arm)
2026-08-06 16:45         ` Jason Gunthorpe
2026-08-06 16:47           ` David Hildenbrand (Arm)
2026-08-06 16:50           ` AI slop (was Re: [PATCH] mm/huge_memory: let special huge VMAs bypass the THP) " Lorenzo Stoakes (ARM)
2026-08-06 17:05             ` John Hubbard
2026-08-06 17:08               ` Zi Yan
2026-08-06 17:40                 ` Gregory Price
2026-08-06 17:42                   ` Lorenzo Stoakes (ARM)
2026-08-06 19:28                     ` Gregory Price
2026-08-06 19:33                       ` Lorenzo Stoakes (ARM)
2026-08-06 17:42                   ` Zi Yan
2026-08-06 17:41                 ` Lorenzo Stoakes (ARM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ddc95f2-8868-4be3-9839-e2d14cf35fef@redhat.com \
    --to=clg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=david@kernel.org \
    --cc=jgg@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=peterx@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.