Re: [PATCH v3 04/12] mm, swap: add support for stable large allocation in swap cache directly
From: Kairui Song
Date: Tue May 12 2026 - 06:00:08 EST
On Tue, May 12, 2026 at 5:49 PM Baolin Wang
<baolin.wang@xxxxxxxxxxxxxxxxx> wrote:
>
>
>
> On 4/21/26 2:16 PM, Kairui Song via B4 Relay wrote:
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > +/**
> > + * swap_cache_alloc_folio - Allocate folio for swapped out slot in swap cache.
> > + * @targ_entry: swap entry indicating the target slot
> > + * @gfp: memory allocation flags
> > + * @orders: allocation orders
> > + * @vmf: fault information
> > + * @mpol: NUMA memory allocation policy to be applied
> > + * @ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE
> > + *
> > + * Allocate a folio in the swap cache for one swap slot, typically before
> > + * doing IO (e.g. swap in or zswap writeback). The swap slot indicated by
> > + * @targ_entry must have a non-zero swap count (swapped out).
> > + *
> > + * Context: Caller must protect the swap device with reference count or locks.
> > + * Return: Returns the folio if allocation succeeded and folio is added to
> > + * swap cache. Returns error code if allocation failed due to race.
> > + */
> > +struct folio *swap_cache_alloc_folio(swp_entry_t targ_entry, gfp_t gfp,
> > + unsigned long orders, struct vm_fault *vmf,
> > + struct mempolicy *mpol, pgoff_t ilx)
> > +{
> > + int order, err;
> > + struct folio *ret;
> > + struct swap_cluster_info *ci;
> > +
> > + /* Always allow order 0 so swap won't fail under pressure. */
> > + order = orders ? highest_order(orders |= BIT(0)) : 0;
>
> This seems a bit odd here. In THP/mTHP operations, it's usually the
> callers' responsibility to determine the allowable orders. So I think we
> should not implicitly set order 0 here. Instead, we should let callers
> explicitly set it. What do you think?
Totally agree. I hesitated between these two designs.
And Usama also needed this because some callers (PMD swapin) don't
want the fallback.
I'll let the caller explicitly pass in the allowable order in v4.
Thanks for the review!