Re: [PATCH 6/9] mm/swapfile: Make folio_dup_swap batchable

From: Kairui Song

Date: Tue Mar 10 2026 - 04:28:12 EST


On Tue, Mar 10, 2026 at 3:36 PM Dev Jain <dev.jain@xxxxxxx> wrote:
>
> Teach folio_dup_swap to handle a batch of consecutive pages. Note that
> folio_dup_swap already can handle a subset of this: nr_pages == 1 and
> nr_pages == folio_nr_pages(folio). Generalize this to any nr_pages.

Thanks a lot for doing this. I was thinking it's about time we respin
the batch unmapping of anon folios idea. Barry tried that before with
an RFC, and now batching from swap side is easier, so some parts can
be done cleaner.

> Currently we have a not-so-nice logic of passing in subpage == NULL if
> we mean to exercise the logic on the entire folio, and subpage != NULL if
> we want to exercise the logic on only that subpage. Remove this
> indirection, and explicitly pass subpage != NULL, and the number of
> pages required.

I was hoping most callers will just use the whole folio, but after
checking your code, yeah, using explicit subpage and nr does fit the
other parts better.

> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 915bc93964dbd..eaf61ae6c3817 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1738,7 +1738,8 @@ int folio_alloc_swap(struct folio *folio)
> /**
> * folio_dup_swap() - Increase swap count of swap entries of a folio.
> * @folio: folio with swap entries bounded.
> - * @subpage: if not NULL, only increase the swap count of this subpage.
> + * @subpage: Increase the swap count of this subpage till nr number of
> + * pages forward.

The new nr_pages parameter isn't documented in the kernel-doc comment?