Commit 8e30456b authored by Naoya Horiguchi's avatar Naoya Horiguchi Committed by Linus Torvalds

mm/hwpoison: introduce num_poisoned_pages wrappers

num_poisoned_pages counter will be changed outside mm/memory-failure.c
by a subsequent patch, so this patch prepares wrappers to manipulate it.
Signed-off-by: default avatarNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Tested-by: default avatarWanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 665d9da7
...@@ -164,6 +164,9 @@ static inline int is_write_migration_entry(swp_entry_t entry) ...@@ -164,6 +164,9 @@ static inline int is_write_migration_entry(swp_entry_t entry)
#endif #endif
#ifdef CONFIG_MEMORY_FAILURE #ifdef CONFIG_MEMORY_FAILURE
extern atomic_long_t num_poisoned_pages __read_mostly;
/* /*
* Support for hardware poisoned pages * Support for hardware poisoned pages
*/ */
...@@ -177,6 +180,26 @@ static inline int is_hwpoison_entry(swp_entry_t entry) ...@@ -177,6 +180,26 @@ static inline int is_hwpoison_entry(swp_entry_t entry)
{ {
return swp_type(entry) == SWP_HWPOISON; return swp_type(entry) == SWP_HWPOISON;
} }
static inline void num_poisoned_pages_inc(void)
{
atomic_long_inc(&num_poisoned_pages);
}
static inline void num_poisoned_pages_dec(void)
{
atomic_long_dec(&num_poisoned_pages);
}
static inline void num_poisoned_pages_add(long num)
{
atomic_long_add(num, &num_poisoned_pages);
}
static inline void num_poisoned_pages_sub(long num)
{
atomic_long_sub(num, &num_poisoned_pages);
}
#else #else
static inline swp_entry_t make_hwpoison_entry(struct page *page) static inline swp_entry_t make_hwpoison_entry(struct page *page)
......
...@@ -1121,7 +1121,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags) ...@@ -1121,7 +1121,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
nr_pages = 1 << compound_order(hpage); nr_pages = 1 << compound_order(hpage);
else /* normal page or thp */ else /* normal page or thp */
nr_pages = 1; nr_pages = 1;
atomic_long_add(nr_pages, &num_poisoned_pages); num_poisoned_pages_add(nr_pages);
/* /*
* We need/can do nothing about count=0 pages. * We need/can do nothing about count=0 pages.
...@@ -1149,7 +1149,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags) ...@@ -1149,7 +1149,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
if (PageHWPoison(hpage)) { if (PageHWPoison(hpage)) {
if ((hwpoison_filter(p) && TestClearPageHWPoison(p)) if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
|| (p != hpage && TestSetPageHWPoison(hpage))) { || (p != hpage && TestSetPageHWPoison(hpage))) {
atomic_long_sub(nr_pages, &num_poisoned_pages); num_poisoned_pages_sub(nr_pages);
unlock_page(hpage); unlock_page(hpage);
return 0; return 0;
} }
...@@ -1173,7 +1173,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags) ...@@ -1173,7 +1173,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
else else
pr_err("MCE: %#lx: thp split failed\n", pfn); pr_err("MCE: %#lx: thp split failed\n", pfn);
if (TestClearPageHWPoison(p)) if (TestClearPageHWPoison(p))
atomic_long_sub(nr_pages, &num_poisoned_pages); num_poisoned_pages_sub(nr_pages);
put_hwpoison_page(p); put_hwpoison_page(p);
return -EBUSY; return -EBUSY;
} }
...@@ -1233,14 +1233,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags) ...@@ -1233,14 +1233,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
*/ */
if (!PageHWPoison(p)) { if (!PageHWPoison(p)) {
printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn); printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
atomic_long_sub(nr_pages, &num_poisoned_pages); num_poisoned_pages_sub(nr_pages);
unlock_page(hpage); unlock_page(hpage);
put_hwpoison_page(hpage); put_hwpoison_page(hpage);
return 0; return 0;
} }
if (hwpoison_filter(p)) { if (hwpoison_filter(p)) {
if (TestClearPageHWPoison(p)) if (TestClearPageHWPoison(p))
atomic_long_sub(nr_pages, &num_poisoned_pages); num_poisoned_pages_sub(nr_pages);
unlock_page(hpage); unlock_page(hpage);
put_hwpoison_page(hpage); put_hwpoison_page(hpage);
return 0; return 0;
...@@ -1469,7 +1469,7 @@ int unpoison_memory(unsigned long pfn) ...@@ -1469,7 +1469,7 @@ int unpoison_memory(unsigned long pfn)
return 0; return 0;
} }
if (TestClearPageHWPoison(p)) if (TestClearPageHWPoison(p))
atomic_long_dec(&num_poisoned_pages); num_poisoned_pages_dec();
pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn); pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
return 0; return 0;
} }
...@@ -1483,7 +1483,7 @@ int unpoison_memory(unsigned long pfn) ...@@ -1483,7 +1483,7 @@ int unpoison_memory(unsigned long pfn)
*/ */
if (TestClearPageHWPoison(page)) { if (TestClearPageHWPoison(page)) {
pr_info("MCE: Software-unpoisoned page %#lx\n", pfn); pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
atomic_long_sub(nr_pages, &num_poisoned_pages); num_poisoned_pages_sub(nr_pages);
freeit = 1; freeit = 1;
if (PageHuge(page)) if (PageHuge(page))
clear_page_hwpoison_huge_page(page); clear_page_hwpoison_huge_page(page);
...@@ -1619,11 +1619,10 @@ static int soft_offline_huge_page(struct page *page, int flags) ...@@ -1619,11 +1619,10 @@ static int soft_offline_huge_page(struct page *page, int flags)
if (PageHuge(page)) { if (PageHuge(page)) {
set_page_hwpoison_huge_page(hpage); set_page_hwpoison_huge_page(hpage);
dequeue_hwpoisoned_huge_page(hpage); dequeue_hwpoisoned_huge_page(hpage);
atomic_long_add(1 << compound_order(hpage), num_poisoned_pages_add(1 << compound_order(hpage));
&num_poisoned_pages);
} else { } else {
SetPageHWPoison(page); SetPageHWPoison(page);
atomic_long_inc(&num_poisoned_pages); num_poisoned_pages_inc();
} }
} }
return ret; return ret;
...@@ -1662,7 +1661,7 @@ static int __soft_offline_page(struct page *page, int flags) ...@@ -1662,7 +1661,7 @@ static int __soft_offline_page(struct page *page, int flags)
put_hwpoison_page(page); put_hwpoison_page(page);
pr_info("soft_offline: %#lx: invalidated\n", pfn); pr_info("soft_offline: %#lx: invalidated\n", pfn);
SetPageHWPoison(page); SetPageHWPoison(page);
atomic_long_inc(&num_poisoned_pages); num_poisoned_pages_inc();
return 0; return 0;
} }
...@@ -1683,7 +1682,7 @@ static int __soft_offline_page(struct page *page, int flags) ...@@ -1683,7 +1682,7 @@ static int __soft_offline_page(struct page *page, int flags)
page_is_file_cache(page)); page_is_file_cache(page));
list_add(&page->lru, &pagelist); list_add(&page->lru, &pagelist);
if (!TestSetPageHWPoison(page)) if (!TestSetPageHWPoison(page))
atomic_long_inc(&num_poisoned_pages); num_poisoned_pages_dec();
ret = migrate_pages(&pagelist, new_page, NULL, MPOL_MF_MOVE_ALL, ret = migrate_pages(&pagelist, new_page, NULL, MPOL_MF_MOVE_ALL,
MIGRATE_SYNC, MR_MEMORY_FAILURE); MIGRATE_SYNC, MR_MEMORY_FAILURE);
if (ret) { if (ret) {
...@@ -1699,7 +1698,7 @@ static int __soft_offline_page(struct page *page, int flags) ...@@ -1699,7 +1698,7 @@ static int __soft_offline_page(struct page *page, int flags)
if (ret > 0) if (ret > 0)
ret = -EIO; ret = -EIO;
if (TestClearPageHWPoison(page)) if (TestClearPageHWPoison(page))
atomic_long_dec(&num_poisoned_pages); num_poisoned_pages_dec();
} }
} else { } else {
pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n", pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
...@@ -1765,11 +1764,10 @@ int soft_offline_page(struct page *page, int flags) ...@@ -1765,11 +1764,10 @@ int soft_offline_page(struct page *page, int flags)
if (PageHuge(page)) { if (PageHuge(page)) {
set_page_hwpoison_huge_page(hpage); set_page_hwpoison_huge_page(hpage);
if (!dequeue_hwpoisoned_huge_page(hpage)) if (!dequeue_hwpoisoned_huge_page(hpage))
atomic_long_add(1 << compound_order(hpage), num_poisoned_pages_add(1 << compound_order(hpage));
&num_poisoned_pages);
} else { } else {
if (!TestSetPageHWPoison(page)) if (!TestSetPageHWPoison(page))
atomic_long_inc(&num_poisoned_pages); num_poisoned_pages_inc();
} }
} }
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment