Skip to content

Commit 34d7cf6

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: don't try THP alignment for FS without get_unmapped_area
Commit ed48e87 ("thp: add thp_get_unmapped_area_vmflags()") changes thp_get_unmapped_area() to thp_get_unmapped_area_vmflags() in __get_unmapped_area(), which doesn't initialize local get_area for anonymous mappings. This leads to us always trying THP alignment even for file_operations which have a NULL ->get_unmapped_area() callback. Since commit efa7df3 ("mm: align larger anonymous mappings on THP boundaries") we only want to enable THP alignment for anonymous mappings, so add a !file check to avoid attempting THP alignment for file mappings. Found issue by code inspection. THP alignment is used for easy or more pmd mappings, from vma side. This may cause unnecessary VMA fragmentation and potentially worse performance on filesystems that do not actually support THPs and thus cannot benefit from the alignment. Link: https://lkml.kernel.org/r/[email protected] Fixes: ed48e87 ("thp: add thp_get_unmapped_area_vmflags()") Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Reviewed-by: Yang Shi <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jann Horn <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Rick Edgecombe <[email protected]> Cc: Ryan Roberts <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6aaced5 commit 34d7cf6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
892892

893893
if (get_area) {
894894
addr = get_area(file, addr, len, pgoff, flags);
895-
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)
895+
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && !file
896896
&& !addr /* no hint */
897897
&& IS_ALIGNED(len, PMD_SIZE)) {
898898
/* Ensures that larger anonymous mappings are THP aligned. */

0 commit comments

Comments
 (0)