Commit d84f2f5a authored by David Hildenbrand's avatar David Hildenbrand Committed by Linus Torvalds
Browse files

drivers/base/node.c: simplify unregister_memory_block_under_nodes()

We don't allow to offline memory block devices that belong to multiple
numa nodes.  Therefore, such devices can never get removed.  It is
sufficient to process a single node when removing the memory block.  No
need to iterate over each and every PFN.

We already have the nid stored for each memory block.  Make sure that the
nid always has a sane value.

Please note that checking for node_online(nid) is not required.  If we
would have a memory block belonging to a node that is no longer offline,
then we would have a BUG in the node offlining code.


Signed-off-by: default avatarDavid Hildenbrand <>
Cc: Greg Kroah-Hartman <>
Cc: "Rafael J. Wysocki" <>
Cc: David Hildenbrand <>
Cc: Stephen Rothwell <>
Cc: Pavel Tatashin <>
Cc: Michal Hocko <>
Cc: Oscar Salvador <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 3fccb74c
......@@ -674,6 +674,7 @@ static int init_memory_block(struct memory_block **memory,
mem->state = state;
start_pfn = section_nr_to_pfn(mem->start_section_nr);
mem->phys_device = arch_get_memory_phys_device(start_pfn);
mem->nid = NUMA_NO_NODE;
ret = register_memory(mem);
......@@ -759,8 +759,6 @@ static int register_mem_sect_under_node(struct memory_block *mem_blk,
int ret, nid = *(int *)arg;
unsigned long pfn, sect_start_pfn, sect_end_pfn;
mem_blk->nid = nid;
sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
sect_end_pfn += PAGES_PER_SECTION - 1;
......@@ -789,6 +787,13 @@ static int register_mem_sect_under_node(struct memory_block *mem_blk,
if (page_nid != nid)
* If this memory block spans multiple nodes, we only indicate
* the last processed node.
mem_blk->nid = nid;
ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
......@@ -804,32 +809,18 @@ static int register_mem_sect_under_node(struct memory_block *mem_blk,
* Unregister memory block device under all nodes that it spans.
* Has to be called with mem_sysfs_mutex held (due to unlinked_nodes).
* Unregister a memory block device under the node it spans. Memory blocks
* with multiple nodes cannot be offlined and therefore also never be removed.
void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
unsigned long pfn, sect_start_pfn, sect_end_pfn;
static nodemask_t unlinked_nodes;
sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
int nid;
if (mem_blk->nid == NUMA_NO_NODE)
nid = get_nid_for_pfn(pfn);
if (nid < 0)
if (!node_online(nid))
if (node_test_and_set(nid, unlinked_nodes))
int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment