diff options
author | Wei Yang <richard.weiyang@gmail.com> | 2020-06-04 01:58:39 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2020-06-04 06:09:44 +0300 |
commit | 58b7f1194fe1e188a1687e45c3475a98906aae4b (patch) | |
tree | f1d26608c2d363659fd99244a38f6755b616eec7 /mm/page_alloc.c | |
parent | 534fe5e3c44f93ddd9daf7bb59ec2950583d0522 (diff) | |
download | linux-58b7f1194fe1e188a1687e45c3475a98906aae4b.tar.xz |
mm/page_alloc.c: extract check_[new|free]_page_bad() common part to page_bad_reason()
We share similar code in check_[new|free]_page_bad() to get the page's bad
reason.
Let's extract it and reduce code duplication.
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Link: http://lkml.kernel.org/r/20200411220357.9636-6-richard.weiyang@gmail.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r-- | mm/page_alloc.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 57c497d32738..cbe73a5610a1 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1070,7 +1070,7 @@ static inline bool page_expected_state(struct page *page, return true; } -static void check_free_page_bad(struct page *page) +static const char *page_bad_reason(struct page *page, unsigned long flags) { const char *bad_reason = NULL; @@ -1080,13 +1080,23 @@ static void check_free_page_bad(struct page *page) bad_reason = "non-NULL mapping"; if (unlikely(page_ref_count(page) != 0)) bad_reason = "nonzero _refcount"; - if (unlikely(page->flags & PAGE_FLAGS_CHECK_AT_FREE)) - bad_reason = "PAGE_FLAGS_CHECK_AT_FREE flag(s) set"; + if (unlikely(page->flags & flags)) { + if (flags == PAGE_FLAGS_CHECK_AT_PREP) + bad_reason = "PAGE_FLAGS_CHECK_AT_PREP flag(s) set"; + else + bad_reason = "PAGE_FLAGS_CHECK_AT_FREE flag(s) set"; + } #ifdef CONFIG_MEMCG if (unlikely(page->mem_cgroup)) bad_reason = "page still charged to cgroup"; #endif - bad_page(page, bad_reason); + return bad_reason; +} + +static void check_free_page_bad(struct page *page) +{ + bad_page(page, + page_bad_reason(page, PAGE_FLAGS_CHECK_AT_FREE)); } static inline int check_free_page(struct page *page) @@ -2083,26 +2093,14 @@ static inline void expand(struct zone *zone, struct page *page, static void check_new_page_bad(struct page *page) { - const char *bad_reason = NULL; - if (unlikely(page->flags & __PG_HWPOISON)) { /* Don't complain about hwpoisoned pages */ page_mapcount_reset(page); /* remove PageBuddy */ return; } - if (unlikely(atomic_read(&page->_mapcount) != -1)) - bad_reason = "nonzero mapcount"; - if (unlikely(page->mapping != NULL)) - bad_reason = "non-NULL mapping"; - if (unlikely(page_ref_count(page) != 0)) - bad_reason = "nonzero _refcount"; - if (unlikely(page->flags & PAGE_FLAGS_CHECK_AT_PREP)) - bad_reason = "PAGE_FLAGS_CHECK_AT_PREP flag set"; -#ifdef CONFIG_MEMCG - if (unlikely(page->mem_cgroup)) - bad_reason = "page still charged to cgroup"; -#endif - bad_page(page, bad_reason); + + bad_page(page, + page_bad_reason(page, PAGE_FLAGS_CHECK_AT_PREP)); } /* |