Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memory_hotplug: introduce CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE

This patchset continues the work I started with commit 31bc3858ea3e
("memory-hotplug: add automatic onlining policy for the newly added
memory").

Initially I was going to stop there and bring the policy setting logic
to userspace. I met two issues on this way:

1) It is possible to have memory hotplugged at boot (e.g. with QEMU).
These blocks stay offlined if we turn the onlining policy on by
userspace.

2) My attempt to bring this policy setting to systemd failed, systemd
maintainers suggest to change the default in kernel or ... to use
tmpfiles.d to alter the policy (which looks like a hack to me):
https://github.com/systemd/systemd/pull/2938

Here I suggest to add a config option to set the default value for the
policy and a kernel command line parameter to make the override.

This patch (of 2):

Introduce config option to set the default value for memory hotplug
onlining policy (/sys/devices/system/memory/auto_online_blocks). The
reason one would want to turn this option on are to have early onlining
for hotpluggable memory available at boot and to not require any
userspace actions to make memory hotplug work.

[akpm@linux-foundation.org: tweak Kconfig text]
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Vitaly Kuznetsov and committed by
Linus Torvalds
8604d9e5 fd8cfd30

+25 -4
+5 -4
Documentation/memory-hotplug.txt
··· 261 261 262 262 % cat /sys/devices/system/memory/auto_online_blocks 263 263 264 - The default is "offline" which means the newly added memory is not in a 265 - ready-to-use state and you have to "online" the newly added memory blocks 266 - manually. Automatic onlining can be requested by writing "online" to 267 - "auto_online_blocks" file: 264 + The default depends on the CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE kernel config 265 + option. If it is disabled the default is "offline" which means the newly added 266 + memory is not in a ready-to-use state and you have to "online" the newly added 267 + memory blocks manually. Automatic onlining can be requested by writing "online" 268 + to "auto_online_blocks" file: 268 269 269 270 % echo online > /sys/devices/system/memory/auto_online_blocks 270 271
+16
mm/Kconfig
··· 192 192 def_bool y 193 193 depends on SPARSEMEM && MEMORY_HOTPLUG 194 194 195 + config MEMORY_HOTPLUG_DEFAULT_ONLINE 196 + bool "Online the newly added memory blocks by default" 197 + default n 198 + depends on MEMORY_HOTPLUG 199 + help 200 + This option sets the default policy setting for memory hotplug 201 + onlining policy (/sys/devices/system/memory/auto_online_blocks) which 202 + determines what happens to newly added memory regions. Policy setting 203 + can always be changed at runtime. 204 + See Documentation/memory-hotplug.txt for more information. 205 + 206 + Say Y here if you want all hot-plugged memory blocks to appear in 207 + 'online' state by default. 208 + Say N here if you want the default policy to keep all hot-plugged 209 + memory blocks in 'offline' state. 210 + 195 211 config MEMORY_HOTREMOVE 196 212 bool "Allow for memory hot remove" 197 213 select MEMORY_ISOLATION
+4
mm/memory_hotplug.c
··· 78 78 #define memhp_lock_acquire() lock_map_acquire(&mem_hotplug.dep_map) 79 79 #define memhp_lock_release() lock_map_release(&mem_hotplug.dep_map) 80 80 81 + #ifndef CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE 81 82 bool memhp_auto_online; 83 + #else 84 + bool memhp_auto_online = true; 85 + #endif 82 86 EXPORT_SYMBOL_GPL(memhp_auto_online); 83 87 84 88 void get_online_mems(void)