Re: [PATCH v5 14/14] mm: thp: always enable mTHP support

From: Lance Yang

Date: Wed Jun 03 2026 - 03:59:47 EST




On 2026/6/3 15:23, Baolin Wang wrote:


On 6/3/26 2:47 PM, Lance Yang wrote:
Hi Luiz,

SHMEM_HUGE_FORCE still assumes PMD order in a few places.

Is that expected?

shmem_init() only sets the default inherit mask when PMD leaves are
available.

    if (!shmem_orders_configured && pgtable_has_pmd_leaves())
        huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER);

But shmem_parse_huge() rejects "force" unless the mask is exactly PMD
order.

    if (huge == SHMEM_HUGE_FORCE &&
        huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER))
        return -EINVAL;

Even if "force" is selected, shmem_huge_global_enabled() still return
only PMD order.

    if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE)
        return maybe_pmd_order;

and shmem_allowable_huge_orders() mask it out.

    if (!pgtable_has_pmd_leaves())
        disabled_orders = BIT(PMD_ORDER);

    if (!vma || !vma_is_anon_shmem(vma))
        return global_orders & ~disabled_orders;

For anon shmem, it can also return 0 for same reason.

    if (shmem_huge == SHMEM_HUGE_FORCE)
        return READ_ONCE(huge_shmem_orders_inherit) & ~disabled_orders;

Should SHMEM_HUGE_FORCE use the available mTHP orders below PMD when
pgtable_has_pmd_leaves() is false?

No. That's exactly the strategy we agreed on after lots of discussion:
1. The options 'force' and 'deny' are dropped for mTHP interfaces, which are rather testing artifacts from the old ages.

2. If top level value is 'force', then only PMD-sized hugepages have enabled="inherit", otherwise configuration will be failed and vice versa.

You can check commit 4b98995530b7 ("mm: shmem: add multi-size THP sysfs interface for anonymous shmem") for more information.

Ah, thanks Baolin, good to know that :D

Cheers, Lance