Re: [PATCH v2 05/15] mm, swap: always lock and check the swap cache folio before use
From: Kairui Song
Date: Tue Sep 09 2025 - 10:58:53 EST
On Mon, Sep 8, 2025 at 10:08 PM David Hildenbrand <david@xxxxxxxxxx> wrote:
>
>
> >
> > folio_lock(folio);
> > + if (!folio_matches_swap_entry(folio, entry)) {
> > + folio_unlock(folio);
> > + folio_put(folio);
> > + continue;
> > + }
> > +
>
> I wonder if we should put that into unuse_pte() instead. It checks for
> other types of races (like the page table entry getting modified) already.
Doing this earlier here might help to avoid the folio_wait_writeback
below? And checking the folio right after locking seems to follow the
convention more strictly.
I'm fine either way though as there should be almost no difference.
> --
> Cheers
>
> David / dhildenb
>
>