1 From 7f36e3e56db1ae75d1e157011b3cb2e0957f0a7e Mon Sep 17 00:00:00 2001
2 From: Tang Chen <tangchen@cn.fujitsu.com>
3 Date: Fri, 4 Sep 2015 15:42:32 -0700
4 Subject: memory-hotplug: add hot-added memory ranges to memblock before allocate node_data for a node.
6 From: Tang Chen <tangchen@cn.fujitsu.com>
8 commit 7f36e3e56db1ae75d1e157011b3cb2e0957f0a7e upstream.
10 Commit f9126ab9241f ("memory-hotplug: fix wrong edge when hot add a new
11 node") hot-added memory range to memblock, after creating pgdat for new
14 But there is a problem:
17 |--> hotadd_new_pgdat()
18 |--> free_area_init_node()
19 |--> get_pfn_range_for_nid()
20 |--> find start_pfn and end_pfn in memblock
22 |--> memblock_add_node(start, size, nid) -------- Here, just too late.
24 get_pfn_range_for_nid() will find that start_pfn and end_pfn are both 0.
25 As a result, when adding memory, dmesg will give the following wrong
28 Initmem setup node 5 [mem 0x0000000000000000-0xffffffffffffffff]
29 On node 5 totalpages: 0
30 Built 5 zonelists in Node order, mobility grouping on. Total pages: 32588823
32 init_memory_mapping: [mem 0x60000000000-0x607ffffffff]
34 The solution is simple, just add the memory range to memblock a little
35 earlier, before hotadd_new_pgdat().
37 [akpm@linux-foundation.org: coding-style fixes]
38 Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
39 Cc: Xishi Qiu <qiuxishi@huawei.com>
40 Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
41 Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
42 Cc: Taku Izumi <izumi.taku@jp.fujitsu.com>
43 Cc: Gu Zheng <guz.fnst@cn.fujitsu.com>
44 Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
45 Cc: Vlastimil Babka <vbabka@suse.cz>
46 Cc: Mel Gorman <mgorman@techsingularity.net>
47 Cc: David Rientjes <rientjes@google.com>
48 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
49 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
50 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
53 mm/memory_hotplug.c | 10 +++++++++-
54 1 file changed, 9 insertions(+), 1 deletion(-)
56 --- a/mm/memory_hotplug.c
57 +++ b/mm/memory_hotplug.c
58 @@ -1248,6 +1248,14 @@ int __ref add_memory(int nid, u64 start,
63 + * Add new range to memblock so that when hotadd_new_pgdat() is called
64 + * to allocate new pgdat, get_pfn_range_for_nid() will be able to find
65 + * this new range and calculate total pages correctly. The range will
66 + * be removed at hot-remove time.
68 + memblock_add_node(start, size, nid);
70 new_node = !node_online(nid);
72 pgdat = hotadd_new_pgdat(nid, start);
73 @@ -1277,7 +1285,6 @@ int __ref add_memory(int nid, u64 start,
75 /* create new memmap entry */
76 firmware_map_add_hotplug(start, start + size, "System RAM");
77 - memblock_add_node(start, size, nid);
81 @@ -1286,6 +1293,7 @@ error:
83 rollback_node_hotadd(nid, pgdat);
84 release_memory_resource(res);
85 + memblock_remove(start, size);