Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1619819

[PATCH 5/9] mm, memory_hotplug: split up register_one_node

From Michal Hocko <mhocko@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 5/9] mm, memory_hotplug: split up register_one_node
Date 2017-04-10 13:10 +0200
Message-ID <tuFmP-8iD-31@gated-at.bofh.it> (permalink)
References <tuFmO-8iD-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Michal Hocko <mhocko@suse.com>

Memory hotplug (add_memory_resource) has to reinitialize node
infrastructure if the node is offline (one which went through the
complete add_memory(); remove_memory() cycle). That involves node
registration to the kobj infrastructure (register_node), the proper
association with cpus (register_cpu_under_node) and finally creation of
node<->memblock symlinks (link_mem_sections).

The last part requires to know node_start_pfn and node_spanned_pages
which we currently have but a leter patch will postpone this
initialization to the onlining phase which happens later. In fact we do
not need to rely on the early pgdat initialization even now because the
currently hot added pfn range is currently known.

Split register_one_node into core which does all the common work for
the boot time NUMA initialization and the hotplug (__register_one_node).
register_one_node keeps the full initialization while hotplug calls
__register_one_node and manually calls link_mem_sections for the proper
range.

This shouldn't introduce any functional change.

Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/base/node.c  | 51 ++++++++++++++++++++-------------------------------
 include/linux/node.h | 35 ++++++++++++++++++++++++++++++++++-
 mm/memory_hotplug.c  | 17 ++++++++++++++++-
 3 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index 06294d69779b..dff5b53f7905 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -461,10 +461,9 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
 	return 0;
 }
 
-static int link_mem_sections(int nid)
+int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)
 {
-	unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
-	unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
+	unsigned long end_pfn = start_pfn + nr_pages;
 	unsigned long pfn;
 	struct memory_block *mem_blk = NULL;
 	int err = 0;
@@ -552,10 +551,7 @@ static int node_memory_callback(struct notifier_block *self,
 	return NOTIFY_OK;
 }
 #endif	/* CONFIG_HUGETLBFS */
-#else	/* !CONFIG_MEMORY_HOTPLUG_SPARSE */
-
-static int link_mem_sections(int nid) { return 0; }
-#endif	/* CONFIG_MEMORY_HOTPLUG_SPARSE */
+#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
 
 #if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || \
     !defined(CONFIG_HUGETLBFS)
@@ -569,39 +565,32 @@ static void init_node_hugetlb_work(int nid) { }
 
 #endif
 
-int register_one_node(int nid)
+int __register_one_node(int nid)
 {
-	int error = 0;
+	int p_node = parent_node(nid);
+	struct node *parent = NULL;
+	int error;
 	int cpu;
 
-	if (node_online(nid)) {
-		int p_node = parent_node(nid);
-		struct node *parent = NULL;
-
-		if (p_node != nid)
-			parent = node_devices[p_node];
-
-		node_devices[nid] = kzalloc(sizeof(struct node), GFP_KERNEL);
-		if (!node_devices[nid])
-			return -ENOMEM;
-
-		error = register_node(node_devices[nid], nid, parent);
+	if (p_node != nid)
+		parent = node_devices[p_node];
 
-		/* link cpu under this node */
-		for_each_present_cpu(cpu) {
-			if (cpu_to_node(cpu) == nid)
-				register_cpu_under_node(cpu, nid);
-		}
+	node_devices[nid] = kzalloc(sizeof(struct node), GFP_KERNEL);
+	if (!node_devices[nid])
+		return -ENOMEM;
 
-		/* link memory sections under this node */
-		error = link_mem_sections(nid);
+	error = register_node(node_devices[nid], nid, parent);
 
-		/* initialize work queue for memory hot plug */
-		init_node_hugetlb_work(nid);
+	/* link cpu under this node */
+	for_each_present_cpu(cpu) {
+		if (cpu_to_node(cpu) == nid)
+			register_cpu_under_node(cpu, nid);
 	}
 
-	return error;
+	/* initialize work queue for memory hot plug */
+	init_node_hugetlb_work(nid);
 
+	return error;
 }
 
 void unregister_one_node(int nid)
diff --git a/include/linux/node.h b/include/linux/node.h
index 2115ad5d6f19..d1751beb462c 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -30,9 +30,38 @@ struct memory_block;
 extern struct node *node_devices[];
 typedef  void (*node_registration_func_t)(struct node *);
 
+#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
+extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages);
+#else
+static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)
+{
+	return 0;
+}
+#endif
+
 extern void unregister_node(struct node *node);
 #ifdef CONFIG_NUMA
-extern int register_one_node(int nid);
+/* Core of the node registration - only memory hotplug should use this */
+extern int __register_one_node(int nid);
+
+/* Registers an online node */
+static inline int register_one_node(int nid)
+{
+	int error = 0;
+
+	if (node_online(nid)) {
+		struct pglist_data *pgdat = NODE_DATA(nid);
+
+		error = __register_one_node(nid);
+		if (error)
+			return error;
+		/* link memory sections under this node */
+		error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages);
+	}
+
+	return error;
+}
+
 extern void unregister_one_node(int nid);
 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
@@ -46,6 +75,10 @@ extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
 					 node_registration_func_t unregister);
 #endif
 #else
+static inline int __register_one_node(int nid)
+{
+	return 0;
+}
 static inline int register_one_node(int nid)
 {
 	return 0;
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 1570b3eea493..f5df0fe15ddf 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1387,7 +1387,22 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
 	node_set_online(nid);
 
 	if (new_node) {
-		ret = register_one_node(nid);
+		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);
+register_fail:
 		/*
 		 * If sysfs file of new node can't create, cpu on the node
 		 * can't be hot-added. There is no rollback way now.
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 13:10 +0200
  [PATCH 3/9] mm: drop page_initialized check from get_nid_for_pfn Michal Hocko <mhocko@kernel.org> - 2017-04-10 13:10 +0200
    Re: [PATCH 3/9] mm: drop page_initialized check from get_nid_for_pfn Vlastimil Babka <vbabka@suse.cz> - 2017-04-13 15:00 +0200
  [PATCH 9/9] mm, memory_hotplug: remove unused cruft after memory hotplug rework Michal Hocko <mhocko@kernel.org> - 2017-04-10 13:10 +0200
    Re: [PATCH 9/9] mm, memory_hotplug: remove unused cruft after memory  hotplug rework Vlastimil Babka <vbabka@suse.cz> - 2017-04-20 10:40 +0200
  [PATCH 4/9] mm, memory_hotplug: get rid of is_zone_device_section Michal Hocko <mhocko@kernel.org> - 2017-04-10 13:10 +0200
    Re: [PATCH 4/9] mm, memory_hotplug: get rid of is_zone_device_section Jerome Glisse <jglisse@redhat.com> - 2017-04-10 18:30 +0200
      Re: [PATCH 4/9] mm, memory_hotplug: get rid of is_zone_device_section Michal Hocko <mhocko@kernel.org> - 2017-04-10 18:40 +0200
    Re: [PATCH 4/9] mm, memory_hotplug: get rid of is_zone_device_section Vlastimil Babka <vbabka@suse.cz> - 2017-04-13 15:10 +0200
    Re: [PATCH 4/9] mm, memory_hotplug: get rid of is_zone_device_section Jerome Glisse <jglisse@redhat.com> - 2017-04-17 22:20 +0200
      Re: [PATCH 4/9] mm, memory_hotplug: get rid of is_zone_device_section Michal Hocko <mhocko@kernel.org> - 2017-04-18 09:20 +0200
  [PATCH 5/9] mm, memory_hotplug: split up register_one_node Michal Hocko <mhocko@kernel.org> - 2017-04-10 13:10 +0200
    Re: [PATCH 5/9] mm, memory_hotplug: split up register_one_node Vlastimil Babka <vbabka@suse.cz> - 2017-04-13 16:10 +0200
      Re: [PATCH 5/9] mm, memory_hotplug: split up register_one_node Michal Hocko <mhocko@kernel.org> - 2017-04-13 16:20 +0200
  Re: [PATCH -v2 0/9] mm: make movable onlining suck less Igor Mammedov <imammedo@redhat.com> - 2017-04-10 16:30 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 17:00 +0200
      Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 17:30 +0200
        Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 17:40 +0200
      Re: [PATCH -v2 0/9] mm: make movable onlining suck less Igor Mammedov <imammedo@redhat.com> - 2017-04-11 10:10 +0200
        Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 10:50 +0200
          Re: [PATCH -v2 0/9] mm: make movable onlining suck less Igor Mammedov <imammedo@redhat.com> - 2017-04-11 12:00 +0200
            Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 12:50 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 18:10 +0200
      Re: [PATCH -v2 0/9] mm: make movable onlining suck less Vlastimil Babka <vbabka@suse.cz> - 2017-04-18 10:30 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 18:10 +0200
      Re: [PATCH -v2 0/9] mm: make movable onlining suck less Igor Mammedov <imammedo@redhat.com> - 2017-04-11 08:40 +0200
        Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 11:30 +0200
          Re: [PATCH -v2 0/9] mm: make movable onlining suck less Igor Mammedov <imammedo@redhat.com> - 2017-04-11 12:00 +0200
            Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 13:10 +0200
              Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 13:40 +0200
                Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 14:40 +0200
  Re: [PATCH -v2 0/9] mm: make movable onlining suck less Reza Arbab <arbab@linux.vnet.ibm.com> - 2017-04-10 17:50 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 11:00 +0200
  Re: [PATCH -v2 0/9] mm: make movable onlining suck less Jerome Glisse <jglisse@redhat.com> - 2017-04-10 18:40 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-10 20:00 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Balbir Singh <bsingharora@gmail.com> - 2017-04-11 05:00 +0200
  Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-11 19:10 +0200
    Re: [PATCH -v2 0/9] mm: make movable onlining suck less Dan Williams <dan.j.williams@gmail.com> - 2017-04-18 00:00 +0200
      Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-18 09:20 +0200
        Re: [PATCH -v2 0/9] mm: make movable onlining suck less Dan Williams <dan.j.williams@gmail.com> - 2017-04-18 18:50 +0200
          Re: [PATCH -v2 0/9] mm: make movable onlining suck less Michal Hocko <mhocko@kernel.org> - 2017-04-18 22:00 +0200
            Re: [PATCH -v2 0/9] mm: make movable onlining suck less Dan Williams <dan.j.williams@intel.com> - 2017-04-20 05:40 +0200
  [PATCH 3/3] mm: __first_valid_page skip over offline pages Michal Hocko <mhocko@kernel.org> - 2017-04-15 14:20 +0200
  [PATCH 1/3] mm: consider zone which is not fully populated to have holes Michal Hocko <mhocko@kernel.org> - 2017-04-15 14:20 +0200
    Re: [PATCH 1/3] mm: consider zone which is not fully populated to  have holes Vlastimil Babka <vbabka@suse.cz> - 2017-04-18 10:50 +0200
      Re: [PATCH 1/3] mm: consider zone which is not fully populated to  have holes Michal Hocko <mhocko@kernel.org> - 2017-04-18 11:30 +0200
        Re: [PATCH 1/3] mm: consider zone which is not fully populated to  have holes Vlastimil Babka <vbabka@suse.cz> - 2017-04-19 14:00 +0200
          Re: [PATCH 1/3] mm: consider zone which is not fully populated to  have holes Michal Hocko <mhocko@kernel.org> - 2017-04-19 14:20 +0200
            Re: [PATCH 1/3] mm: consider zone which is not fully populated to  have holes Vlastimil Babka <vbabka@suse.cz> - 2017-04-19 14:40 +0200
              Re: [PATCH 1/3] mm: consider zone which is not fully populated to  have holes Michal Hocko <mhocko@kernel.org> - 2017-04-19 15:00 +0200
  (none) Michal Hocko <mhocko@kernel.org> - 2017-04-15 14:20 +0200
    [PATCH 2/3] mm, compaction: skip over holes in __reset_isolation_suitable Michal Hocko <mhocko@kernel.org> - 2017-04-15 14:20 +0200
    Re: your mail Joonsoo Kim <js1304@gmail.com> - 2017-04-17 07:50 +0200
      Re: your mail Michal Hocko <mhocko@kernel.org> - 2017-04-17 10:20 +0200
        Re: your mail Joonsoo Kim <js1304@gmail.com> - 2017-04-20 03:30 +0200
          Re: your mail Michal Hocko <mhocko@kernel.org> - 2017-04-20 09:30 +0200
            Re: your mail Michal Hocko <mhocko@kernel.org> - 2017-04-20 10:50 +0200
              Re: your mail Vlastimil Babka <vbabka@suse.cz> - 2017-04-20 14:00 +0200
                Re: your mail Michal Hocko <mhocko@kernel.org> - 2017-04-20 14:20 +0200
            Re: your mail Joonsoo Kim <js1304@gmail.com> - 2017-04-21 06:40 +0200
              Re: your mail Michal Hocko <mhocko@kernel.org> - 2017-04-21 09:20 +0200
                Re: your mail Joonsoo Kim <js1304@gmail.com> - 2017-04-24 03:50 +0200
                Re: your mail Michal Hocko <mhocko@kernel.org> - 2017-04-24 10:00 +0200

csiph-web