aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorVitaly Kuznetsov <vkuznets@redhat.com>2016-03-15 17:56:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-15 19:55:16 -0400
commit31bc3858ea3ebcc3157b3f5f0e624c5962f5a7a6 (patch)
tree85b88976d85135ad518de3aa47cfef6e826d3917 /mm
parent9cb65bc3b1114004e2ccee5939031325c7bf16e8 (diff)
memory-hotplug: add automatic onlining policy for the newly added memory
Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like: SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online" to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory. Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/auto_online_blocks file with two possible values: "offline" which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added. The default is "offline". Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Daniel Kiper <daniel.kiper@oracle.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Tang Chen <tangchen@cn.fujitsu.com> Cc: David Vrabel <david.vrabel@citrix.com> Acked-by: David Rientjes <rientjes@google.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Xishi Qiu <qiuxishi@huawei.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Igor Mammedov <imammedo@redhat.com> Cc: Kay Sievers <kay@vrfy.org> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memory_hotplug.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 979b18cbd343..484e86761b3e 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -77,6 +77,9 @@ static struct {
77#define memhp_lock_acquire() lock_map_acquire(&mem_hotplug.dep_map) 77#define memhp_lock_acquire() lock_map_acquire(&mem_hotplug.dep_map)
78#define memhp_lock_release() lock_map_release(&mem_hotplug.dep_map) 78#define memhp_lock_release() lock_map_release(&mem_hotplug.dep_map)
79 79
80bool memhp_auto_online;
81EXPORT_SYMBOL_GPL(memhp_auto_online);
82
80void get_online_mems(void) 83void get_online_mems(void)
81{ 84{
82 might_sleep(); 85 might_sleep();
@@ -1261,8 +1264,13 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default,
1261 return zone_default; 1264 return zone_default;
1262} 1265}
1263 1266
1267static int online_memory_block(struct memory_block *mem, void *arg)
1268{
1269 return memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
1270}
1271
1264/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ 1272/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1265int __ref add_memory_resource(int nid, struct resource *res) 1273int __ref add_memory_resource(int nid, struct resource *res, bool online)
1266{ 1274{
1267 u64 start, size; 1275 u64 start, size;
1268 pg_data_t *pgdat = NULL; 1276 pg_data_t *pgdat = NULL;
@@ -1322,6 +1330,11 @@ int __ref add_memory_resource(int nid, struct resource *res)
1322 /* create new memmap entry */ 1330 /* create new memmap entry */
1323 firmware_map_add_hotplug(start, start + size, "System RAM"); 1331 firmware_map_add_hotplug(start, start + size, "System RAM");
1324 1332
1333 /* online pages if requested */
1334 if (online)
1335 walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
1336 NULL, online_memory_block);
1337
1325 goto out; 1338 goto out;
1326 1339
1327error: 1340error:
@@ -1345,7 +1358,7 @@ int __ref add_memory(int nid, u64 start, u64 size)
1345 if (IS_ERR(res)) 1358 if (IS_ERR(res))
1346 return PTR_ERR(res); 1359 return PTR_ERR(res);
1347 1360
1348 ret = add_memory_resource(nid, res); 1361 ret = add_memory_resource(nid, res, memhp_auto_online);
1349 if (ret < 0) 1362 if (ret < 0)
1350 release_memory_resource(res); 1363 release_memory_resource(res);
1351 return ret; 1364 return ret;