Re: [PATCH] f2fs: let memory-failure remove poisoned page-cache folios

From: Miaohe Lin

Date: Thu Dec 03 2026 - 01:39:32 EST


On 2026/12/2 1:15, Kurt Lin wrote:
> f2fs_dblock_aops has no ->error_remove_folio(). memory_failure() then
> falls back to mapping_evict_folio(), which cannot remove a dirty folio.
> So when a dirty f2fs page-cache page is hard-poisoned, recovery fails:
>
> Memory failure: 0x6289: Failed to invalidate
> Memory failure: 0x6289: recovery action for dirty LRU page: Failed
>
> madvise(MADV_HWPOISON) returns -EBUSY and the poisoned folio stays in
> the page cache. read() keeps returning its contents without an error,
> and the next fsync() writes it back to disk before reporting -EIO. With
> a real memory error, the kernel keeps reading the poisoned memory.
>
> Set ->error_remove_folio() to generic_error_remove_folio(), as ext4,
> xfs, btrfs and others do. The folio is then truncated at the time of
> the error, and f2fs_invalidate_folio() drops its dirty accounting:
>
> Memory failure: 0x742b: recovery action for dirty LRU page: Recovered
>
> madvise() returns 0 and nothing is written back. fsync() still reports
> -EIO, and an atomic write with a poisoned page still fails to commit
> with -EIO and is rolled back.
>
> Found and tested with the help of an AI coding assistant.
>
> Signed-off-by: Kurt Lin <lylin1023@xxxxxxxxx>

Reviewed-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>

Thanks.
.