From patchwork Fri Dec 20 21:07:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13917391 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 1D5B5E77188 for ; Fri, 20 Dec 2024 21:07:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 899AA6B007B; Fri, 20 Dec 2024 16:07:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 849716B0082; Fri, 20 Dec 2024 16:07:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E9CF6B0083; Fri, 20 Dec 2024 16:07:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 508676B007B for ; Fri, 20 Dec 2024 16:07:16 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CAC5FC0D75 for ; Fri, 20 Dec 2024 21:07:15 +0000 (UTC) X-FDA: 82916570394.17.836E6DB Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf08.hostedemail.com (Postfix) with ESMTP id CB38C160013 for ; Fri, 20 Dec 2024 21:06:50 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=gPB9N+xa; dmarc=none; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.173 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734728801; a=rsa-sha256; cv=none; b=deJejUSULAUwQyESeiPNlmjirw9xdiUY34bG5mKUvuYaLxyaiWUOlp6l3N36CQnnvHpnpQ J5V/MGJ0xXTNZTk03+4BcgpdH1YEKyzSsBuOM4Qk7kJzlztK8HbmfsA8PZBe/31aICGKGx rDm2tU2JDpXxPwETx9z6Hc/9zF7oDyo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=gPB9N+xa; dmarc=none; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.173 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734728801; 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=FBnwh1px/ppyY9TXnXI5D+rrc/T3rbUUoO/nhganj2U=; b=cBTfs7oncqNMR8U8PsPYnZeHPNU8C+Hisq757UYjtD0tlW1mphmfxSfl0oWZ2d/7EMNmWu 1aQMVn9N5op2epOuDPsu8WX0zYopAObwwUMGP/0STSARrFuJIfvB84l5lbeZ+ESEIisesl g9bt8ARQer9xyLRIgGrPiVQXWN/1iBE= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-46785fbb949so24036931cf.3 for ; Fri, 20 Dec 2024 13:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1734728833; x=1735333633; 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=FBnwh1px/ppyY9TXnXI5D+rrc/T3rbUUoO/nhganj2U=; b=gPB9N+xaT/BG8uZyMGwi1+EcY06LlRafRHLWCrr7AzyCsvdpHZ7dknMjIyUIIWcnHg 81IIvG0trfjJVlkGpW+5l/c9pT7R8zWgJWA12rp6+I0fUzZqKJWCGtfHC6LVXSdJChMi zcIs5KZCCxxUX+kAECwgoFJScI8yg7C4gm/JSsS70kfw/oqMXkj7Icc704KFutN8wnUN bZqfNMMVpaXNgNTlXS7ebzpwkpzh5HXrzEVnsE767N2qCGJrZEt2VtafxrQZSpBHfwYg k5ZWTude1uBnjSTj0x3+Q5jtixDeIQCJUwQNavgBre8mInDrETb0FMVNqaObc4IUm1wM +QSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734728833; x=1735333633; 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=FBnwh1px/ppyY9TXnXI5D+rrc/T3rbUUoO/nhganj2U=; b=n2FoVu8UiLD8UsZ9twMrY8coWGZdtTI0LY36AlkxsD6dhST8CLHbf53lsKnjs1iMt5 ZdnANi6x20LKGnzNgy+2Ed2K4mTQ4mnPl1mukcRpb4KVB/04uW1Dsb4nIb8+kuILRimI yx+Kug7/71o3T2xTSqcS7k5IWeNTDiIMtauCsp3r2R9FLrUb89AIMsEM/x24Wp7zIjSD eLjEZDXzJlRz8TYUraTO2zwrX3fOLEcrz2OG3WydTORv+Rf4cIOiQZVktfFAlcQdzaxZ wJAholtSscLg0BMuz+gz1DkqWmrwGyZpzt0h0D8Ow4ghtqSsIq/iHawrAJ+vy0YkDnxE idKQ== X-Gm-Message-State: AOJu0YxqY2TVnc8mYvhEVrwM6z7/kwJAD32M+WLvEFefRg9+UGHJWcJ6 PnmoJgAJfagzqPwHTiGa0EcsBQ0FbcC+0W8VazprXAALZ+egdkNOWpamUf5GBlOGdyYSiux86O3 8 X-Gm-Gg: ASbGnctRL/2nAfVJ71fnkpPW+Kx0KKoKZKNWvg19ndxM55xnfpgSGftAwY5Ptax+hLZ PiTaC5ugqrqSxmsvHHCT0xKFZAUkyJ0RF8C6p7G3Ak4VGeXMxX/3PLkhbi6uz+SDejmqkrUFUfB BmXtrVp1zJ6hXjnYv17XLMQkYDwhaEfY7TbG9RzFNDUWepr6MIrt39KR6/iwd3gEs8hCK7Hts43 qPrA2zoBQOwOwKClh3RcW0u7fJ69uyKHYTT7/lbKOtaOYZ+PDqbZNL2fZTqM+qJ0A7+ej5prF2T 4aIkLjaIyxyCKfEj8SIhozTrDB/A27u/eFI19xcQk6cD X-Google-Smtp-Source: AGHT+IE0fytysCaD+QZqQMNx4pmUQoDDsSg7GEVZ/PqcYQhdzeLx+0aGMZuHIAdln0YzE4SsS6toFw== X-Received: by 2002:a05:622a:cf:b0:467:b649:6a46 with SMTP id d75a77b69052e-46a4a96c043mr73079801cf.42.1734728832666; Fri, 20 Dec 2024 13:07:12 -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 d75a77b69052e-46a3e653f2dsm20403971cf.4.2024.12.20.13.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 13:07:12 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, kernel-team@meta.com, corbet@lwn.net, david@redhat.com, osalvador@suse.de, akpm@linux-foundation.org, chenhuacai@kernel.org, kernel@xen0n.name, gregkh@linuxfoundation.org, rafael@kernel.org Subject: [PATCH v3] mm: add build-time option for hotplug memory default online type Date: Fri, 20 Dec 2024 16:07:09 -0500 Message-ID: <20241220210709.300066-1-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Stat-Signature: 6a7745xiesucfg3s5eh65xfkb4o3ao6s X-Rspam-User: X-Rspamd-Queue-Id: CB38C160013 X-Rspamd-Server: rspam08 X-HE-Tag: 1734728810-192223 X-HE-Meta: U2FsdGVkX19dXn6kNSv25PbAZ7FaLQzDPj1baF96K1W7wtLBp0TF3V+97+x1+wa2lgH5Zh/gm5Hysy+aj8Fp/DAx5KL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aZ3C6Pa7R9x831Uc5xebtOolQAUiPzduX69kNFVxsXANHtBYCNn4lVq6THCwVEHeciIdMm+4Mf5RTM2AulwhaTBEFnmlGIAs2dzVSlGOOxnQnlvn407t1ZJCWcGg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Signed-off-by: Gregory Price Acked-by: David Hildenbrand --- .../admin-guide/kernel-parameters.txt | 4 +- .../admin-guide/mm/memory-hotplug.rst | 4 +- arch/loongarch/configs/loongson3_defconfig | 5 +- drivers/base/memory.c | 4 +- include/linux/memory_hotplug.h | 5 +- mm/Kconfig | 57 ++++++++++++++++--- mm/memory_hotplug.c | 33 ++++++++--- 7 files changed, 89 insertions(+), 23 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index c79691eee54f..9138fcd18260 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3351,8 +3351,8 @@ [KNL] Set the initial state for the memory hotplug onlining policy. If not specified, the default value is set according to the - CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE kernel config - option. + CONFIG_MHP_DEFAULT_ONLINE_TYPE kernel config + options. See Documentation/admin-guide/mm/memory-hotplug.rst. memmap=exactmap [KNL,X86,EARLY] Enable setting of an exact diff --git a/Documentation/admin-guide/mm/memory-hotplug.rst b/Documentation/admin-guide/mm/memory-hotplug.rst index cb2c080f400c..33c886f3d198 100644 --- a/Documentation/admin-guide/mm/memory-hotplug.rst +++ b/Documentation/admin-guide/mm/memory-hotplug.rst @@ -280,8 +280,8 @@ The following files are currently defined: blocks; configure auto-onlining. The default value depends on the - CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE kernel configuration - option. + CONFIG_MHP_DEFAULT_ONLINE_TYPE kernel configuration + options. See the ``state`` property of memory blocks for details. ``block_size_bytes`` read-only: the size in bytes of a memory block. diff --git a/arch/loongarch/configs/loongson3_defconfig b/arch/loongarch/configs/loongson3_defconfig index 4dffc90192f7..1cc6e8843680 100644 --- a/arch/loongarch/configs/loongson3_defconfig +++ b/arch/loongarch/configs/loongson3_defconfig @@ -113,7 +113,10 @@ CONFIG_ZBUD=y CONFIG_ZSMALLOC=m # CONFIG_COMPAT_BRK is not set CONFIG_MEMORY_HOTPLUG=y -CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y +# CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE is not set +CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO=y +# CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL is not set +# CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE is not set CONFIG_MEMORY_HOTREMOVE=y CONFIG_KSM=y CONFIG_TRANSPARENT_HUGEPAGE=y diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 67858eeb92ed..348c5dbbfa68 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[mhp_get_default_online_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; + mhp_set_default_online_type(online_type); return count; } diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index b27ddce5d324..eaac5ae8c05c 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 mhp_get_default_online_type(void); +extern void mhp_set_default_online_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..af163dbbaab1 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -550,20 +550,63 @@ menuconfig MEMORY_HOTPLUG if MEMORY_HOTPLUG -config MEMORY_HOTPLUG_DEFAULT_ONLINE - bool "Online the newly added memory blocks by default" - depends on MEMORY_HOTPLUG +choice + prompt "Memory Hotplug Default Online Type" + default MHP_DEFAULT_ONLINE_TYPE_OFFLINE help + Default memory type for driver managed hotplug memory. + This option sets the default policy setting for memory hotplug onlining policy (/sys/devices/system/memory/auto_online_blocks) which determines what happens to newly added memory regions. Policy setting can always be changed at runtime. + + The default is 'offline'. + + Select offline to defer onlining to drivers and user policy. + Select auto to let the kernel choose what zones to utilize. + Select online_kernel to generally allow kernel usage of this memory. + Select online_movable to generally disallow kernel usage of this memory. + + Example kernel usage would be page structs and page tables. + See Documentation/admin-guide/mm/memory-hotplug.rst for more information. - Say Y here if you want all hot-plugged memory blocks to appear in - 'online' state by default. - Say N here if you want the default policy to keep all hot-plugged - memory blocks in 'offline' state. +config MHP_DEFAULT_ONLINE_TYPE_OFFLINE + bool "offline" + help + Driver managed memory will not be onlined by default. + Choose this for systems with drivers and user policy that + handle onlining of hotplug memory policy. + +config MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO + bool "auto" + help + Select this if you want the kernel to automatically online + memory into the zone it thinks is reasonable. This memory + may be utilized for kernel data (e.g. page tables). + +config MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL + bool "kernel" + help + Select this if you want the kernel to automatically online + hotplug memory into a zone capable of being used for kernel + data (e.g. page tables). This typically means ZONE_NORMAL. + +config MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE + bool "movable" + help + Select this if you want the kernel to automatically online + hotplug memory into ZONE_MOVABLE. This memory will generally + not be utilized for kernel data (e.g. page tables). + + This should only be used when the admin knows sufficient + ZONE_NORMAL memory is available to describe hotplug memory, + otherwise hotplug memory may fail to online. For example, + sufficient kernel-capable memory (ZONE_NORMAL) must be + available to allocate page structs to describe ZONE_MOVABLE. + +endchoice config MEMORY_HOTREMOVE bool "Allow for memory hot remove" diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 3b6f93962481..e3655f07dd6e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -219,11 +219,30 @@ 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 mhp_get_default_online_type(void) +{ + if (mhp_default_online_type >= 0) + return mhp_default_online_type; + + if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE)) + mhp_default_online_type = MMOP_OFFLINE; + else if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO)) + mhp_default_online_type = MMOP_ONLINE; + else if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL)) + mhp_default_online_type = MMOP_ONLINE_KERNEL; + else if (IS_ENABLED(CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE)) + mhp_default_online_type = MMOP_ONLINE_MOVABLE; + else + mhp_default_online_type = MMOP_OFFLINE; + + return mhp_default_online_type; +} + +void mhp_set_default_online_type(int online_type) +{ + mhp_default_online_type = online_type; +} static int __init setup_memhp_default_state(char *str) { @@ -1328,7 +1347,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 = mhp_get_default_online_type(); return device_online(&mem->dev); } @@ -1575,7 +1594,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 (mhp_get_default_online_type() != MMOP_OFFLINE) walk_memory_blocks(start, size, NULL, online_memory_block); return ret;