Re: [PATCH v2 5/8] mm/internal: rename swap offset helpers to softleaf offset
From: Barry Song
Date: Sat Sep 05 2026 - 06:52:23 EST
On Sat, Sep 5, 2026 at 6:42 PM Barry Song <baohua@xxxxxxxxxx> wrote:
>
> On Tue, Sep 1, 2026 at 1:44 PM Dev Jain <dev.jain@xxxxxxx> wrote:
> >
> > In preparation for adding a helper to set softleaf ptes in one go,
> > generalize the swap entry helpers shifting the swap offset by delta,
> > for softleaves.
> >
> > Note that the soft-dirty bit, exclusive bit and uffd bit preservation
> > will still work for non-swap softleaves, since a softleaf entry is
> > constructed out of a type and offset, and those bits are ahead of
> > the soft-dirty, exclusive and uffd bits.
> >
> > For example, for a migration entry, pte_swp_exclusive() will return
> > false, as the exclusivity is encoded in the type itself
> > (SOFTLEAF_MIGRATION_READ_EXCLUSIVE).
>
> I don't quite understand why you mention this. Is anyone calling
> `pte_swp_exclusive()` on a migration entry? Shouldn't it only be called
> when `softleaf_is_swap()` is true?
Is it the rename from `pte_move_swp_offset()` to
`pte_move_softleaf_offset()` here that is causing this semantic confusion?
static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
{
const softleaf_t entry = softleaf_from_pte(pte);
pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry),
(swp_offset(entry)
+ delta)));
if (pte_swp_soft_dirty(pte))
new = pte_swp_mksoft_dirty(new);
if (pte_swp_exclusive(pte))
new = pte_swp_mkexclusive(new);
if (pte_swp_uffd(pte))
new = pte_swp_mkuffd(new);
return new;
}
If so, I wonder if it would be better not to rely on the implicit
assumption that the softleaf type and offset fields are laid out before
the soft-dirty, exclusive, and uffd bits. Could we make this explicit
in the code?