Skip to content

Commit

Permalink
mm/memory_hotplug.c: call register_mem_sect_under_node()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
osalvadorvilardaga authored and torvalds committed Aug 17, 2018
1 parent b9ff036 commit d5b6f6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
2 changes: 0 additions & 2 deletions drivers/base/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,6 @@ int hotplug_memory_register(int nid, struct mem_section *section)
mem->section_count++;
}

if (mem->section_count == sections_per_block)
ret = register_mem_sect_under_node(mem, nid, false);
out:
mutex_unlock(&mem_sysfs_mutex);
return ret;
Expand Down
32 changes: 11 additions & 21 deletions mm/memory_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
u64 start, size;
bool new_node = false;
int ret;
unsigned long start_pfn, nr_pages;

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

/* we online node here. we can't roll back from here. */
node_set_online(nid);

if (new_node) {
unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT;

ret = __register_one_node(nid);
if (ret)
goto register_fail;

/*
* link memory sections under this node. This is already
* done when creatig memory section in register_new_memory
* but that depends to have the node registered so offline
* nodes have to go through register_node.
* TODO clean up this mess.
*/
ret = link_mem_sections(nid, start_pfn, nr_pages, false);
register_fail:
/*
* If sysfs file of new node can't create, cpu on the node
/* If sysfs file of new node can't be created, cpu on the node
* can't be hot-added. There is no rollback way now.
* So, check by BUG_ON() to catch it reluctantly..
* We online node here. We can't roll back from here.
*/
node_set_online(nid);
ret = __register_one_node(nid);
BUG_ON(ret);
}

/* link memory sections under this node.*/
start_pfn = start >> PAGE_SHIFT;
nr_pages = size >> PAGE_SHIFT;
ret = link_mem_sections(nid, start_pfn, nr_pages, false);
BUG_ON(ret);

/* create new memmap entry */
firmware_map_add_hotplug(start, start + size, "System RAM");

Expand Down

0 comments on commit d5b6f6a

Please sign in to comment.