From: Kurt Lin <lylin1023@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
linux-mm@kvack.org, linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Kurt Lin <lylin1023@gmail.com>
Subject: [PATCH] f2fs: let memory-failure remove poisoned page-cache folios
Date: Wed, 02 Dec 2026 01:15:45 +0800 [thread overview]
Message-ID: <20261202-f2fs-error-remove-folio-v1-1-645aef601439@gmail.com> (raw)
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>
reply other threads:[~2026-12-01 17:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202-f2fs-error-remove-folio-v1-1-645aef601439@gmail.com \
--to=lylin1023@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linmiaohe@huawei.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nao.horiguchi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®