The THP mode check in __thp_vma_allowable_orders() runs before the clause that trusts huge_fault() handlers, so huge pfnmaps only materialize when THP is set to "always". The THP modes exist to limit the memory and khugepaged costs of transparent hugepages. Special mappings are backed by pfns instead of THP folios and khugepaged never scans them, so those costs do not apply and we can exempt special mappings from the mode check. This also makes THPeligible in smaps report 1 for such mappings. This matters for VFIO device passthrough on distributions where the default THP mode is "madvise". Mapping a 128 GiB GPU BAR through VFIO_IOMMU_MAP_DMA costs 33.5 million order 0 faults and 20.7 seconds when the mode denies huge pfnmaps. With huge pfnmaps allowed, the same mapping takes 128 PUD faults and 0.4 seconds. Signed-off-by: Saravanan D --- mm/huge_memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index afbb5974bd22..bc61b8020af6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -193,9 +193,10 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, if (!vma_is_anonymous(vma)) { /* * Enforce THP collapse requirements as necessary. Anonymous vmas - * were already handled in thp_vma_allowable_orders(). + * were already handled in thp_vma_allowable_orders(). Special + * mappings have no THP costs and are exempt. */ - if (!forced_collapse && + if (!forced_collapse && !vma_is_special_huge(vma) && (!hugepage_global_enabled() || (!(vm_flags & VM_HUGEPAGE) && !hugepage_global_always()))) return 0; base-commit: a032d41a86cb82a747bc14d9c82b3e153a9a9ab7 -- 2.53.0