Re: [RFT PATCH v2 03/23] x86/boot: Drop global variables keeping track of LA57 state

Ingo Molnar
2025-05-05T21:51:12Z

* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> > - PGDIR_SHIFT: (inlined 156 times)
>
> Several of those are actually of the form
>
> #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
>
> so you artificially see PGDIR_SHIFT as the important part, even though
> it's often a different constant entirely that just gets generated
> using it.

Yeah, I only examined the first level use.

Here's the stats for PGDIR_SIZE:

31 ffffffff844cde5c <stat__pgtable_l5_enabled_PGDIR_SIZE>
157 ffffffff844cdea0 <stat__pgtable_l5_enabled_PGDIR_SHIFT> # total: includes PGDIR_SIZE

Ie. only about 19% of PGDIR_SHIFT use is PGDIR_SIZE.

> > - PTRS_PER_P4D: (inlined 46 times)
> > This too could be implemented via a precomputed constant percpu
> > value (per_cpu__x86_PTRS_PER_P4D), eliminating a branch,
> > or via an ALTERNATIVE() immediate constant.
>
> Again, we do have that, although the 64-bit constant is a bit wasteful.

Adds 4 bytes to the size of the MOVQ. Not the end of the world, but I
suspect for x86-specific values that flag off a CPU-feature flag (which
is the case here) we can use the ALTERNATIVE_CONST_U32() trick and have
it all in a single place.

> The reason runtime-const does a 64-bit constant is that the actual
> performance-critical cases were for big constants (TASK_SIZE) and for
> pointers (hash table pointers).

I remembered that we had something in this area, but I grepped for
'alternative.*const' which found nothing, while runtime_const uses its
own simple text-patching method a.k.a. runtime_const_fixup(). :-)

Thanks,

Ingo