Re: [PATCH v4 2/3] mm: swap: drop dropbehind swap cache folios on writeback completion
From: Nhat Pham
Date: Tue Sep 08 2026 - 14:56:22 EST
On Tue, Aug 25, 2026 at 6:54 AM Alexandre Ghiti <alex@xxxxxxxx> wrote:
>
> A PG_dropbehind folio is dropped from its cache once writeback completes
> rather than left for reclaim to find later; this is implemented for file
> folios in folio_end_dropbehind(). Extend it to swap cache folios.
>
> The drop takes the folio and swap cluster locks and may sleep, so it
> cannot run in interrupt context. Set BIO_COMPLETE_IN_TASK on the write,
> as the file dropbehind paths do, and drop the folio directly from
> folio_end_writeback().
This BIO_COMPLETE_IN_TASK thing is really nice! I'm glad we have a
proper infra now and no longer have to roll our own solutions :)
>
> Suggested-by: Yosry Ahmed <yosry@xxxxxxxxxx>
> Suggested-by: Johannes Weiner <hannes@xxxxxxxxxxx>
> Suggested-by: Nhat Pham <nphamcs@xxxxxxxxx>
> Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
Mostly LGTM FWIW. Just one query below:
[...]
> + * Gate remove_mapping_reclaim() on folio_test_swapcache(): a racing
> + * swapin may have freed the swap slot (folio_free_swap()) and dropped the
> + * folio from the cache, and it must not run on a non-swapcache folio (it
> + * would trip __remove_mapping()'s mapping == folio_mapping() check).
> + */
> + if (!folio_test_swapcache(folio) || folio_test_writeback(folio) ||
> + !remove_mapping_reclaim(swap_address_space(folio->swap), folio, memcg)) {
remove_mapping_reclaim() and the likes seem a bit confusing to me, but
I don't have a good suggestions for the naming...
(also I'm hoping we're fixing the weird shadows behavior of zswap
writeback soon :))
Anyway:
Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>