Skip to content

Commit c8bd84f

Browse files
pizhenweiakpm00
authored andcommitted
mm/memory-failure.c: simplify num_poisoned_pages_dec
Don't decrease the number of poisoned pages in page_alloc.c, let the memory-failure.c do inc/dec poisoned pages only. Also simplify unpoison_memory(), only decrease the number of poisoned pages when: - TestClearPageHWPoison() succeed - put_page_back_buddy succeed After decreasing, print necessary log. Finally, remove clear_page_hwpoison() and unpoison_taken_off_page(). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: zhenwei pi <[email protected]> Acked-by: Naoya Horiguchi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 60f272f commit c8bd84f

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

mm/memory-failure.c

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,28 +2092,6 @@ core_initcall(memory_failure_init);
20922092
pr_info(fmt, pfn); \
20932093
})
20942094

2095-
static inline int clear_page_hwpoison(struct ratelimit_state *rs, struct page *p)
2096-
{
2097-
if (TestClearPageHWPoison(p)) {
2098-
unpoison_pr_info("Unpoison: Software-unpoisoned page %#lx\n",
2099-
page_to_pfn(p), rs);
2100-
num_poisoned_pages_dec();
2101-
return 1;
2102-
}
2103-
return 0;
2104-
}
2105-
2106-
static inline int unpoison_taken_off_page(struct ratelimit_state *rs,
2107-
struct page *p)
2108-
{
2109-
if (put_page_back_buddy(p)) {
2110-
unpoison_pr_info("Unpoison: Software-unpoisoned page %#lx\n",
2111-
page_to_pfn(p), rs);
2112-
return 0;
2113-
}
2114-
return -EBUSY;
2115-
}
2116-
21172095
/**
21182096
* unpoison_memory - Unpoison a previously poisoned page
21192097
* @pfn: Page number of the to be unpoisoned page
@@ -2131,6 +2109,7 @@ int unpoison_memory(unsigned long pfn)
21312109
struct page *page;
21322110
struct page *p;
21332111
int ret = -EBUSY;
2112+
int freeit = 0;
21342113
static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL,
21352114
DEFAULT_RATELIMIT_BURST);
21362115

@@ -2171,18 +2150,15 @@ int unpoison_memory(unsigned long pfn)
21712150

21722151
ret = get_hwpoison_page(p, MF_UNPOISON);
21732152
if (!ret) {
2174-
if (clear_page_hwpoison(&unpoison_rs, page))
2175-
ret = 0;
2176-
else
2177-
ret = -EBUSY;
2153+
ret = TestClearPageHWPoison(page) ? 0 : -EBUSY;
21782154
} else if (ret < 0) {
21792155
if (ret == -EHWPOISON) {
2180-
ret = unpoison_taken_off_page(&unpoison_rs, p);
2156+
ret = put_page_back_buddy(p) ? 0 : -EBUSY;
21812157
} else
21822158
unpoison_pr_info("Unpoison: failed to grab page %#lx\n",
21832159
pfn, &unpoison_rs);
21842160
} else {
2185-
int freeit = clear_page_hwpoison(&unpoison_rs, p);
2161+
freeit = !!TestClearPageHWPoison(p);
21862162

21872163
put_page(page);
21882164
if (freeit && !(pfn == my_zero_pfn(0) && page_count(p) == 1)) {
@@ -2193,6 +2169,11 @@ int unpoison_memory(unsigned long pfn)
21932169

21942170
unlock_mutex:
21952171
mutex_unlock(&mf_mutex);
2172+
if (!ret || freeit) {
2173+
num_poisoned_pages_dec();
2174+
unpoison_pr_info("Unpoison: Software-unpoisoned page %#lx\n",
2175+
page_to_pfn(p), &unpoison_rs);
2176+
}
21962177
return ret;
21972178
}
21982179
EXPORT_SYMBOL(unpoison_memory);

mm/page_alloc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9497,7 +9497,6 @@ bool put_page_back_buddy(struct page *page)
94979497
ClearPageHWPoisonTakenOff(page);
94989498
__free_one_page(page, pfn, zone, 0, migratetype, FPI_NONE);
94999499
if (TestClearPageHWPoison(page)) {
9500-
num_poisoned_pages_dec();
95019500
ret = true;
95029501
}
95039502
}

0 commit comments

Comments
 (0)