Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Cédric Le Goater" <clg@redhat.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	linux-mm@kvack.org
Cc: Peter Xu <peterx@redhat.com>, Lorenzo Stoakes <ljs@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: Thu, 6 Aug 2026 16:26:20 +0200	[thread overview]
Message-ID: <0e52d0b4-064d-4602-8e7b-5744b05f24ea@kernel.org> (raw)
In-Reply-To: <20260805055544.1568534-1-clg@redhat.com>

On 8/5/26 07:55, Cédric Le Goater wrote:
> From: Cedric Le Goater <clg@redhat.com>
> 
> The global THP sysfs policy (transparent_hugepage=never/madvise/always)
> gates the huge fault dispatch path in __thp_vma_allowable_orders() for
> all non-anonymous VMAs, including PFN-mapped device BARs (VM_PFNMAP).
> 
> DAX VMAs already bypass this check via an early return:
> 
> 	if (vma_is_dax(vma))
> 		return in_pf ? orders : 0;
> 
> But "special huge" VMAs -- identified by vma_is_special_huge() -- do not
> get this early return, even though they share the same fundamental
> property: they map physical addresses directly into page tables and
> involve no memory allocation, no compaction, no splitting, and no
> reclaim. The THP policy has no meaningful effect on them.
> 
> This matters for VFIO PCI passthrough of large-BAR devices such as
> NVIDIA H200 NVL GPUs (256 GB BAR each). The VFIO driver registers a
> .huge_fault handler (vfio_pci_mmap_huge_fault) that dispatches to
> vmf_insert_pfn_pmd/pud, and QEMU's vfio_region_mmap() aligns the BAR
> mappings for huge page table entries. Both prerequisites are met, but
> with THP=never or THP=madvise, __thp_vma_allowable_orders() returns 0
> before reaching the "trust huge_fault handlers" code.
> 
> The result: each 256 GB BAR is mapped at 4 KiB granularity -- 67 million
> page faults per GPU instead of a few thousand PMD/PUD faults. On hosts
> with 8 GPUs (2 TB of BAR space), this causes VM boot times to degrade
> severely, with 99.98% of CPU time spent in the VFIO BAR mapping path.
> 
> Configurations that trigger this:
>   - transparent_hugepage=never on the kernel command line
>   - The tuned cpu-partitioning profile (inherits network-latency, which
>     sets transparent_hugepages=never via sysfs)
>   - transparent_hugepage=madvise (the RHEL default), since VFIO VMAs
>     lack VM_HUGEPAGE and QEMU does not call madvise(MADV_HUGEPAGE) on
>     BAR mmap regions
> 
> Extend the existing DAX early return to also cover vma_is_special_huge()
> VMAs. This is consistent with how vma_is_special_huge() is already
> treated for supported_orders (grouped with DAX). The mm/Kconfig TODO
> comment "Allow to be enabled without THP" also acknowledges this
> coupling is wrong.
> 
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Fixes: 5dd40721f147 ("mm: allow THP orders for PFNMAPs")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-4
> Signed-off-by: Cedric Le Goater <clg@redhat.com>
> ---
>  mm/huge_memory.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 58cabe6af33d031e48250e21db51506bc46c97b2..6dfef5500a054f09f9ece6df8bf7a0194624350f 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -139,8 +139,12 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
>  	if (thp_disabled_by_hw() || vma_thp_disabled(vma, vm_flags, forced_collapse))
>  		return 0;
>  
> -	/* khugepaged doesn't collapse DAX vma, but page fault is fine. */
> -	if (vma_is_dax(vma))
> +	/*
> +	 * khugepaged doesn't collapse DAX or special huge VMAs, but page
> +	 * fault is fine. These map physical addresses directly — the THP
> +	 * policy is irrelevant for them.

emdash in a code comment?

Then I spot

	Assisted-by: Claude:claude-opus-4

and really have to shake my head.

-- 
Cheers,

David


  parent reply	other threads:[~2026-08-06 14:26 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
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) [this message]
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                   ` Zi Yan
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: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=0e52d0b4-064d-4602-8e7b-5744b05f24ea@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox