Re: [PATCH RESEND v2 12/21] mm/pgtable: redefine PGTABLE_LEVEL enum with ascend order from PGD

From: Mike Rapoport

Date: Thu Nov 26 2026 - 13:11:13 EST


On Thu, Nov 26, 2026 at 02:30:54PM +0000, Yeoreum Yun wrote:
> On Thu, Nov 26, 2026 at 03:19:13PM +0100, David Hildenbrand (Arm) wrote:
> > On 11/24/26 19:52, Yeoreum Yun wrote:
> > > On Tue, Nov 24, 2026 at 07:05:38PM +0200, Mike Rapoport wrote:
> > >> On Mon, Nov 02, 2026 at 11:21:25AM +0000, Yeoreum Yun wrote:
> > >>> The PGTABLE_LEVEL enum values appear to be ordered in the opposite direction
> > >>> from their intended usage.
> > >>>
> > >>> Intuitively, higher page table levels should have smaller enum values,
> > >>> but PTE is currently assigned 0.
> > >>
> > >> That's not what x86 thinks :)
> > >> They even expose it in /proc/vmstat with smaller numbers meaning lower levels
> > >>
> > >> $ grep direct_map /proc/vmstat
> > >> direct_map_level2_splits 152
> > >> direct_map_level3_splits 4
> > >> direct_map_level2_collapses 0
> > >> direct_map_level3_collapses 0
> > >>
> > >> Just an observation, I don't mind either order.
> > >
> > > Right. I made this change because a depth-based scheme seems more intuitive.
> > >
> > > As you pointed out, though, the x86 specification uses smaller
> > > numbers (0) for lower levels (pte), so I think we can leave the
> > > x86-specific direct_map_* entries as they are.
> >
> > patch #14 depends on this, no?
>
> Interestingly, x86 documentation numbers the PGD level as 4 or 5,
> whereas helpers such as effective_prot_pgd() use 0 for PGD.
>
> Anyway, this follows the usage and semantics of effective_prot_pXd(),
> rather than architecture-specific level numbering, which varies across
> architectures.

I asked an LLM and here's what it told me:

x86, s390, riscv, LoongArch and powerpc count from the leaf. arm64 and
ARM count from the root, and so does the generic page walk and ptdump.

My guess that the only reason that generic ptdump counts from the root is
because it came from @arm.com :)

> And yes, patch #14 depends on this, although changing the condition to
> level != PGD_LEVEL would remove that dependency.

I think the only real hard dependency on levels numbering is x86's KVM code
that manages secondary page tables, but it anyway does not use enum
pgtable_level but rather x86's own enum pg_level.

> --
> Sincerely,
> Yeoreum Yun

--
Sincerely yours,
Mike.