summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Salvador <osalvador@suse.de>2018-08-17 18:46:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-17 19:20:29 -0400
commit4fbce633910ed80b135b84160a22b219080c8082 (patch)
tree719985a2f3a69277b26a6e3ba124829b7bf44eee
parentd5b6f6a3610b05e6712cb9c61a85a6dff16e91cf (diff)
mm/memory_hotplug.c: make register_mem_sect_under_node() a callback of walk_memory_range()
link_mem_sections() and walk_memory_range() share most of the code, so we can use convert link_mem_sections() into a dummy function that calls walk_memory_range() with a callback to register_mem_sect_under_node(). This patch converts register_mem_sect_under_node() in order to match a walk_memory_range's callback, getting rid of the check_nid argument and checking instead if the system is still boothing, since we only have to check for the nid if the system is in such state. Link: http://lkml.kernel.org/r/20180622111839.10071-4-osalvador@techadventures.net Signed-off-by: Oscar Salvador <osalvador@suse.de> Suggested-by: Pavel Tatashin <pasha.tatashin@oracle.com> Tested-by: Reza Arbab <arbab@linux.vnet.ibm.com> Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Pavel 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/node.c44
-rw-r--r--include/linux/node.h12
-rw-r--r--mm/memory_hotplug.c5
3 files changed, 14 insertions, 47 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index a5e821d09656..845d5523812b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -399,10 +399,9 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
399} 399}
400 400
401/* register memory section under specified node if it spans that node */ 401/* register memory section under specified node if it spans that node */
402int register_mem_sect_under_node(struct memory_block *mem_blk, int nid, 402int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
403 bool check_nid)
404{ 403{
405 int ret; 404 int ret, nid = *(int *)arg;
406 unsigned long pfn, sect_start_pfn, sect_end_pfn; 405 unsigned long pfn, sect_start_pfn, sect_end_pfn;
407 406
408 if (!mem_blk) 407 if (!mem_blk)
@@ -433,7 +432,7 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
433 * case, during hotplug we know that all pages in the memory 432 * case, during hotplug we know that all pages in the memory
434 * block belong to the same node. 433 * block belong to the same node.
435 */ 434 */
436 if (check_nid) { 435 if (system_state == SYSTEM_BOOTING) {
437 page_nid = get_nid_for_pfn(pfn); 436 page_nid = get_nid_for_pfn(pfn);
438 if (page_nid < 0) 437 if (page_nid < 0)
439 continue; 438 continue;
@@ -490,41 +489,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
490 return 0; 489 return 0;
491} 490}
492 491
493int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages, 492int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
494 bool check_nid)
495{ 493{
496 unsigned long end_pfn = start_pfn + nr_pages; 494 return walk_memory_range(start_pfn, end_pfn, (void *)&nid,
497 unsigned long pfn; 495 register_mem_sect_under_node);
498 struct memory_block *mem_blk = NULL;
499 int err = 0;
500
501 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
502 unsigned long section_nr = pfn_to_section_nr(pfn);
503 struct mem_section *mem_sect;
504 int ret;
505
506 if (!present_section_nr(section_nr))
507 continue;
508 mem_sect = __nr_to_section(section_nr);
509
510 /* same memblock ? */
511 if (mem_blk)
512 if ((section_nr >= mem_blk->start_section_nr) &&
513 (section_nr <= mem_blk->end_section_nr))
514 continue;
515
516 mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
517
518 ret = register_mem_sect_under_node(mem_blk, nid, check_nid);
519 if (!err)
520 err = ret;
521
522 /* discard ref obtained in find_memory_block() */
523 }
524
525 if (mem_blk)
526 kobject_put(&mem_blk->dev.kobj);
527 return err;
528} 496}
529 497
530#ifdef CONFIG_HUGETLBFS 498#ifdef CONFIG_HUGETLBFS
diff --git a/include/linux/node.h b/include/linux/node.h
index 6d336e38d155..257bb3d6d014 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -33,10 +33,10 @@ typedef void (*node_registration_func_t)(struct node *);
33 33
34#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) 34#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
35extern int link_mem_sections(int nid, unsigned long start_pfn, 35extern int link_mem_sections(int nid, unsigned long start_pfn,
36 unsigned long nr_pages, bool check_nid); 36 unsigned long end_pfn);
37#else 37#else
38static inline int link_mem_sections(int nid, unsigned long start_pfn, 38static inline int link_mem_sections(int nid, unsigned long start_pfn,
39 unsigned long nr_pages, bool check_nid) 39 unsigned long end_pfn)
40{ 40{
41 return 0; 41 return 0;
42} 42}
@@ -54,12 +54,14 @@ static inline int register_one_node(int nid)
54 54
55 if (node_online(nid)) { 55 if (node_online(nid)) {
56 struct pglist_data *pgdat = NODE_DATA(nid); 56 struct pglist_data *pgdat = NODE_DATA(nid);
57 unsigned long start_pfn = pgdat->node_start_pfn;
58 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
57 59
58 error = __register_one_node(nid); 60 error = __register_one_node(nid);
59 if (error) 61 if (error)
60 return error; 62 return error;
61 /* link memory sections under this node */ 63 /* link memory sections under this node */
62 error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages, true); 64 error = link_mem_sections(nid, start_pfn, end_pfn);
63 } 65 }
64 66
65 return error; 67 return error;
@@ -69,7 +71,7 @@ extern void unregister_one_node(int nid);
69extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); 71extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
70extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 72extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
71extern int register_mem_sect_under_node(struct memory_block *mem_blk, 73extern int register_mem_sect_under_node(struct memory_block *mem_blk,
72 int nid, bool check_nid); 74 void *arg);
73extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 75extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
74 unsigned long phys_index); 76 unsigned long phys_index);
75 77
@@ -99,7 +101,7 @@ static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
99 return 0; 101 return 0;
100} 102}
101static inline int register_mem_sect_under_node(struct memory_block *mem_blk, 103static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
102 int nid, bool check_nid) 104 void *arg)
103{ 105{
104 return 0; 106 return 0;
105} 107}
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index e2ed64b994e5..4eb6e824a80c 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1123,7 +1123,6 @@ 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;
1127 1126
1128 start = res->start; 1127 start = res->start;
1129 size = resource_size(res); 1128 size = resource_size(res);
@@ -1164,9 +1163,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
1164 } 1163 }
1165 1164
1166 /* link memory sections under this node.*/ 1165 /* link memory sections under this node.*/
1167 start_pfn = start >> PAGE_SHIFT; 1166 ret = link_mem_sections(nid, PFN_DOWN(start), PFN_UP(start + size - 1));
1168 nr_pages = size >> PAGE_SHIFT;
1169 ret = link_mem_sections(nid, start_pfn, nr_pages, false);
1170 BUG_ON(ret); 1167 BUG_ON(ret);
1171 1168
1172 /* create new memmap entry */ 1169 /* create new memmap entry */