From patchwork Thu Dec 26 18:29: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: 13921418 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 8C26FE77188 for ; Thu, 26 Dec 2024 18:29:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00C2F6B009A; Thu, 26 Dec 2024 13:29:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EFD7F6B009C; Thu, 26 Dec 2024 13:29:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC5946B009F; Thu, 26 Dec 2024 13:29:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BF2216B009A for ; Thu, 26 Dec 2024 13:29:42 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38641B05E2 for ; Thu, 26 Dec 2024 18:29:42 +0000 (UTC) X-FDA: 82937947344.26.D970590 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by imf25.hostedemail.com (Postfix) with ESMTP id 54C93A0010 for ; Thu, 26 Dec 2024 18:29:10 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=nhWPYZIQ; spf=pass (imf25.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.52 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=1735237761; 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=ulc8YI8Od+RVUqdmJbEp8bNR29/8W69RWWEZTKBLmks=; b=UmAVfC4N/rXy7atZ/F6p/28LFSukeU504Q2PK/GDhQbAGlAqXjnEy2rWvuYEBS/2dX9kmJ y/+NnWg2vRLrX7TC59v3RoW2WZSWzyMQg+ieAmnwdQkNgq3Gve79yFUgPLTj+6rn0Nco88 Tn5nHIPuZalcmCp0DUfJ7WNUsWzlU8s= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=nhWPYZIQ; spf=pass (imf25.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.52 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735237761; a=rsa-sha256; cv=none; b=yn8mRCgKqqsUjwQwm1aoSlCH4FEJAzJyM3qt3Azwh1efGQAEgU4t9IjlzUQKYpM5oXmvmq Lx6IYOAqQ8OLgGjb7QRIwVwuNs91K8PfWBK1ReT7vlu5fT83jpzxOC7IK1KqnjVkfc4W7g uwdKAgUcc1+zaLsiE+2v7Bxmac0bNUs= Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d8f916b40bso91129236d6.3 for ; Thu, 26 Dec 2024 10:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1735237779; x=1735842579; 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=ulc8YI8Od+RVUqdmJbEp8bNR29/8W69RWWEZTKBLmks=; b=nhWPYZIQ/PjFRsvu282Vlauk+YSUYrrsa645lL+2GV6TgVpG33PlmbF83THzpZHvL5 FjDd9+f03a8r4dCj3hFT3yPV8Lhqi7Ys+RS58ttu4/zxNQxOwGlaZivnNs+zfq/4C/h9 JvUDoPIHe1pU3T2JYZAZbqtJV5pfTqilTClns+y7+oSZNhBrx7bxMQ+g9qZdUenbhwCn omR8QNCf7TDImCwosGx90lxiLwsyXIIkSXhD0SDNAhaCVjNGQXxt64EPl3o9Rzqht9bd PRt1n37u0uPD4bZQlrNRlk/lhMW4kgjYMkaAto4U5Ni0mqFspyjocLwM2HLyHRiuOR3/ KS0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735237779; x=1735842579; 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=ulc8YI8Od+RVUqdmJbEp8bNR29/8W69RWWEZTKBLmks=; b=Mn9Z79n6Ej/Q7aNi2+QBk47Nq+oNtFVdGLZKIuH0te/PZqNTzz3aWkGFm/uCVg6f/u LPujNFxkDs75bFLTuJRXJMPe7CztSQLS219SBdQyL/cccrrv3ln24Q7pUpv0YRumQCn9 gw4JbJwLcsBV7Z4UmAWA6sN+hS0ng7/f/9SxcaTPCvCc15tzrW1XbmcdmkSNPvfHL1Ml i3un9IUyOdLZ+hhgRVseIkqUjx09VMIB6VJqfW/kCh2AspV3mmnY8PZB1IeHXHuoCKSE riewPx64dScmttH8/cAQf3m3wJD/ABXsV4UKwVPrT/pfVdlH0omwGHfntRNc4ZgUb+aE S72Q== X-Gm-Message-State: AOJu0YwUIA7bP+1FsNVq0ooBL5uYFZVKdMqf+HDo65rKmHpPhm4WNsrP dSH0tvKGWwMD3a3WsYXaV6Gqv7wxGFnPHtrOJTz1OxaAc1WNqKzAdmxoKzIpGL/QAJsGSKzkPyr aakk= X-Gm-Gg: ASbGnctt0Svh6o82Hm1+1ZmBMF061UwHOUDIsmpRGcA2pvSieXgcZXI+yNA62T4SuRG nDXtrQQnyPfoPGU8PBWjKxLJLiwIk7rhZ45AT7KK1geAY1f4Y/j1SDYRm0v/VTa0uk4LP12T7MW XnIqYrPnJ1As7AtT/nL2LZEFADPKQrkOARUOBPdjBs8k7bGlJ/B3lYIr4C6m0CDVM7nwiODDfjW mK9+Jedwg+HGxcJDW+C/oHhCmeZMD3RWwh7C6bmIxUsa49Y2ynVVb2evVkCrbY= X-Google-Smtp-Source: AGHT+IGunNgWGzawZSRYp426fRZ4HyEUdARE5RrkmmyWVpaqiWqMPRG0VVdcHlqGkSu5TnJeGImAmg== X-Received: by 2002:a05:6214:250c:b0:6d8:8e0f:8c03 with SMTP id 6a1803df08f44-6dd2333737emr432315856d6.18.1735237779001; Thu, 26 Dec 2024 10:29:39 -0800 (PST) Received: from localhost.localdomain ([184.169.45.4]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd181d52c2sm71619526d6.113.2024.12.26.10.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2024 10:29:38 -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, akpm@linux-foundation.org Subject: [PATCH v4] mm: add build-time option for hotplug memory default online type Date: Thu, 26 Dec 2024 11:29:18 -0700 Message-ID: <20241226182918.648799-1-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 54C93A0010 X-Stat-Signature: 1j7h9dask8j8emr5fa7e18p3446y5w44 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1735237750-621176 X-HE-Meta: U2FsdGVkX1+x96/JpE4JWe/ZRYtd70ST5DHPaNLR0jDK4NLXTdhadYfPUwSdZey16VQXvdwauU91ioTKBut4N3o/5Du6g8KaUtl5dgol9i/LsuTnteL3KCOE6W8EX+i+i9rkiLPX89pB+yycLNmr8HehSZxoXAWaovIQqM5wyLV3fYBDKPJNF2XFX1TmItEbMdj4FJuNl0DoN30TndoolEUypw2Q3IZzd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2exYsRtBwKzCy+lwRges= 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: v4: updated KConfig comments 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..1b501db06417 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 hotplugged 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 + Hotplugged 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 + hotplugged memory into the zone it thinks is reasonable. + This memory may be utilized for kernel data. + +config MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL + bool "kernel" + help + Select this if you want the kernel to automatically online + hotplugged memory into a zone capable of being used for kernel + data. 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. + + 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;