Re: [PATCH 1/2] mm: zswap: free synchronous-IO writeback folios directly
From: Johannes Weiner
Date: Tue Jul 21 2026 - 07:33:47 EST
On Mon, Jul 20, 2026 at 08:56:32AM -0700, Nhat Pham wrote:
> > @@ -972,6 +972,30 @@ static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio)
> > /*********************************
> > * writeback code
> > **********************************/
> > +static void zswap_writeback_free_folio(struct folio *folio)
> > +{
> > + folio_lock(folio);
> > +
> > + /* The folio was allocated off the LRU and nothing re-adds it here. */
> > + VM_WARN_ON_ONCE_FOLIO(folio_test_lru(folio), folio);
> > +
> > + /*
> > + * Gate remove_mapping() on folio_test_swapcache(): a racing swapin may
> > + * have freed the swap slot (folio_free_swap()) and dropped the folio from
> > + * the cache, and remove_mapping() must not run on a non-swapcache folio
> > + * (it would trip __remove_mapping()'s mapping == folio_mapping() check).
> > + */
> > + if (folio_test_swapcache(folio) &&
> > + remove_mapping(swap_address_space(folio->swap), folio))
>
> Hmm I think you also have to test for writeback and dirty here right?
>
> After a racing swapin freed the swap slot, the folio might be dirtied
> and swapped out again. We probably shouldn't try to remove_mapping()
> such a folio?
remove_mapping() itself handles dirty state. It fails in that case.