diff options
author | Oscar Salvador <osalvador@suse.de> | 2018-08-17 18:46:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-17 19:20:29 -0400 |
commit | d5b6f6a3610b05e6712cb9c61a85a6dff16e91cf (patch) | |
tree | d5899d3a64bc6232a7c2112fe614a97f86482446 | |
parent | b9ff036082cd1793a59b35c4432644fe44620664 (diff) |
mm/memory_hotplug.c: call register_mem_sect_under_node()
When hotplugging memory, it is possible that two calls are being made to
register_mem_sect_under_node().
One comes from __add_section()->hotplug_memory_register() and the other
from add_memory_resource()->link_mem_sections() if we had to register a
new node.
In case we had to register a new node, hotplug_memory_register() will
only handle/allocate the memory_block's since
register_mem_sect_under_node() will return right away because the node
it is not online yet.
I think it is better if we leave hotplug_memory_register() to
handle/allocate only memory_block's and make link_mem_sections() to call
register_mem_sect_under_node().
So this patch removes the call to register_mem_sect_under_node() from
hotplug_memory_register(), and moves the call to link_mem_sections() out
of the condition, so it will always be called. In this way we only have
one place where the memory sections are registered.
Link: http://lkml.kernel.org/r/20180622111839.10071-3-osalvador@techadventures.net
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Pavel Tatashin <pasha.tatashin@oracle.com>
Tested-by: Reza Arbab <arbab@linux.vnet.ibm.com>
Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Pasha Tatashin <Pavel.Tatashin@microsoft.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/base/memory.c | 2 | ||||
-rw-r--r-- | mm/memory_hotplug.c | 32 |
2 files changed, 11 insertions, 23 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index f5e560188a18..c8a1cb0b6136 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -736,8 +736,6 @@ int hotplug_memory_register(int nid, struct mem_section *section) | |||
736 | mem->section_count++; | 736 | mem->section_count++; |
737 | } | 737 | } |
738 | 738 | ||
739 | if (mem->section_count == sections_per_block) | ||
740 | ret = register_mem_sect_under_node(mem, nid, false); | ||
741 | out: | 739 | out: |
742 | mutex_unlock(&mem_sysfs_mutex); | 740 | mutex_unlock(&mem_sysfs_mutex); |
743 | return ret; | 741 | return ret; |
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 504ba120bdfc..e2ed64b994e5 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c | |||
@@ -1123,6 +1123,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) | |||
1123 | u64 start, size; | 1123 | u64 start, size; |
1124 | bool new_node = false; | 1124 | bool new_node = false; |
1125 | int ret; | 1125 | int ret; |
1126 | unsigned long start_pfn, nr_pages; | ||
1126 | 1127 | ||
1127 | start = res->start; | 1128 | start = res->start; |
1128 | size = resource_size(res); | 1129 | size = resource_size(res); |
@@ -1151,34 +1152,23 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) | |||
1151 | if (ret < 0) | 1152 | if (ret < 0) |
1152 | goto error; | 1153 | goto error; |
1153 | 1154 | ||
1154 | /* we online node here. we can't roll back from here. */ | ||
1155 | node_set_online(nid); | ||
1156 | |||
1157 | if (new_node) { | 1155 | if (new_node) { |
1158 | unsigned long start_pfn = start >> PAGE_SHIFT; | 1156 | /* If sysfs file of new node can't be created, cpu on the node |
1159 | unsigned long nr_pages = size >> PAGE_SHIFT; | ||
1160 | |||
1161 | ret = __register_one_node(nid); | ||
1162 | if (ret) | ||
1163 | goto register_fail; | ||
1164 | |||
1165 | /* | ||
1166 | * link memory sections under this node. This is already | ||
1167 | * done when creatig memory section in register_new_memory | ||
1168 | * but that depends to have the node registered so offline | ||
1169 | * nodes have to go through register_node. | ||
1170 | * TODO clean up this mess. | ||
1171 | */ | ||
1172 | ret = link_mem_sections(nid, start_pfn, nr_pages, false); | ||
1173 | register_fail: | ||
1174 | /* | ||
1175 | * If sysfs file of new node can't create, cpu on the node | ||
1176 | * can't be hot-added. There is no rollback way now. | 1157 | * can't be hot-added. There is no rollback way now. |
1177 | * So, check by BUG_ON() to catch it reluctantly.. | 1158 | * So, check by BUG_ON() to catch it reluctantly.. |
1159 | * We online node here. We can't roll back from here. | ||
1178 | */ | 1160 | */ |
1161 | node_set_online(nid); | ||
1162 | ret = __register_one_node(nid); | ||
1179 | BUG_ON(ret); | 1163 | BUG_ON(ret); |
1180 | } | 1164 | } |
1181 | 1165 | ||
1166 | /* link memory sections under this node.*/ | ||
1167 | start_pfn = start >> PAGE_SHIFT; | ||
1168 | nr_pages = size >> PAGE_SHIFT; | ||
1169 | ret = link_mem_sections(nid, start_pfn, nr_pages, false); | ||
1170 | BUG_ON(ret); | ||
1171 | |||
1182 | /* create new memmap entry */ | 1172 | /* create new memmap entry */ |
1183 | firmware_map_add_hotplug(start, start + size, "System RAM"); | 1173 | firmware_map_add_hotplug(start, start + size, "System RAM"); |
1184 | 1174 | ||