From bac699103c545693a4519be46ca0d6cd19fe57f0 Mon Sep 17 00:00:00 2001 From: Wen Congyang Date: Tue, 23 Oct 2012 13:50:14 +1100 Subject: [PATCH] memory-hotplug: allocate zone's pcp before onlining pages We use __free_page() to put a page to buddy system when onlining pages. __free_page() will store NR_FREE_PAGES in zone's pcp.vm_stat_diff, so we should allocate zone's pcp before onlining pages, otherwise we will lose some free pages. Signed-off-by: Wen Congyang Cc: David Rientjes Cc: Jiang Liu Cc: Len Brown Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Christoph Lameter Cc: Minchan Kim Cc: KOSAKI Motohiro Cc: Yasuaki Ishimatsu Cc: Dave Hansen Cc: Mel Gorman Signed-off-by: Andrew Morton --- mm/memory_hotplug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 72f4fef2b728..5c8ad6dcd18f 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -505,12 +505,16 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages) * So, zonelist must be updated after online. */ mutex_lock(&zonelists_mutex); - if (!populated_zone(zone)) + if (!populated_zone(zone)) { need_zonelists_rebuild = 1; + build_all_zonelists(NULL, zone); + } ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages, online_pages_range); if (ret) { + if (need_zonelists_rebuild) + zone_pcp_reset(zone); mutex_unlock(&zonelists_mutex); printk(KERN_DEBUG "online_pages [mem %#010llx-%#010llx] failed\n", (unsigned long long) pfn << PAGE_SHIFT, @@ -525,9 +529,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages) zone->zone_pgdat->node_present_pages += onlined_pages; if (onlined_pages) { node_set_state(zone_to_nid(zone), N_HIGH_MEMORY); - if (need_zonelists_rebuild) - build_all_zonelists(NULL, zone); - else + if (!need_zonelists_rebuild) zone_pcp_update(zone); } -- 2.39.5