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

Yeoreum Yun yeoreum.yun at arm.com
Tue Nov 24 10:52:00 PST 2026


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.

>  
> > For consistency and cleanup, reverse the enum value ordering.
> > 
> > Since there is no current user relies on these numbers to be ascending from
> > PTE->PGD, so it can be changed to be ascending from PGD->PTE, in the
> > direction of the page table walk.
> > 
> > Reviewed-by: David Hildenbrand (Arm) <david at kernel.org>
> > Signed-off-by: Yeoreum Yun <yeoreum.yun at arm.com>
> > ---
> >  include/linux/pgtable.h | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> > index 780fe849ff8b7..a032f95943357 100644
> > --- a/include/linux/pgtable.h
> > +++ b/include/linux/pgtable.h
> > @@ -2288,11 +2288,11 @@ static inline bool arch_has_pfn_modify_check(void)
> >  typedef unsigned int pgtbl_mod_mask;
> >  
> >  enum pgtable_level {
> > -	PGTABLE_LEVEL_PTE = 0,
> > -	PGTABLE_LEVEL_PMD,
> > -	PGTABLE_LEVEL_PUD,
> > +	PGTABLE_LEVEL_PGD = 0,
> >  	PGTABLE_LEVEL_P4D,
> > -	PGTABLE_LEVEL_PGD,
> > +	PGTABLE_LEVEL_PUD,
> > +	PGTABLE_LEVEL_PMD,
> > +	PGTABLE_LEVEL_PTE,
> >  };
> >  
> >  static inline const char *pgtable_level_to_str(enum pgtable_level level)
> > 
> > -- 
> > 2.43.0
> > 
> 
> -- 
> Sincerely yours,
> Mike.

-- 
Sincerely,
Yeoreum Yun



More information about the linux-riscv mailing list