Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/mmap: teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings

Patch series "Unify hugetlb into arch_get_unmapped_area functions", v4.

This is an attempt to get rid of a fair amount of duplicated code wrt.
hugetlb and *get_unmapped_area* functions.

HugeTLB registers a .get_unmapped_area function which gets called from
__get_unmapped_area().
hugetlb_get_unmapped_area() is defined by a bunch of architectures and
it also has a generic definition for those that do not define it.
Short-long story is that there is a ton of duplicated code between
specific hugetlb *_get_unmapped_area_* functions and mm-core functions,
so we can do better by teaching arch_get_unmapped_area* functions how
to deal with hugetlb mappings.

Note that not a lot of things need to be taught though.
hugetlb_get_unmapped_area, that gets called for hugetlb mappings, runs
some sanity checks prior to calling mm_get_unmapped_area_vmflags(), so we
do not need to that down the road in the respective
{generic,arch}_get_unmapped_area* functions.

More information can be found in the respective patches.

LTP mmapstress hugetlb selftests were ran succesfully on:


This patch (of 9):

We want to stop special casing hugetlb mappings and make them go through
generic channels, so teach generic_get_unmapped_area{_topdown} to handle
those. The main difference is that we set info.align_mask for huge
mappings.

Link: https://lkml.kernel.org/r/20241007075037.267650-1-osalvador@suse.de
Link: https://lkml.kernel.org/r/20241007075037.267650-2-osalvador@suse.de
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@redhat.com>
Cc: Donet Tom <donettom@linux.ibm.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Oscar Salvador and committed by
Andrew Morton
7f24cbc9 04f315a7

+14
+10
include/linux/hugetlb.h
··· 1035 1035 */ 1036 1036 bool is_raw_hwpoison_page_in_hugepage(struct page *page); 1037 1037 1038 + static inline unsigned long huge_page_mask_align(struct file *file) 1039 + { 1040 + return PAGE_MASK & ~huge_page_mask(hstate_file(file)); 1041 + } 1042 + 1038 1043 #else /* CONFIG_HUGETLB_PAGE */ 1039 1044 struct hstate {}; 1045 + 1046 + static inline unsigned long huge_page_mask_align(struct file *file) 1047 + { 1048 + return 0; 1049 + } 1040 1050 1041 1051 static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio) 1042 1052 {
+4
mm/mmap.c
··· 776 776 info.low_limit = mm->mmap_base; 777 777 info.high_limit = mmap_end; 778 778 info.start_gap = stack_guard_placement(vm_flags); 779 + if (filp && is_file_hugepages(filp)) 780 + info.align_mask = huge_page_mask_align(filp); 779 781 return vm_unmapped_area(&info); 780 782 } 781 783 ··· 828 826 info.low_limit = PAGE_SIZE; 829 827 info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); 830 828 info.start_gap = stack_guard_placement(vm_flags); 829 + if (filp && is_file_hugepages(filp)) 830 + info.align_mask = huge_page_mask_align(filp); 831 831 addr = vm_unmapped_area(&info); 832 832 833 833 /*