Re: [PATCH v3 01/11] mm, swap: add virtual swap device infrastructure

From: Nhat Pham

Date: Wed Aug 19 2026 - 12:54:19 EST


On Tue, Aug 18, 2026 at 11:41 AM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
>
> >
> > Can you make this a pure allocation function - vswap_alloc_cluster()
> > or something - that links it to &si->free_clusters, then jump back and
> > use the existing alloc_swap_scan_list() sites?
>
> That name was vestigial from Kairui's RFC, but yeah I agree
> vswap_alloc_cluster sounds better.
>
> Regarding the linkage of the newly allocated cluster to the free list
> - I'm a bit hesitant to introduce new surface for these clusters,
> mostly because I'm afraid I might mess up the handling of these
> clusters (when I unlink them from the free list), but I can give it a
> shot.
>
> >
> > There is a new_cluster: label upstream you could use for the retry.

Actually, I stared at it a bit more. I don't think we should jump to
new_cluster here - it's not what physical swap allocator does in the
first place (we never do any backward jump to retry).

So basically, this is the old code:

new_cluster:
if (discard)
alloc_swap_scan_list(free list); /* not taken by vswap */

if (alloc_swap_scan_list(nonfull)) return;

/*
* Added by me. vswap (almost) always succeeds here
*/
if (alloc_swap_scan_dynamic()) return;

/*
* not taken by vswap, because we succeeds above
* and free list is always empty.
*/
if (not discard)
alloc_swap_scan_list(free list);

/* if free list scan fail, keep going */

etc. etc.

The new code becomes:

new_cluster:
if (discard)
alloc_swap_scan_list(free list) /* still not taken by vswap */

if (alloc_swap_scan_list(nonfull)) return;

/* vswap puts new cluster into free list, then falls through */
if (si is vswap)
vswap_cluster_alloc();

/* vswap now scans free list to get the cluster it just allocated */
if (not discard)
alloc_swap_scan_list(free list)

/* if free list scan fail, keep going */

This works, but I'm not sure if putting the new cluster on free list
buy us much other than more lock contention points (we need si->lock
to scan free list) :/

I'll just rename alloc_swap_scan_dynamic to vswap_cluster_alloc(), for now?