[PATCH 1/3] mm: consider zone which is not fully populated to have holes

From: Michal Hocko
Date: Sat Apr 15 2017 - 08:19:51 EST


From: Michal Hocko <mhocko@xxxxxxxx>

__pageblock_pfn_to_page has two users currently, set_zone_contiguous
which checks whether the given zone contains holes and
pageblock_pfn_to_page which then carefully returns a first valid
page from the given pfn range for the given zone. This doesn't handle
zones which are not fully populated though. Memory pageblocks can be
offlined or might not have been onlined yet. In such a case the zone
should be considered to have holes otherwise pfn walkers can touch
and play with offline pages.

Current callers of pageblock_pfn_to_page in compaction seem to work
properly right now because they only isolate PageBuddy
(isolate_freepages_block) or PageLRU resp. __PageMovable
(isolate_migratepages_block) which will be always false for these pages.
It would be safer to skip these pages altogether, though. In order
to do that let's check PageReserved in __pageblock_pfn_to_page because
offline pages are reserved.

Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
mm/page_alloc.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0cacba69ab04..dcbbcfdda60e 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1351,6 +1351,8 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
return NULL;

start_page = pfn_to_page(start_pfn);
+ if (PageReserved(start_page))
+ return NULL;

if (page_zone(start_page) != zone)
return NULL;
--
2.11.0