Re: [PATCH v5 1/3] mm: swap: move LRU insertion out of the swap cache allocator
From: Barry Song
Date: Fri Sep 18 2026 - 05:56:32 EST
On Fri, Sep 11, 2026 at 8:15 PM Alexandre Ghiti <alex@xxxxxxxx> wrote:
>
> This is a preparatory patch.
>
> __swap_cache_alloc_folio() adds the new folio to the LRU itself, which
> leaves its callers no way to act on the folio before it becomes visible
> to reclaim. Two users need exactly that:
>
> - moving the refault evaluation out of the swap cache folio allocation
> requires it to happen before folio_add_lru(): that consumes PG_active
> to file the folio on the inactive or the active list, and under MGLRU
> it also reads PG_workingset to pick the generation. Setting either
> flag afterwards does not move the folio;
>
> - zswap writeback dropbehind needs the buffer folio to stay off the LRU
> entirely, as the per-CPU LRU batch would hold a reference on it and
> keep remove_mapping() from freeing it once writeback completes.
>
> Defer the LRU insertion to the callers of __swap_cache_alloc_folio():
> each of them adds the folio right after the allocation, so there is no
> functional change intended.
>
> Suggested-by: Kairui Song <kasong@xxxxxxxxxxx>
> Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>
> Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
> Acked-by: Usama Arif <usama.arif@xxxxxxxxx>
> Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
> ---
LGTM,
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>