Re: [PATCH 1/2] mm: zswap: free synchronous-IO writeback folios directly
From: Barry Song
Date: Tue Jul 21 2026 - 22:41:08 EST
On Sat, Jul 18, 2026 at 5:38 PM Alexandre Ghiti <alex@xxxxxxxx> wrote:
>
> When zswap writes an entry back, it allocates a swap cache folio,
> decompresses the entry into it and writes it out. That folio is cold by
> construction, but it is currently left on the LRU for page reclaim to find
> and free later. This wastes a reclaim scan and keeps cold memory resident
> longer than necessary.
With MGLRU, we already have code like the one below that reclaims
folios directly without requiring another reclaim scan, whereas the
active/inactive LRU path doesn't have an equivalent mechanism.
/* retry folios that may have missed
folio_rotate_reclaimable() */
if (!skip_retry && !folio_test_active(folio) &&
!folio_mapped(folio) &&
!folio_test_dirty(folio) && !folio_test_writeback(folio)) {
list_move(&folio->lru, &clean);
continue;
}
>
> For synchronous-IO swap devices writeback completes in the calling context,
> so the folio can be freed right after the write rather than left behind; do
> that. Because it is freed directly rather than through reclaim, it is
> allocated off the LRU: dropping the last reference on a folio still on the
> LRU would trip the free-time page-flag checks. A folio that a concurrent
> swapin has meanwhile claimed is left in place and reclaimed as usual.
>
> Asynchronous and filesystem-backed swap complete writeback in interrupt
> context, where the folio cannot be freed; they are handled in a later
> change.
Might be a bit off-topic, but I've been thinking about this problem
for a while.
MADV_PAGEOUT, and reclaim in general, don't actually free memory
when using asynchronous swap devices. Do you think it would make
sense to free the folio directly, at least for anonymous folios,
once it has been written out, instead of waiting for another reclaim
scan?
It seems a bit odd that after MADV_PAGEOUT completes, the memory is
still occupied.
>
> Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
Best Regards
Barry