From patchwork Fri Dec 20 14:45:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13916861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D951E77188 for ; Fri, 20 Dec 2024 14:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CD126B0083; Fri, 20 Dec 2024 09:45:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17D2F6B0088; Fri, 20 Dec 2024 09:45:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01D5B6B0089; Fri, 20 Dec 2024 09:45:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D70AC6B0083 for ; Fri, 20 Dec 2024 09:45:27 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 514FCC0ADB for ; Fri, 20 Dec 2024 14:45:27 +0000 (UTC) X-FDA: 82915608258.20.831041A Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by imf20.hostedemail.com (Postfix) with ESMTP id C06AC1C000C for ; Fri, 20 Dec 2024 14:44:49 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=bY8asRoZ; spf=pass (imf20.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.47 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734705909; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=IMZAkqujM6Tmo2tiBp9aVM60cgfNl7Ir34Aswvp+9CQ=; b=qvw7FWYwBURcYErN7gNHNileeh29zvg6w3SHUw49MY6nD949EXkEhf7Qa6BMVpOrPRIkLS RT7iTQBTgK0/P9dW6GUr9paJHXsBVgcjEBP+L5Q7V6A/SDofG6ZSXWKQFZUPZpjfkShwnx SRpamDUjcbudaFrnkKuyZv66+uN7qUk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734705909; a=rsa-sha256; cv=none; b=QvwH6NxKhURDyopH87Ex2hsPGM3n5Ntewn0QaVd9f5MLmLhCkChpaROcQ9O1JAA2YeAKBb jzKF1jqGZKD6ClziepyYedW+Hh9jfawmhbEYWphR/yg/GB9Z8DeEMKGSmeRuLN6VBRzVSN YE3704cq8BwNqqlkzcWQglVn9REFwkw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=bY8asRoZ; spf=pass (imf20.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.47 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6dcc42b5e30so24566806d6.1 for ; Fri, 20 Dec 2024 06:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1734705924; x=1735310724; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IMZAkqujM6Tmo2tiBp9aVM60cgfNl7Ir34Aswvp+9CQ=; b=bY8asRoZ7SvZ9spMx9heW9ikzAFXULNi0hEf5AU0vIb3PCTlM7223Fs6YcmtIWfY6J YSHJGwXFR1YgESzQVu0sPalvPwXiyR0Z/egVIOIzRzEd7PBUQm3ZyoDfgABxekKiWXSf 6sQlYtEOLS5QjcKvlMZ2aPel71UcwqpGq/1kX6PnzQRA84+/C/G4Iw6QhzggLxHI1fxx F7zdtLv917hbNr0aCLj17ea1bdySXzKUUr0CCtYpdltdctZTqCKoInhrBiKwjLXzbGMB 6Pj7iiiwrAAtaemcLxJ1DbJH4AnnbHtvZXBQxRbS6V3PhD7oSso6FPivMLBU2ucXQOY6 O7oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705924; x=1735310724; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IMZAkqujM6Tmo2tiBp9aVM60cgfNl7Ir34Aswvp+9CQ=; b=mM4rUjid8kmQvr47fBsTrzYmSoyFLJ8baVvjl4NI1BPE7tum0MOIv4KtO2IOnTxDav mdXDgdMHLHSN4PlUybkciQ7NdFjgvheywCJ2mBs2mldgyhUmoDNUxFohVOtNoxuhMqgH FWQS0yJU2m7NI5X4L0vmgkidA3sfYNLDoK/Hpr9KM+e/t+N6SzyGlMWisMow2Jue9bB4 GMUNpje/5C6AAIurfomot7mgTQx+FQFfAnjd6ID/uayhImkVnRQnIh/Rrz+Wu4J3wsgq CKkKED8h4O0AowAFX+jaHaNckvyo3y8vdfGPa4CSgq0kvz4HBWIQ+ljF+6rcO2C8LrDa ACeg== X-Gm-Message-State: AOJu0YxN36jrmof9q6PBYwZQXdqhSCPaeVOU0rIaz8VuvPBzjPN4dG94 fQZdU+NBJx2tIJG2EFu8fj4kpdIAHxBHv69ZTOg5WyGCuoxmVyrD7DSQ6jVxCt1u1y4cyF2I+KU T X-Gm-Gg: ASbGncuR2JDD6KdFKHaKJYEDqwuFH7OfKMaqwOiHYEW3Wn9tdWs7YN5gdY4M+lfx8xY bYLhvzfNa5pUCj/ozFr08fNkUgAAxprivhBwwdAne52CHl6ivDnfFmTGP0QvFi3kTiV7Q4QUYyN TNoMYj+3qA0ka1+FnnQ8rGovAJfU2VgLlUpzsiuQFaIwEh1WBPAcLc8h6C1rvzpoxw0RL/zKtoB Bl1G+4LHFxtrwBExr+P7GalC3KSZK58PIG+I0yw0/6+zJy8jXzfvKeBe2J0NSzxblIgKBCldWho 9kodbbdlG93vat6K3vqEZrSaZSMBjO5IGRS4i0zACDtg X-Google-Smtp-Source: AGHT+IGMAMfYUvnrU987TuPpGf67dBtZnGtQjIvMTGI0ulFTq/udftZqv751Unovo7gkVthu1rUktw== X-Received: by 2002:ad4:5fc9:0:b0:6d8:a148:9ac1 with SMTP id 6a1803df08f44-6dd233aa32fmr49931076d6.47.1734705924192; Fri, 20 Dec 2024 06:45:24 -0800 (PST) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd181d3db8sm17410256d6.104.2024.12.20.06.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:45:23 -0800 (PST) From: Gregory Price 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 Message-ID: <20241220144518.206208-1-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C06AC1C000C X-Stat-Signature: cihkt19hcwzfy6mzi8r9kj131hrdwa5p X-Rspam-User: X-HE-Tag: 1734705889-475473 X-HE-Meta: U2FsdGVkX19gpT0t2QqjjFv0184DXSOSBuo4sB7KGQa/35RBAzvQHT2XfuuiPFq7C+DgDiPiG1e57O+VXt4kt64ZAlilXJulW5fV3Jmg0wKf7YbHtqhal1VrcaEJRPfmi0ARUAOlTK5i/DOwR39geKeELeyD6HtvVwpMoK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9LohEKYxQ4TQCZLN8+QnWNaoHgFYhRpa1RCkHvLf8vR/mF0GpU/yVpv6N9Juvu7FYgFGw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000014, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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;