From: Gregory Price <gourry@gourry.net>
To: linux-mm@kvack.org
Cc: linux-kernel@kvack.org, david@redhat.com, osalvador@suse.de,
gregkh@linuxfoundation.org, rafael@kernel.org,
akpm@linux-foundation.org
Subject: [PATCH] mm: add build-time option to set hotplug default type
Date: Fri, 20 Dec 2024 09:45:18 -0500 [thread overview]
Message-ID: <20241220144518.206208-1-gourry@gourry.net> (raw)
When memory hotplug auto-online is enabled, hotplug memory blocks are
onlined into ZONE_NORMAL by default. The `memhp_default_state` boot
param allows runtime configuration, but no build-time config exists.
Add a build-time configuration option to change default hotplug zone.
build config:
MEMHP_DEFAULT_TYPE
Selections:
MEMHP_DEFAULT_TYPE_NORMAL => mhp_default_online_type = "online"
MEMHP_DEFAULT_TYPE_MOVABLE => mhp_default_online_type = "online_movable"
When MEMORY_HOTPLUG_DEFAULT_ONLINE is disabled, MEMHP_DEFAULT_TYPE is
set to "offline" to match the current system behavior.
ZONE_NORMAL still remains the default, because for systems with a large
amount of hotplug memory, defaulting it to ZONE_MOVABLE may result in
portions failing to online if sufficient ZONE_NORMAL memory does not
exist to describe it.
Signed-off-by: Gregory Price <gourry@gourry.net>
---
drivers/base/memory.c | 4 ++--
include/linux/memory_hotplug.h | 5 +++--
mm/Kconfig | 33 +++++++++++++++++++++++++++++++++
mm/memory_hotplug.c | 29 ++++++++++++++++++++++-------
4 files changed, 60 insertions(+), 11 deletions(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 67858eeb92ed..6f69b01abe51 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -512,7 +512,7 @@ static ssize_t auto_online_blocks_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sysfs_emit(buf, "%s\n",
- online_type_to_str[mhp_default_online_type]);
+ online_type_to_str[memhp_default_type()]);
}
static ssize_t auto_online_blocks_store(struct device *dev,
@@ -524,7 +524,7 @@ static ssize_t auto_online_blocks_store(struct device *dev,
if (online_type < 0)
return -EINVAL;
- mhp_default_online_type = online_type;
+ memhp_set_default_type(online_type);
return count;
}
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index b27ddce5d324..a43470f0d93c 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -144,8 +144,6 @@ extern u64 max_mem_size;
extern int mhp_online_type_from_str(const char *str);
-/* Default online_type (MMOP_*) when new memory blocks are added. */
-extern int mhp_default_online_type;
/* If movable_node boot option specified */
extern bool movable_node_enabled;
static inline bool movable_node_is_enabled(void)
@@ -303,6 +301,9 @@ static inline void __remove_memory(u64 start, u64 size) {}
#endif /* CONFIG_MEMORY_HOTREMOVE */
#ifdef CONFIG_MEMORY_HOTPLUG
+/* Default online_type (MMOP_*) when new memory blocks are added. */
+extern int memhp_default_type(void);
+extern void memhp_set_default_type(int online_type);
extern void __ref free_area_init_core_hotplug(struct pglist_data *pgdat);
extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
diff --git a/mm/Kconfig b/mm/Kconfig
index 7949ab121070..b6e63e5306b1 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -565,6 +565,39 @@ config MEMORY_HOTPLUG_DEFAULT_ONLINE
Say N here if you want the default policy to keep all hot-plugged
memory blocks in 'offline' state.
+choice
+ prompt "Memory Hotplug Default Type"
+ depends on MEMORY_HOTPLUG_DEFAULT_ONLINE
+ default MEMHP_DEFAULT_TYPE_NORMAL
+ help
+ Default memory zone for driver managed hotplug memory.
+ Select normal to generally allow kernel usage of this memory.
+ Select movable to generally disallow kernel usage of this memory.
+ Example typical kernel usage would be page structs and page tables.
+
+
+config MEMHP_DEFAULT_TYPE_NORMAL
+ bool "Normal"
+ help
+ Online driver managed hotplug memory into zone normal.
+ Select this if you want the kernel to be able to utilize
+ this memory for kernel data (e.g. page tables).
+
+config MEMHP_DEFAULT_TYPE_MOVABLE
+ bool "Movable"
+ help
+ Online driver managed hotplug memory into zone movable.
+ Select this if you do not want the kernel to be able to
+ utilize this memory for kernel data (e.g. page tables).
+
+endchoice
+
+config MEMHP_DEFAULT_TYPE
+ string
+ default "online" if MEMHP_DEFAULT_TYPE_NORMAL
+ default "online_movable" if MEMHP_DEFAULT_TYPE_MOVABLE
+ default "offline"
+
config MEMORY_HOTREMOVE
bool "Allow for memory hot remove"
select HAVE_BOOTMEM_INFO_NODE if (X86_64 || PPC64)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 3b6f93962481..1e4340fa9f07 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -219,11 +219,26 @@ void put_online_mems(void)
bool movable_node_enabled = false;
-#ifndef CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE
-int mhp_default_online_type = MMOP_OFFLINE;
-#else
-int mhp_default_online_type = MMOP_ONLINE;
-#endif
+static int mhp_default_online_type = -1;
+int memhp_default_type(void)
+{
+ int type;
+
+ if (mhp_default_online_type >= 0)
+ return mhp_default_online_type;
+
+ type = mhp_online_type_from_str(CONFIG_MEMHP_DEFAULT_TYPE);
+ if (type < 0)
+ type = MMOP_OFFLINE;
+
+ mhp_default_online_type = type;
+ return mhp_default_online_type;
+}
+
+void memhp_set_default_type(int online_type)
+{
+ mhp_default_online_type = online_type;
+}
static int __init setup_memhp_default_state(char *str)
{
@@ -1328,7 +1343,7 @@ static int check_hotplug_memory_range(u64 start, u64 size)
static int online_memory_block(struct memory_block *mem, void *arg)
{
- mem->online_type = mhp_default_online_type;
+ mem->online_type = memhp_default_type();
return device_online(&mem->dev);
}
@@ -1575,7 +1590,7 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
merge_system_ram_resource(res);
/* online pages if requested */
- if (mhp_default_online_type != MMOP_OFFLINE)
+ if (memhp_default_type() != MMOP_OFFLINE)
walk_memory_blocks(start, size, NULL, online_memory_block);
return ret;
--
2.47.1
next reply other threads:[~2024-12-20 14:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 14:45 Gregory Price [this message]
2024-12-20 14:59 ` David Hildenbrand
2024-12-20 15:17 ` Gregory Price
2024-12-20 15:56 ` David Hildenbrand
2024-12-20 16:04 ` David Hildenbrand
2024-12-20 16:37 ` Gregory Price
2024-12-20 18:25 ` David Hildenbrand
2024-12-20 18:36 ` Gregory Price
2024-12-20 18:25 ` Gregory Price
2024-12-20 18:26 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241220144518.206208-1-gourry@gourry.net \
--to=gourry@gourry.net \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@kvack.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox