Re: [PATCH v2 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
From: Lorenzo Stoakes
Date: Mon Nov 10 2025 - 14:18:00 EST
On Sun, Nov 09, 2025 at 08:34:09PM +0800, Lance Yang wrote:
>
>
> On 2025/11/9 01:08, Lorenzo Stoakes wrote:
> > The kernel maintains leaf page table entries which contain either:
> >
> > - Nothing ('none' entries)
> > - Present entries (that is stuff the hardware can navigate without fault)
> > - Everything else that will cause a fault which the kernel handles
> >
> > In the 'everything else' group we include swap entries, but we also include
> > a number of other things such as migration entries, device private entries
> > and marker entries.
> >
> > Unfortunately this 'everything else' group expresses everything through
> > a swp_entry_t type, and these entries are referred to swap entries even
> > though they may well not contain a... swap entry.
> >
> > This is compounded by the rather mind-boggling concept of a non-swap swap
> > entry (checked via non_swap_entry()) and the means by which we twist and
> > turn to satisfy this.
> >
> > This patch lays the foundation for reducing this confusion.
> >
> > We refer to 'everything else' as a 'software-define leaf entry' or
> > 'softleaf'. for short And in fact we scoop up the 'none' entries into this
> > concept also so we are left with:
> >
> > - Present entries.
> > - Softleaf entries (which may be empty).
> >
> > This allows for radical simplification across the board - one can simply
> > convert any leaf page table entry to a leaf entry via softleaf_from_pte().
> >
> > If the entry is present, we return an empty leaf entry, so it is assumed
> > the caller is aware that they must differentiate between the two categories
> > of page table entries, checking for the former via pte_present().
> >
> > As a result, we can eliminate a number of places where we would otherwise
> > need to use predicates to see if we can proceed with leaf page table entry
> > conversion and instead just go ahead and do it unconditionally.
> >
> > We do so where we can, adjusting surrounding logic as necessary to
> > integrate the new softleaf_t logic as far as seems reasonable at this
> > stage.
> >
> > We typedef swp_entry_t to softleaf_t for the time being until the
> > conversion can be complete, meaning everything remains compatible
> > regardless of which type is used. We will eventually remove swp_entry_t
> > when the conversion is complete.
>
> Cool! The softleaf abstraction is way easier and clearer for me to follow ;)
>
> Just a couple of nits below.
Thanks!
Hm I only saw one :P
> > --- /dev/null
> > +++ b/include/linux/leafops.h
> > @@ -0,0 +1,382 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Describes operations that can be performed on software-defined page table
> > + * leaf entries. These are abstracted from the hardware page table entries
> > + * themselves by the softleaf_t type, see mm_types.h.
> > + */
> > +#ifndef _LINUX_LEAFOPS_H
> > +#define _LINUX_LEAFOPS_H
[snip]
> > +#endif /* CONFIG_MMU */
> > +#endif /* _LINUX_SWAPOPS_H */
>
> Small copy-paste error? Should be _LINUX_LEAFOPS_H.
>
> Thanks,
> Lance
Oops, copy/pasta error here :) will fix.