Re: [PATCH v3 05/12] mm, swap: unify large folio allocation

From: Kairui Song

Date: Mon May 11 2026 - 10:40:57 EST


On Mon, May 11, 2026 at 8:58 PM David Hildenbrand (Arm)
<david@xxxxxxxxxx> wrote:
>
> On 4/21/26 08:16, Kairui Song via B4 Relay wrote:
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > Now that direct large order allocation is supported in the swap cache,
> > both anon and shmem can use it instead of implementing their own methods.
> > This unifies the fallback and swap cache check, which also reduces the
> > TOCTOU race window of swap cache state: previously, high order swapin
> > required checking swap cache states first, then allocating and falling
> > back separately. Now all these steps happen in the same compact loop.
> >
> > Order fallback and statistics are also unified, callers just need to
> > check and pass the acceptable order bitmask.
> >
> > There is basically no behavior change. This only makes things more
> > unified and prepares for later commits. Cgroup and zero map checks can
> > also be moved into the compact loop, further reducing race windows and
> > redundancy
> >
>
> You should spell out the rename from swapin_folio() to swapin_entry() [and why
> it is done].
>
> swapin_readahead() vs. swapin_entry() looks a bit odd, fiven that both consume
> an entry.

Yes, the current status is a bit odd, about two years ago I also
wanted to name it `swapin_direct()`.
https://lore.kernel.org/linux-mm/20240326185032.72159-3-ryncsn@xxxxxxxxx/

But actually ZRAM or shmem would also benefit from supporting unified
readahead like this:
https://lore.kernel.org/linux-mm/20240102175338.62012-6-ryncsn@xxxxxxxxx/

So calling it `swapin_entry` seems more future-proof. At some point in
the future we might remove `swapin_readahead`. All swapin operations
could have a unified or at least a per-device readahead policy like
the one in the link above, instead of the current policy where the
caller must decide whether to perform readahead.

But any suggestion on naming is welcome :)

> > #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> > /*
> > * Check if the PTEs within a range are contiguous swap entries
> > @@ -4642,8 +4622,6 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)
> > */
> > if (unlikely(swap_zeromap_batch(entry, nr_pages, NULL) != nr_pages))
> > return false;
> > - if (unlikely(non_swapcache_batch(entry, nr_pages) != nr_pages))
> > - return false;
> >
>
> This should also be pointed out in the patch description. (and why it is ok)

Right, the check is now resolved by the swap cache layer, so the
caller no longer needs to check it. I'll describe that in the commit
message.

Thanks!