Re: [PATCH mm-new 2/2] mm/shmem: writeout free swap if swap_writeout() reactivates
From: David Rientjes
Date: Sun Jul 20 2025 - 03:07:56 EST
On Wed, 16 Jul 2025, Hugh Dickins wrote:
> If swap_writeout() returns AOP_WRITEPAGE_ACTIVATE (for example, because
> zswap cannot compress and memcg disables writeback), there is no virtue
> in keeping that folio in swap cache and holding the swap allocation:
> shmem_writeout() switch it back to shmem page cache before returning.
>
> Folio lock is held, and folio->memcg_data remains set throughout, so
> there is no need to get into any memcg or memsw charge complications:
> swap_free_nr() and delete_from_swap_cache() do as much as is needed (but
> beware the race with shmem_free_swap() when inode truncated or evicted).
>
> Doing the same for an anonymous folio is harder, since it will usually
> have been unmapped, with references to the swap left in the page tables.
> Adding a function to remap the folio would be fun, but not worthwhile
> unless it has other uses, or an urgent bug with anon is demonstrated.
>
> Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx>
Tested-by: David Rientjes <rientjes@xxxxxxxxxx>