Skip to content

Commit 4fbce63

Browse files
osalvadorvilardagatorvalds
authored andcommitted
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>
1 parent d5b6f6a commit 4fbce63

File tree

3 files changed

+14
-47
lines changed

3 files changed

+14
-47
lines changed

drivers/base/node.c

+6-38
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,9 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
399399
}
400400

401401
/* register memory section under specified node if it spans that node */
402-
int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
403-
bool check_nid)
402+
int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
404403
{
405-
int ret;
404+
int ret, nid = *(int *)arg;
406405
unsigned long pfn, sect_start_pfn, sect_end_pfn;
407406

408407
if (!mem_blk)
@@ -433,7 +432,7 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
433432
* case, during hotplug we know that all pages in the memory
434433
* block belong to the same node.
435434
*/
436-
if (check_nid) {
435+
if (system_state == SYSTEM_BOOTING) {
437436
page_nid = get_nid_for_pfn(pfn);
438437
if (page_nid < 0)
439438
continue;
@@ -490,41 +489,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
490489
return 0;
491490
}
492491

493-
int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages,
494-
bool check_nid)
492+
int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
495493
{
496-
unsigned long end_pfn = start_pfn + nr_pages;
497-
unsigned long pfn;
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;
494+
return walk_memory_range(start_pfn, end_pfn, (void *)&nid,
495+
register_mem_sect_under_node);
528496
}
529497

530498
#ifdef CONFIG_HUGETLBFS

include/linux/node.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ typedef void (*node_registration_func_t)(struct node *);
3333

3434
#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
3535
extern int link_mem_sections(int nid, unsigned long start_pfn,
36-
unsigned long nr_pages, bool check_nid);
36+
unsigned long end_pfn);
3737
#else
3838
static inline int link_mem_sections(int nid, unsigned long start_pfn,
39-
unsigned long nr_pages, bool check_nid)
39+
unsigned long end_pfn)
4040
{
4141
return 0;
4242
}
@@ -54,12 +54,14 @@ static inline int register_one_node(int nid)
5454

5555
if (node_online(nid)) {
5656
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;
5759

5860
error = __register_one_node(nid);
5961
if (error)
6062
return error;
6163
/* 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);
6365
}
6466

6567
return error;
@@ -69,7 +71,7 @@ extern void unregister_one_node(int nid);
6971
extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
7072
extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
7173
extern int register_mem_sect_under_node(struct memory_block *mem_blk,
72-
int nid, bool check_nid);
74+
void *arg);
7375
extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
7476
unsigned long phys_index);
7577

@@ -99,7 +101,7 @@ static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
99101
return 0;
100102
}
101103
static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
102-
int nid, bool check_nid)
104+
void *arg)
103105
{
104106
return 0;
105107
}

mm/memory_hotplug.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,6 @@ 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;
11271126

11281127
start = res->start;
11291128
size = resource_size(res);
@@ -1164,9 +1163,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
11641163
}
11651164

11661165
/* 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);
1166+
ret = link_mem_sections(nid, PFN_DOWN(start), PFN_UP(start + size - 1));
11701167
BUG_ON(ret);
11711168

11721169
/* create new memmap entry */

0 commit comments

Comments
 (0)