[PATCH] mm: hwpoison: deal with page cache THP
From: Yang Shi
Date: Tue Aug 24 2021 - 18:13:28 EST
Currently hwpoison doesn't handle page cache THP, just give up and return
error. It is just because the hwpoison THP support was added before
page cache THP was supported.
Handling page cache THP is simple, they could be offlined by splitting THP,
just like anonymous THP.
The question is how to distinguish them with allocating and freeing THP
which can't be handled by hwpoison properly. It seems page->mapping is a
good indicator, both anonymous page and file page have it populated, but
it won't be populated until the page is added to rmap or page cache, in
other word, instantiated. If page->mapping is populated it is
definitely not in allocating or freeing.
The later get_page_unless_zero() could serialize against page free
paths.
Cc: Naoya Horiguchi <naoya.horiguchi@xxxxxxx>
Cc: Oscar Salvador <osalvador@xxxxxxx>
Cc: Hugh Dickins <hughd@xxxxxxxxxx>
Cc: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
Signed-off-by: Yang Shi <shy828301@xxxxxxxxx>
---
mm/memory-failure.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 60df8fcd0444..caa0b0c1f5b8 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1149,13 +1149,16 @@ static int __get_hwpoison_page(struct page *page)
if (PageTransHuge(head)) {
/*
- * Non anonymous thp exists only in allocation/free time. We
- * can't handle such a case correctly, so let's give it up.
- * This should be better than triggering BUG_ON when kernel
- * tries to touch the "partially handled" page.
+ * We can't handle allocating or freeing THPs, so let's give
+ * it up. This should be better than triggering BUG_ON when
+ * kernel tries to touch the "partially handled" page.
+ *
+ * page->mapping won't be initialized until the page is added
+ * to rmap or page cache. Use this as an indicator for if
+ * this is an instantiated page.
*/
- if (!PageAnon(head)) {
- pr_err("Memory failure: %#lx: non anonymous thp\n",
+ if (!head->mapping) {
+ pr_err("Memory failure: %#lx: non instantiated thp\n",
page_to_pfn(page));
return 0;
}
@@ -1414,12 +1417,12 @@ static int identify_page_state(unsigned long pfn, struct page *p,
static int try_to_split_thp_page(struct page *page, const char *msg)
{
lock_page(page);
- if (!PageAnon(page) || unlikely(split_huge_page(page))) {
+ if (!page->mapping || unlikely(split_huge_page(page))) {
unsigned long pfn = page_to_pfn(page);
unlock_page(page);
- if (!PageAnon(page))
- pr_info("%s: %#lx: non anonymous thp\n", msg, pfn);
+ if (!page->mapping)
+ pr_info("%s: %#lx: not instantiated thp\n", msg, pfn);
else
pr_info("%s: %#lx: thp split failed\n", msg, pfn);
put_page(page);
--
2.26.2