diff options
author | Toshi Kani <toshi.kani@hp.com> | 2013-11-12 18:07:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 22:09:04 -0500 |
commit | 01b0f19707c51ef247404e6af1d4a97a11ba34f7 (patch) | |
tree | 0e266339d6a644acdb7300c1a6bbad4106c68d57 | |
parent | 309d0b3917387b48d1fa1a15aa6762de489c9123 (diff) |
cpu/mem hotplug: add try_online_node() for cpu_up()
cpu_up() has #ifdef CONFIG_MEMORY_HOTPLUG code blocks, which call
mem_online_node() to put its node online if offlined and then call
build_all_zonelists() to initialize the zone list.
These steps are specific to memory hotplug, and should be managed in
mm/memory_hotplug.c. lock_memory_hotplug() should also be held for the
whole steps.
For this reason, this patch replaces mem_online_node() with
try_online_node(), which performs the whole steps with
lock_memory_hotplug() held. try_online_node() is named after
try_offline_node() as they have similar purpose.
There is no functional change in this patch.
Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Reviewed-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/memory_hotplug.h | 8 | ||||
-rw-r--r-- | kernel/cpu.c | 29 | ||||
-rw-r--r-- | mm/memory_hotplug.c | 16 |
3 files changed, 24 insertions, 29 deletions
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index dd38e62b84d2..22203c293f07 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h | |||
@@ -94,6 +94,8 @@ extern void __online_page_set_limits(struct page *page); | |||
94 | extern void __online_page_increment_counters(struct page *page); | 94 | extern void __online_page_increment_counters(struct page *page); |
95 | extern void __online_page_free(struct page *page); | 95 | extern void __online_page_free(struct page *page); |
96 | 96 | ||
97 | extern int try_online_node(int nid); | ||
98 | |||
97 | #ifdef CONFIG_MEMORY_HOTREMOVE | 99 | #ifdef CONFIG_MEMORY_HOTREMOVE |
98 | extern bool is_pageblock_removable_nolock(struct page *page); | 100 | extern bool is_pageblock_removable_nolock(struct page *page); |
99 | extern int arch_remove_memory(u64 start, u64 size); | 101 | extern int arch_remove_memory(u64 start, u64 size); |
@@ -225,6 +227,11 @@ static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) | |||
225 | { | 227 | { |
226 | } | 228 | } |
227 | 229 | ||
230 | static inline int try_online_node(int nid) | ||
231 | { | ||
232 | return 0; | ||
233 | } | ||
234 | |||
228 | static inline void lock_memory_hotplug(void) {} | 235 | static inline void lock_memory_hotplug(void) {} |
229 | static inline void unlock_memory_hotplug(void) {} | 236 | static inline void unlock_memory_hotplug(void) {} |
230 | 237 | ||
@@ -256,7 +263,6 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} | |||
256 | 263 | ||
257 | extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | 264 | extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, |
258 | void *arg, int (*func)(struct memory_block *, void *)); | 265 | void *arg, int (*func)(struct memory_block *, void *)); |
259 | extern int mem_online_node(int nid); | ||
260 | extern int add_memory(int nid, u64 start, u64 size); | 266 | extern int add_memory(int nid, u64 start, u64 size); |
261 | extern int arch_add_memory(int nid, u64 start, u64 size); | 267 | extern int arch_add_memory(int nid, u64 start, u64 size); |
262 | extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); | 268 | extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); |
diff --git a/kernel/cpu.c b/kernel/cpu.c index 63aa50d7ce1e..973d034acf84 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -437,11 +437,6 @@ int cpu_up(unsigned int cpu) | |||
437 | { | 437 | { |
438 | int err = 0; | 438 | int err = 0; |
439 | 439 | ||
440 | #ifdef CONFIG_MEMORY_HOTPLUG | ||
441 | int nid; | ||
442 | pg_data_t *pgdat; | ||
443 | #endif | ||
444 | |||
445 | if (!cpu_possible(cpu)) { | 440 | if (!cpu_possible(cpu)) { |
446 | printk(KERN_ERR "can't online cpu %d because it is not " | 441 | printk(KERN_ERR "can't online cpu %d because it is not " |
447 | "configured as may-hotadd at boot time\n", cpu); | 442 | "configured as may-hotadd at boot time\n", cpu); |
@@ -452,27 +447,9 @@ int cpu_up(unsigned int cpu) | |||
452 | return -EINVAL; | 447 | return -EINVAL; |
453 | } | 448 | } |
454 | 449 | ||
455 | #ifdef CONFIG_MEMORY_HOTPLUG | 450 | err = try_online_node(cpu_to_node(cpu)); |
456 | nid = cpu_to_node(cpu); | 451 | if (err) |
457 | if (!node_online(nid)) { | 452 | return err; |
458 | err = mem_online_node(nid); | ||
459 | if (err) | ||
460 | return err; | ||
461 | } | ||
462 | |||
463 | pgdat = NODE_DATA(nid); | ||
464 | if (!pgdat) { | ||
465 | printk(KERN_ERR | ||
466 | "Can't online cpu %d due to NULL pgdat\n", cpu); | ||
467 | return -ENOMEM; | ||
468 | } | ||
469 | |||
470 | if (pgdat->node_zonelists->_zonerefs->zone == NULL) { | ||
471 | mutex_lock(&zonelists_mutex); | ||
472 | build_all_zonelists(NULL, NULL); | ||
473 | mutex_unlock(&zonelists_mutex); | ||
474 | } | ||
475 | #endif | ||
476 | 453 | ||
477 | cpu_maps_update_begin(); | 454 | cpu_maps_update_begin(); |
478 | 455 | ||
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 5118028468eb..8285346be663 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c | |||
@@ -1043,17 +1043,23 @@ static void rollback_node_hotadd(int nid, pg_data_t *pgdat) | |||
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | 1045 | ||
1046 | /* | 1046 | /** |
1047 | * try_online_node - online a node if offlined | ||
1048 | * | ||
1047 | * called by cpu_up() to online a node without onlined memory. | 1049 | * called by cpu_up() to online a node without onlined memory. |
1048 | */ | 1050 | */ |
1049 | int mem_online_node(int nid) | 1051 | int try_online_node(int nid) |
1050 | { | 1052 | { |
1051 | pg_data_t *pgdat; | 1053 | pg_data_t *pgdat; |
1052 | int ret; | 1054 | int ret; |
1053 | 1055 | ||
1056 | if (node_online(nid)) | ||
1057 | return 0; | ||
1058 | |||
1054 | lock_memory_hotplug(); | 1059 | lock_memory_hotplug(); |
1055 | pgdat = hotadd_new_pgdat(nid, 0); | 1060 | pgdat = hotadd_new_pgdat(nid, 0); |
1056 | if (!pgdat) { | 1061 | if (!pgdat) { |
1062 | pr_err("Cannot online node %d due to NULL pgdat\n", nid); | ||
1057 | ret = -ENOMEM; | 1063 | ret = -ENOMEM; |
1058 | goto out; | 1064 | goto out; |
1059 | } | 1065 | } |
@@ -1061,6 +1067,12 @@ int mem_online_node(int nid) | |||
1061 | ret = register_one_node(nid); | 1067 | ret = register_one_node(nid); |
1062 | BUG_ON(ret); | 1068 | BUG_ON(ret); |
1063 | 1069 | ||
1070 | if (pgdat->node_zonelists->_zonerefs->zone == NULL) { | ||
1071 | mutex_lock(&zonelists_mutex); | ||
1072 | build_all_zonelists(NULL, NULL); | ||
1073 | mutex_unlock(&zonelists_mutex); | ||
1074 | } | ||
1075 | |||
1064 | out: | 1076 | out: |
1065 | unlock_memory_hotplug(); | 1077 | unlock_memory_hotplug(); |
1066 | return ret; | 1078 | return ret; |