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

Configure Feed

Select the types of activity you want to include in your feed.

mm: add build-time option for hotplug memory default online type

Memory hotplug presently auto-onlines memory into a zone the kernel deems
appropriate if CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y.

The memhp_default_state boot param enables runtime config, but it's not
possible to do this at build-time.

Remove CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE, and replace it with
CONFIG_MHP_DEFAULT_ONLINE_TYPE_* choices that sync with the boot param.

Selections:
CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE
=> mhp_default_online_type = "offline"
Memory will not be onlined automatically.

CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO
=> mhp_default_online_type = "online"
Memory will be onlined automatically in a zone deemed.
appropriate by the kernel.

CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL
=> mhp_default_online_type = "online_kernel"
Memory will be onlined automatically.
The zone may allow kernel data (e.g. ZONE_NORMAL).

CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE
=> mhp_default_online_type = "online_movable"
Memory will be onlined automatically.
The zone will be ZONE_MOVABLE.

Default to CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE to match the existing
default CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=n behavior.

Existing users of CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y should use
CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO.

[gourry@gourry.net: update KConfig comments]
Link: https://lkml.kernel.org/r/20241226182918.648799-1-gourry@gourry.net
Link: https://lkml.kernel.org/r/20241220210709.300066-1-gourry@gourry.net
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Gregory Price and committed by
Andrew Morton
44d46b76 901083d8

+89 -23
+2 -2
Documentation/admin-guide/kernel-parameters.txt
··· 3351 3351 [KNL] Set the initial state for the memory hotplug 3352 3352 onlining policy. If not specified, the default value is 3353 3353 set according to the 3354 - CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE kernel config 3355 - option. 3354 + CONFIG_MHP_DEFAULT_ONLINE_TYPE kernel config 3355 + options. 3356 3356 See Documentation/admin-guide/mm/memory-hotplug.rst. 3357 3357 3358 3358 memmap=exactmap [KNL,X86,EARLY] Enable setting of an exact
+2 -2
Documentation/admin-guide/mm/memory-hotplug.rst
··· 280 280 blocks; configure auto-onlining. 281 281 282 282 The default value depends on the 283 - CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE kernel configuration 284 - option. 283 + CONFIG_MHP_DEFAULT_ONLINE_TYPE kernel configuration 284 + options. 285 285 286 286 See the ``state`` property of memory blocks for details. 287 287 ``block_size_bytes`` read-only: the size in bytes of a memory block.
+4 -1
arch/loongarch/configs/loongson3_defconfig
··· 113 113 CONFIG_ZSMALLOC=m 114 114 # CONFIG_COMPAT_BRK is not set 115 115 CONFIG_MEMORY_HOTPLUG=y 116 - CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y 116 + # CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE is not set 117 + CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO=y 118 + # CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL is not set 119 + # CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE is not set 117 120 CONFIG_MEMORY_HOTREMOVE=y 118 121 CONFIG_KSM=y 119 122 CONFIG_TRANSPARENT_HUGEPAGE=y
+2 -2
drivers/base/memory.c
··· 512 512 struct device_attribute *attr, char *buf) 513 513 { 514 514 return sysfs_emit(buf, "%s\n", 515 - online_type_to_str[mhp_default_online_type]); 515 + online_type_to_str[mhp_get_default_online_type()]); 516 516 } 517 517 518 518 static ssize_t auto_online_blocks_store(struct device *dev, ··· 524 524 if (online_type < 0) 525 525 return -EINVAL; 526 526 527 - mhp_default_online_type = online_type; 527 + mhp_set_default_online_type(online_type); 528 528 return count; 529 529 } 530 530
+3 -2
include/linux/memory_hotplug.h
··· 144 144 145 145 extern int mhp_online_type_from_str(const char *str); 146 146 147 - /* Default online_type (MMOP_*) when new memory blocks are added. */ 148 - extern int mhp_default_online_type; 149 147 /* If movable_node boot option specified */ 150 148 extern bool movable_node_enabled; 151 149 static inline bool movable_node_is_enabled(void) ··· 301 303 #endif /* CONFIG_MEMORY_HOTREMOVE */ 302 304 303 305 #ifdef CONFIG_MEMORY_HOTPLUG 306 + /* Default online_type (MMOP_*) when new memory blocks are added. */ 307 + extern int mhp_get_default_online_type(void); 308 + extern void mhp_set_default_online_type(int online_type); 304 309 extern void __ref free_area_init_core_hotplug(struct pglist_data *pgdat); 305 310 extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); 306 311 extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
+50 -7
mm/Kconfig
··· 550 550 551 551 if MEMORY_HOTPLUG 552 552 553 - config MEMORY_HOTPLUG_DEFAULT_ONLINE 554 - bool "Online the newly added memory blocks by default" 555 - depends on MEMORY_HOTPLUG 553 + choice 554 + prompt "Memory Hotplug Default Online Type" 555 + default MHP_DEFAULT_ONLINE_TYPE_OFFLINE 556 556 help 557 + Default memory type for hotplugged memory. 558 + 557 559 This option sets the default policy setting for memory hotplug 558 560 onlining policy (/sys/devices/system/memory/auto_online_blocks) which 559 561 determines what happens to newly added memory regions. Policy setting 560 562 can always be changed at runtime. 563 + 564 + The default is 'offline'. 565 + 566 + Select offline to defer onlining to drivers and user policy. 567 + Select auto to let the kernel choose what zones to utilize. 568 + Select online_kernel to generally allow kernel usage of this memory. 569 + Select online_movable to generally disallow kernel usage of this memory. 570 + 571 + Example kernel usage would be page structs and page tables. 572 + 561 573 See Documentation/admin-guide/mm/memory-hotplug.rst for more information. 562 574 563 - Say Y here if you want all hot-plugged memory blocks to appear in 564 - 'online' state by default. 565 - Say N here if you want the default policy to keep all hot-plugged 566 - memory blocks in 'offline' state. 575 + config MHP_DEFAULT_ONLINE_TYPE_OFFLINE 576 + bool "offline" 577 + help 578 + Hotplugged memory will not be onlined by default. 579 + Choose this for systems with drivers and user policy that 580 + handle onlining of hotplug memory policy. 581 + 582 + config MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO 583 + bool "auto" 584 + help 585 + Select this if you want the kernel to automatically online 586 + hotplugged memory into the zone it thinks is reasonable. 587 + This memory may be utilized for kernel data. 588 + 589 + config MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL 590 + bool "kernel" 591 + help 592 + Select this if you want the kernel to automatically online 593 + hotplugged memory into a zone capable of being used for kernel 594 + data. This typically means ZONE_NORMAL. 595 + 596 + config MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE 597 + bool "movable" 598 + help 599 + Select this if you want the kernel to automatically online 600 + hotplug memory into ZONE_MOVABLE. This memory will generally 601 + not be utilized for kernel data. 602 + 603 + This should only be used when the admin knows sufficient 604 + ZONE_NORMAL memory is available to describe hotplug memory, 605 + otherwise hotplug memory may fail to online. For example, 606 + sufficient kernel-capable memory (ZONE_NORMAL) must be 607 + available to allocate page structs to describe ZONE_MOVABLE. 608 + 609 + endchoice 567 610 568 611 config MEMORY_HOTREMOVE 569 612 bool "Allow for memory hot remove"
+26 -7
mm/memory_hotplug.c
··· 219 219 220 220 bool movable_node_enabled = false; 221 221 222 - #ifndef CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE 223 - int mhp_default_online_type = MMOP_OFFLINE; 224 - #else 225 - int mhp_default_online_type = MMOP_ONLINE; 226 - #endif 222 + static int mhp_default_online_type = -1; 223 + int mhp_get_default_online_type(void) 224 + { 225 + if (mhp_default_online_type >= 0) 226 + return mhp_default_online_type; 227 + 228 + if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE)) 229 + mhp_default_online_type = MMOP_OFFLINE; 230 + else if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO)) 231 + mhp_default_online_type = MMOP_ONLINE; 232 + else if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL)) 233 + mhp_default_online_type = MMOP_ONLINE_KERNEL; 234 + else if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE)) 235 + mhp_default_online_type = MMOP_ONLINE_MOVABLE; 236 + else 237 + mhp_default_online_type = MMOP_OFFLINE; 238 + 239 + return mhp_default_online_type; 240 + } 241 + 242 + void mhp_set_default_online_type(int online_type) 243 + { 244 + mhp_default_online_type = online_type; 245 + } 227 246 228 247 static int __init setup_memhp_default_state(char *str) 229 248 { ··· 1347 1328 1348 1329 static int online_memory_block(struct memory_block *mem, void *arg) 1349 1330 { 1350 - mem->online_type = mhp_default_online_type; 1331 + mem->online_type = mhp_get_default_online_type(); 1351 1332 return device_online(&mem->dev); 1352 1333 } 1353 1334 ··· 1594 1575 merge_system_ram_resource(res); 1595 1576 1596 1577 /* online pages if requested */ 1597 - if (mhp_default_online_type != MMOP_OFFLINE) 1578 + if (mhp_get_default_online_type() != MMOP_OFFLINE) 1598 1579 walk_memory_blocks(start, size, NULL, online_memory_block); 1599 1580 1600 1581 return ret;