Re: [PATCH] mm/shmem: don't drop a folio whose swap write failed
From: David Hildenbrand (Arm)
Date: Mon Nov 23 2026 - 14:39:22 EST
On 11/23/26 18:21, Mani Tofigh via B4 Relay wrote:
> From: Mani Tofigh <mt4022@xxxxxxxxxxxx>
>
> shmem_swapin_folio() drops a large folio that does not fit the mapping
> from the swap cache if the folio is neither dirty nor under writeback.
> The folio can belong to another file and be under swap writeback, when
> the swap entry was freed and reused before the swap cache lookup.
>
> Swap write completion does not take the folio lock. On a failed write,
> swap_write_end() marks the folio dirty and then ends writeback. Since
> dirty is tested first, the folio can look clean and written:
>
> CPU0 (swapin of file Y) CPU1 (swapout of file X)
> ----------------------- ------------------------
> shmem_swapin_folio()
> folio_test_dirty() == false
> swap_write_end(), failed write
> folio_mark_dirty()
> folio_end_writeback()
> folio_test_writeback() == false
> swap_cache_del_folio()
> /* X's data is lost */
>
> The next swapin of X reads the slot whose write failed.
>
> Test writeback first. Both flags are in folio->flags. If the
> writeback test sees the write ended, the dirty test then sees the dirty
> bit set before it.
>
> With the fix, a folio whose swap write failed stays in the swap cache.
>
> Fixes: fc2c19648d68 ("mm/shmem: fix swapin livelock on a mismatched large swap cache folio")
> Suggested-by: Chris Mason <mason@xxxxxxxxxx>
Nest to make that a Reported-by:
I'll wait a bit before I pick that up. But it will be a v7.4 hotfix.
--
Cheers,
David