mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: let memory-failure remove poisoned page-cache folios
@ 2026-12-01 17:15 Kurt Lin
  0 siblings, 0 replies; only message in thread
From: Kurt Lin @ 2026-12-01 17:15 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu
  Cc: Andrew Morton, Miaohe Lin, Naoya Horiguchi, linux-mm,
	linux-f2fs-devel, linux-kernel, Kurt Lin

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@gmail.com>
---
Tested on f2fs dev b61a029304bb in a QEMU x86_64 guest (4K blocks) with
MADV_HWPOISON on a dirty mmap'd page. The two kernels differ only by
this patch:

                               before            after
  recovery action (20 runs)    Failed 20/20      Recovered 20/20
  madvise()                    -EBUSY            0
  that page on disk after      poisoned page     not written
    fsync() (O_DIRECT read)
  fsync()                      -EIO              -EIO
  atomic write commit          -EIO, rolled back -EIO, rolled back

With the patch it is also Recovered in a compress_algorithm=lz4
directory (chattr +c), and in a 4-page file the other three pages read
back intact. fsck.f2fs shows nothing new. The mm memory-failure
selftest passes with and without the patch, as it does not check the
recovery result.

Not tested: block size smaller than PAGE_SIZE, large folios, a real
memory error.

This is the f2fs counterpart of Andrew's FUSE patch:
https://lore.kernel.org/all/82801b542ac4481a85ec2c869294ca28.1@linux-foundation.org/
---
 fs/f2fs/data.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index cdc9e6e8633c..6df85fb7d5af 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -6403,6 +6403,7 @@ const struct address_space_operations f2fs_dblock_aops = {
 	.migrate_folio	= filemap_migrate_folio,
 	.invalidate_folio = f2fs_invalidate_folio,
 	.release_folio	= f2fs_release_folio,
+	.error_remove_folio = generic_error_remove_folio,
 	.is_partially_uptodate = f2fs_is_partially_uptodate,
 	.bmap		= f2fs_bmap,
 	.swap_activate  = f2fs_swap_activate,

---
base-commit: b61a029304bb5531312ebc133b2a895d14dc3fee
change-id: 20261201-f2fs-error-remove-folio-37c5167981bf

Best regards,
-- 
Kurt Lin <lylin1023@gmail.com>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-01 17:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 17:15 [PATCH] f2fs: let memory-failure remove poisoned page-cache folios Kurt Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®