Re: [PATCH v3 02/10] mm: introduce pgtable_has_pmd_leaves()
From: Lance Yang
Date: Mon Apr 20 2026 - 03:00:19 EST
On Fri, Apr 17, 2026 at 11:57:54AM +0200, David Hildenbrand (Arm) wrote:
>On 4/10/26 10:19, Lance Yang wrote:
[...]
>>>
>>> #if !defined(MAX_POSSIBLE_PHYSMEM_BITS) && !defined(CONFIG_64BIT)
>>> diff --git a/init/main.c b/init/main.c
>>> index 1cb395dd94e4..07f2ddbf9677 100644
>>> --- a/init/main.c
>>> +++ b/init/main.c
>>> @@ -1044,6 +1044,7 @@ void start_kernel(void)
>>> print_kernel_cmdline(saved_command_line);
>>> /* parameters may set static keys */
>>> parse_early_param();
>>> + init_arch_has_pmd_leaves();
>>
>> One more thought here: I don't see why we need boot-time caching.
>>
>> has_transparent_hugepage() does *not* look expensive on the common
>> archs. On x86, it is just a CPU feature check. MIPS is different, yes,
>> only the first call there is more involved ...
>>
>> But if we *really* want caching, couldn't we just do it lazily instead
>> of adding another early boot init step?
>>
>> Something like:
>>
>> bool pgtable_has_pmd_leaves(void)
>> {
>> static int __arch_has_pmd_leaves = -1;
>>
>> if (READ_ONCE(__arch_has_pmd_leaves) < 0)
>> WRITE_ONCE(__arch_has_pmd_leaves, has_transparent_hugepage());
>>
>> return READ_ONCE(__arch_has_pmd_leaves);
>
>Would look easier when just using two booleans: "has_pmd_leaves" and
>"probed".
>
>I do like static keys, though. And wonder whether just putting that into
>hugepage_init() would be sufficient?
Probably sufficient for the current callers, yes, since they are all
THP-related :)
But then the helper may return false simply because THP is not built,
rather than because the CPU lacks PMD leaf support, which does not match
its semantics very well.
To be clear, I like static keys too, as I suggested earlier ;)
Another boot-time init step that depends on specific init ordering seems
a bit shaky to me... At the very least, we'd need to document that
ordering very clearly.
Cheers,
Lance