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

Configure Feed

Select the types of activity you want to include in your feed.

mm: shmem: allow fallback to smaller large orders for tmpfs mmap() access

After commit 69e0a3b49003 ("mm: shmem: fix the strategy for the tmpfs
'huge=' options"), we have fixed the large order allocation strategy for
tmpfs, which always tries PMD-sized large folios first, and if that fails,
falls back to smaller large folios. For tmpfs large folio allocation via
mmap(), we should maintain the same strategy as well. Let's unify the
large order allocation strategy for tmpfs.

There is no functional change for large folio allocation of anonymous shmem.

Link: https://lkml.kernel.org/r/283a0bdfd6ac7aa334a491422bcae70919c572bd.1763008453.git.baolin.wang@linux.alibaba.com
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baolin Wang and committed by
Andrew Morton
8826f096 1b1a4e4d

+3 -14
+3 -14
mm/shmem.c
··· 645 645 * the mTHP interface, so we still use PMD-sized huge order to 646 646 * check whether global control is enabled. 647 647 * 648 - * For tmpfs mmap()'s huge order, we still use PMD-sized order to 649 - * allocate huge pages due to lack of a write size hint. 650 - * 651 648 * For tmpfs with 'huge=always' or 'huge=within_size' mount option, 652 649 * we will always try PMD-sized order first. If that failed, it will 653 650 * fall back to small large folios. 654 651 */ 655 652 switch (SHMEM_SB(inode->i_sb)->huge) { 656 653 case SHMEM_HUGE_ALWAYS: 657 - if (vma) 658 - return maybe_pmd_order; 659 - 660 654 return THP_ORDERS_ALL_FILE_DEFAULT; 661 655 case SHMEM_HUGE_WITHIN_SIZE: 662 - if (vma) 663 - within_size_orders = maybe_pmd_order; 664 - else 665 - within_size_orders = THP_ORDERS_ALL_FILE_DEFAULT; 666 - 667 - within_size_orders = shmem_get_orders_within_size(inode, within_size_orders, 668 - index, write_end); 656 + within_size_orders = shmem_get_orders_within_size(inode, 657 + THP_ORDERS_ALL_FILE_DEFAULT, index, write_end); 669 658 if (within_size_orders > 0) 670 659 return within_size_orders; 671 660 672 661 fallthrough; 673 662 case SHMEM_HUGE_ADVISE: 674 663 if (vm_flags & VM_HUGEPAGE) 675 - return maybe_pmd_order; 664 + return THP_ORDERS_ALL_FILE_DEFAULT; 676 665 fallthrough; 677 666 default: 678 667 return 0;