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

Nhat Pham <[email protected]>
Newsgroups org.kernel.vger.cgroups,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <CAKEwX=PjvsAOv8rvp+mz_aPqDLm6iRy6URRW2EMFvFrgD2HEgA@mail.gmail.com>
On Tue, Aug 18, 2026 at 11:41 AM Nhat Pham <[email protected]> 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?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.