提交 0ebff32c 编写于 作者: X Xishi Qiu 提交者: Linus Torvalds

memory-failure: fix an error of mce_bad_pages statistics

When doing

    $ echo paddr > /sys/devices/system/memory/soft_offline_page

to offline a *free* page, the value of mce_bad_pages will be added, and
the page is set HWPoison flag, but it is still managed by page buddy
alocator.

   $ cat /proc/meminfo | grep HardwareCorrupted

shows the value.

If we offline the same page, the value of mce_bad_pages will be added
*again*, this means the value is incorrect now.  Assume the page is
still free during this short time.

  soft_offline_page()
    get_any_page()
      "else if (is_free_buddy_page(p))" branch return 0
        "goto done";
           "atomic_long_add(1, &mce_bad_pages);"

This patch:

Move poisoned page check at the beginning of the function in order to
fix the error.
Signed-off-by: NXishi Qiu <qiuxishi@huawei.com>
Signed-off-by: NJiang Liu <jiang.liu@huawei.com>
Tested-by: NNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 194159fb
...@@ -1419,18 +1419,17 @@ static int soft_offline_huge_page(struct page *page, int flags) ...@@ -1419,18 +1419,17 @@ static int soft_offline_huge_page(struct page *page, int flags)
unsigned long pfn = page_to_pfn(page); unsigned long pfn = page_to_pfn(page);
struct page *hpage = compound_head(page); struct page *hpage = compound_head(page);
if (PageHWPoison(hpage)) {
pr_info("soft offline: %#lx hugepage already poisoned\n", pfn);
return -EBUSY;
}
ret = get_any_page(page, pfn, flags); ret = get_any_page(page, pfn, flags);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) if (ret == 0)
goto done; goto done;
if (PageHWPoison(hpage)) {
put_page(hpage);
pr_info("soft offline: %#lx hugepage already poisoned\n", pfn);
return -EBUSY;
}
/* Keep page count to indicate a given hugepage is isolated. */ /* Keep page count to indicate a given hugepage is isolated. */
ret = migrate_huge_page(hpage, new_page, MPOL_MF_MOVE_ALL, false, ret = migrate_huge_page(hpage, new_page, MPOL_MF_MOVE_ALL, false,
MIGRATE_SYNC); MIGRATE_SYNC);
...@@ -1441,12 +1440,11 @@ static int soft_offline_huge_page(struct page *page, int flags) ...@@ -1441,12 +1440,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
return ret; return ret;
} }
done: done:
if (!PageHWPoison(hpage)) /* keep elevated page count for bad page */
atomic_long_add(1 << compound_trans_order(hpage), atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
&mce_bad_pages);
set_page_hwpoison_huge_page(hpage); set_page_hwpoison_huge_page(hpage);
dequeue_hwpoisoned_huge_page(hpage); dequeue_hwpoisoned_huge_page(hpage);
/* keep elevated page count for bad page */
return ret; return ret;
} }
...@@ -1488,6 +1486,11 @@ int soft_offline_page(struct page *page, int flags) ...@@ -1488,6 +1486,11 @@ int soft_offline_page(struct page *page, int flags)
} }
} }
if (PageHWPoison(page)) {
pr_info("soft offline: %#lx page already poisoned\n", pfn);
return -EBUSY;
}
ret = get_any_page(page, pfn, flags); ret = get_any_page(page, pfn, flags);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1519,19 +1522,11 @@ int soft_offline_page(struct page *page, int flags) ...@@ -1519,19 +1522,11 @@ int soft_offline_page(struct page *page, int flags)
return -EIO; return -EIO;
} }
lock_page(page);
wait_on_page_writeback(page);
/* /*
* Synchronized using the page lock with memory_failure() * Synchronized using the page lock with memory_failure()
*/ */
if (PageHWPoison(page)) { lock_page(page);
unlock_page(page); wait_on_page_writeback(page);
put_page(page);
pr_info("soft offline: %#lx page already poisoned\n", pfn);
return -EBUSY;
}
/* /*
* Try to invalidate first. This should work for * Try to invalidate first. This should work for
* non dirty unmapped page cache pages. * non dirty unmapped page cache pages.
...@@ -1583,8 +1578,9 @@ int soft_offline_page(struct page *page, int flags) ...@@ -1583,8 +1578,9 @@ int soft_offline_page(struct page *page, int flags)
return ret; return ret;
done: done:
/* keep elevated page count for bad page */
atomic_long_add(1, &mce_bad_pages); atomic_long_add(1, &mce_bad_pages);
SetPageHWPoison(page); SetPageHWPoison(page);
/* keep elevated page count for bad page */
return ret; return ret;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册