aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTang Chen <tangchen@cn.fujitsu.com>2014-08-06 19:05:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 21:01:16 -0400
commit4f7c6b49c45a398d72763d1f0e64ddff8b3653c7 (patch)
tree156a0907b39d4e8af61a729870e9013679f4c099
parent1f6a6cc82ed305c09385753c80bb7b3bc9eea864 (diff)
mem-hotplug: introduce MMOP_OFFLINE to replace the hard coding -1
In store_mem_state(), we have: ... 334 else if (!strncmp(buf, "offline", min_t(int, count, 7))) 335 online_type = -1; ... 355 case -1: 356 ret = device_offline(&mem->dev); 357 break; ... Here, "offline" is hard coded as -1. This patch does the following renaming: ONLINE_KEEP -> MMOP_ONLINE_KEEP ONLINE_KERNEL -> MMOP_ONLINE_KERNEL ONLINE_MOVABLE -> MMOP_ONLINE_MOVABLE and introduces MMOP_OFFLINE = -1 to avoid hard coding. Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Cc: Hu Tao <hutao@cn.fujitsu.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/base/memory.c18
-rw-r--r--include/linux/memory_hotplug.h9
-rw-r--r--mm/memory_hotplug.c9
3 files changed, 20 insertions, 16 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index c6707dfb5284..7c60ed27e711 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -284,7 +284,7 @@ static int memory_subsys_online(struct device *dev)
284 * attribute and need to set the online_type. 284 * attribute and need to set the online_type.
285 */ 285 */
286 if (mem->online_type < 0) 286 if (mem->online_type < 0)
287 mem->online_type = ONLINE_KEEP; 287 mem->online_type = MMOP_ONLINE_KEEP;
288 288
289 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); 289 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
290 290
@@ -316,22 +316,22 @@ store_mem_state(struct device *dev,
316 return ret; 316 return ret;
317 317
318 if (sysfs_streq(buf, "online_kernel")) 318 if (sysfs_streq(buf, "online_kernel"))
319 online_type = ONLINE_KERNEL; 319 online_type = MMOP_ONLINE_KERNEL;
320 else if (sysfs_streq(buf, "online_movable")) 320 else if (sysfs_streq(buf, "online_movable"))
321 online_type = ONLINE_MOVABLE; 321 online_type = MMOP_ONLINE_MOVABLE;
322 else if (sysfs_streq(buf, "online")) 322 else if (sysfs_streq(buf, "online"))
323 online_type = ONLINE_KEEP; 323 online_type = MMOP_ONLINE_KEEP;
324 else if (sysfs_streq(buf, "offline")) 324 else if (sysfs_streq(buf, "offline"))
325 online_type = -1; 325 online_type = MMOP_OFFLINE;
326 else { 326 else {
327 ret = -EINVAL; 327 ret = -EINVAL;
328 goto err; 328 goto err;
329 } 329 }
330 330
331 switch (online_type) { 331 switch (online_type) {
332 case ONLINE_KERNEL: 332 case MMOP_ONLINE_KERNEL:
333 case ONLINE_MOVABLE: 333 case MMOP_ONLINE_MOVABLE:
334 case ONLINE_KEEP: 334 case MMOP_ONLINE_KEEP:
335 /* 335 /*
336 * mem->online_type is not protected so there can be a 336 * mem->online_type is not protected so there can be a
337 * race here. However, when racing online, the first 337 * race here. However, when racing online, the first
@@ -342,7 +342,7 @@ store_mem_state(struct device *dev,
342 mem->online_type = online_type; 342 mem->online_type = online_type;
343 ret = device_online(&mem->dev); 343 ret = device_online(&mem->dev);
344 break; 344 break;
345 case -1: 345 case MMOP_OFFLINE:
346 ret = device_offline(&mem->dev); 346 ret = device_offline(&mem->dev);
347 break; 347 break;
348 default: 348 default:
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 010d125bffbf..79dd9eca054f 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -26,11 +26,12 @@ enum {
26 MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO, 26 MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
27}; 27};
28 28
29/* Types for control the zone type of onlined memory */ 29/* Types for control the zone type of onlined and offlined memory */
30enum { 30enum {
31 ONLINE_KEEP, 31 MMOP_OFFLINE = -1,
32 ONLINE_KERNEL, 32 MMOP_ONLINE_KEEP,
33 ONLINE_MOVABLE, 33 MMOP_ONLINE_KERNEL,
34 MMOP_ONLINE_MOVABLE,
34}; 35};
35 36
36/* 37/*
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 3557e8c9e8de..a3797d3fd8a4 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -977,15 +977,18 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
977 zone = page_zone(pfn_to_page(pfn)); 977 zone = page_zone(pfn_to_page(pfn));
978 978
979 ret = -EINVAL; 979 ret = -EINVAL;
980 if ((zone_idx(zone) > ZONE_NORMAL || online_type == ONLINE_MOVABLE) && 980 if ((zone_idx(zone) > ZONE_NORMAL ||
981 online_type == MMOP_ONLINE_MOVABLE) &&
981 !can_online_high_movable(zone)) 982 !can_online_high_movable(zone))
982 goto out; 983 goto out;
983 984
984 if (online_type == ONLINE_KERNEL && zone_idx(zone) == ZONE_MOVABLE) { 985 if (online_type == MMOP_ONLINE_KERNEL &&
986 zone_idx(zone) == ZONE_MOVABLE) {
985 if (move_pfn_range_left(zone - 1, zone, pfn, pfn + nr_pages)) 987 if (move_pfn_range_left(zone - 1, zone, pfn, pfn + nr_pages))
986 goto out; 988 goto out;
987 } 989 }
988 if (online_type == ONLINE_MOVABLE && zone_idx(zone) == ZONE_MOVABLE - 1) { 990 if (online_type == MMOP_ONLINE_MOVABLE &&
991 zone_idx(zone) == ZONE_MOVABLE - 1) {
989 if (move_pfn_range_right(zone, zone + 1, pfn, pfn + nr_pages)) 992 if (move_pfn_range_right(zone, zone + 1, pfn, pfn + nr_pages))
990 goto out; 993 goto out;
991 } 994 }