[PATCH] fold me "mm: consider zone which is not fully populated to have holes"

From: Michal Hocko
Date: Thu May 18 2017 - 12:38:24 EST


- check valid section number in pfn_to_online_page - Vlastimil
- mark sections online after all struct pages are initialized in
online_pages_range - Vlastimil

Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
include/linux/memory_hotplug.h | 3 ++-
mm/memory_hotplug.c | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index aec88657ec49..9e0249d0f5e4 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -22,8 +22,9 @@ struct resource;
#define pfn_to_online_page(pfn) \
({ \
struct page *___page = NULL; \
+ unsigned long ___nr = pfn_to_section_nr(pfn); \
\
- if (online_section_nr(pfn_to_section_nr(pfn))) \
+ if (___nr < NR_MEM_SECTIONS && online_section_nr(___nr))\
___page = pfn_to_page(pfn); \
___page; \
})
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index de30822642c6..a31b547c11f0 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -746,14 +746,15 @@ static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
unsigned long onlined_pages = *(unsigned long *)arg;
struct page *page;

- online_mem_sections(start_pfn, start_pfn + nr_pages);
-
if (PageReserved(pfn_to_page(start_pfn)))
for (i = 0; i < nr_pages; i++) {
page = pfn_to_page(start_pfn + i);
(*online_page_callback)(page);
onlined_pages++;
}
+
+ online_mem_sections(start_pfn, start_pfn + nr_pages);
+
*(unsigned long *)arg = onlined_pages;
return 0;
}
--
2.11.0


--
Michal Hocko
SUSE Labs