Re: [PATCH v3 02/10] mm: introduce pgtable_has_pmd_leaves()
From: Luiz Capitulino
Date: Thu Apr 09 2026 - 14:23:13 EST
On 2026-04-09 08:26, Lance Yang wrote:
+Cc THP
On Wed, Apr 08, 2026 at 04:22:57PM -0400, Luiz Capitulino wrote:
Currently, we have two helpers that check for PMD-sized pages but have
different names and slightly different semantics:
- has_transparent_hugepage(): the name suggests it checks if THP is
enabled, but when CONFIG_TRANSPARENT_HUGEPAGE=y and the architecture
implements this helper, it actually checks if the CPU supports
PMD-sized pages
- thp_disabled_by_hw(): the name suggests it checks if THP is disabled
by the hardware, but it just returns a cached value acquired with
has_transparent_hugepage(). This helper is used in fast paths
This commit introduces a new helper called pgtable_has_pmd_leaves()
which is intended to replace both has_transparent_hugepage() and
thp_disabled_by_hw(). pgtable_has_pmd_leaves() has very clear semantics:
it returns true if the CPU supports PMD-sized pages and false otherwise.
It always returns a cached value, so it can be used in fast paths.
Set once at boot and then read in hot paths, would a static key be a
better fit there instead? Something like:
This looks like a good suggestion, if nobody opposes I can do this for v4
(although it may delay inclusion a bit).
DEFINE_STATIC_KEY_FALSE(arch_has_pmd_leaves_key);
static inline bool pgtable_has_pmd_leaves(void)
{
return static_branch_unlikely(&arch_has_pmd_leaves_key);
}
void __init init_arch_has_pmd_leaves(void)
{
if (has_transparent_hugepage())
static_branch_enable(&arch_has_pmd_leaves_key);
}
Cheers,
Lance