Skip to content

Commit d5b6f6a

Browse files
osalvadorvilardagatorvalds
authored andcommitted
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/[email protected] Signed-off-by: Oscar Salvador <[email protected]> Reviewed-by: Pavel Tatashin <[email protected]> Tested-by: Reza Arbab <[email protected]> Tested-by: Jonathan Cameron <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b9ff036 commit d5b6f6a

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

drivers/base/memory.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,6 @@ int hotplug_memory_register(int nid, struct mem_section *section)
736736
mem->section_count++;
737737
}
738738

739-
if (mem->section_count == sections_per_block)
740-
ret = register_mem_sect_under_node(mem, nid, false);
741739
out:
742740
mutex_unlock(&mem_sysfs_mutex);
743741
return ret;

mm/memory_hotplug.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
11231123
u64 start, size;
11241124
bool new_node = false;
11251125
int ret;
1126+
unsigned long start_pfn, nr_pages;
11261127

11271128
start = res->start;
11281129
size = resource_size(res);
@@ -1151,34 +1152,23 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
11511152
if (ret < 0)
11521153
goto error;
11531154

1154-
/* we online node here. we can't roll back from here. */
1155-
node_set_online(nid);
1156-
11571155
if (new_node) {
1158-
unsigned long start_pfn = start >> PAGE_SHIFT;
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
1156+
/* If sysfs file of new node can't be created, cpu on the node
11761157
* can't be hot-added. There is no rollback way now.
11771158
* So, check by BUG_ON() to catch it reluctantly..
1159+
* We online node here. We can't roll back from here.
11781160
*/
1161+
node_set_online(nid);
1162+
ret = __register_one_node(nid);
11791163
BUG_ON(ret);
11801164
}
11811165

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+
11821172
/* create new memmap entry */
11831173
firmware_map_add_hotplug(start, start + size, "System RAM");
11841174

0 commit comments

Comments
 (0)