From patchwork Mon Jan 13 17:44:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13937845 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 5F357C02184 for ; Mon, 13 Jan 2025 17:44:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E19DD6B0082; Mon, 13 Jan 2025 12:44:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC3D66B0083; Mon, 13 Jan 2025 12:44:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEF0B6B0085; Mon, 13 Jan 2025 12:44:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 94C906B0082 for ; Mon, 13 Jan 2025 12:44:54 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 31FAFACE4E for ; Mon, 13 Jan 2025 17:44:54 +0000 (UTC) X-FDA: 83003154108.26.3D96EC8 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf03.hostedemail.com (Postfix) with ESMTP id 40D0C2000A for ; Mon, 13 Jan 2025 17:44:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=WcFPD9+z; dmarc=none; spf=pass (imf03.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.180 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736790292; a=rsa-sha256; cv=none; b=SEDsjSbE+uaA/DfcEwxTsrgaDviNXNJKfqnnhgtCqcJ/tPEyCH+8DBQK2UFWGCJsCvz/Qw d2UgiHuIvjbwGAzV3B11PnSW2ZzuvsLgdSxshdCCtojJuiPzAPJxF47g/fL+il0GAEQ88Y 7rCfkMd3dS7VPWi6pqDGlpHD6lExCNY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=WcFPD9+z; dmarc=none; spf=pass (imf03.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.180 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=1736790292; 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:in-reply-to:references:references:dkim-signature; bh=5lYIOjwVOiyZSO9nrORqGYqQ+1pRAYOeyq4Co+ahKG0=; b=FwLQOykIT08Igyb/fI9VSvO6rb7GvZaKxpIj6NC35x3tqli2UqNurt0bPCl4JjG6C5srs6 NNmBbTrDVkxUCbkGRVB3ZrAv5qg1BBzwgCcSnBF5pAXCaiGoOuAXNJWgj5Zduqc3JB4YrA Ou3BXgoFdhb1MaEEnmlq7A8O6a0ibhQ= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7b702c3c021so407016985a.3 for ; Mon, 13 Jan 2025 09:44:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736790291; x=1737395091; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5lYIOjwVOiyZSO9nrORqGYqQ+1pRAYOeyq4Co+ahKG0=; b=WcFPD9+zEgK2MPN/uRF5h/Pc3OqYG0L5wMyMiT5jDQgPjfAshL0x1uuPzcgcht9raB RTFH9sDulacE/JFkNX77/BlhbCSXice4rPozO/Zd6xtEfNnP+qldY7bB+W8Z93K8HkZx b42CFLgj1DSBGS7MmgieLb0M9XDyAg1npM2Hu1lQrQT9ht0o7zK5Mz1uiN1HP5oBamWr PcYQTp4zRAe+OreDZ3ZOU1QcNlL5jMzUmWCLAXSzpu7f71lEux7tNG7gem3LrH3aCS5x K4/e/IOLNvqALZ8L8jRjfNwGQqodlJ1aRKY6eMmV47eYgP+ilOADiyGhH+6n2nQ7u87Y SEYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736790291; x=1737395091; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5lYIOjwVOiyZSO9nrORqGYqQ+1pRAYOeyq4Co+ahKG0=; b=agDb3FT/RCXyOjrIjwg4BJNRJFTv52f7XEzHv72Er7DFFxqT/lLj7gtV1RQ+/GjoK5 p+eQxWPqKM1K9ppr9b6pR6ty5kkjbnn3ldkYKCY1niEassKVwxyTcML1qwm5sQjEMpjQ M63X7d20s8flPZ9otcCG0ZegzCZNkugouYkviqe2hrg4wW4HVtimxbLXa+ZsHIKdfw8M JbXQ2bfYYhmcRcDWej+M/wzaJUGWzlyOSf0QRkgiVGbK8eHldxZo8xKQGRxWuC2x9tcM 0VfdfoLLVNAiIpeFsf9NuR/TnjklJVeAGn63uyqqa8GDz4dHWq1y89VGLgqvJetsnzCK 6Lhg== X-Gm-Message-State: AOJu0Yy+IGOFqp6ymwIbK0tu7QOAGGuUSoGqEUfoFCA1lRwtUfsWhdGP KV5bISr5oqKL4buYbtsKByfGx3ULRfIy5TRZUkW4rxppu0myNqMSZtqNUevQBGfguwtMC/DON3/ E X-Gm-Gg: ASbGnctIqVjXbfUsHVYhOgty6infpoVylR3JmbKHPBcZTyWeE0sPmTA40iCR+3Ly2Xo jYzc+Ddi/6yfCSPcjKbggnPWqmRx8cmRSM+X82huZv/krEbt6T8Ksx/icnGfa7p+3YgDhgYZtu+ CjAXTKkR9jYYmXRoHsUaXzjWiQGY1PzFKcFocZpS+FnAQyubXtBcfRqojuErITx8f0lmJBhwJzS gFpo7bOrZwIs1QfS8N7EhyfMiHszixCqLy+9Zyso/w7yoiBKot0Cx5O0l+jL56T28jfjGxVJUYM rlNM+4AnSqVXc8pbMvoSHQgo9GG4SvShuzC2Ram1gcS0 X-Google-Smtp-Source: AGHT+IGji/zdVSjj+QKuBorX8KRhL5U0vYxcdcXprimxamnxuQtc2su0NPyPj8UIhAzTvvuSrnfbyg== X-Received: by 2002:a05:620a:460f:b0:7b1:1d91:5d06 with SMTP id af79cd13be357-7bcd9759e0amr3397038585a.46.1736790290892; Mon, 13 Jan 2025 09:44:50 -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 af79cd13be357-7bce3248c80sm511214185a.49.2025.01.13.09.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 09:44:50 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org, linux-acpi@vger.kernel.org Cc: kernel-team@meta.com, x86@kernel.org, linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, dan.j.williams@intel.com, Jonathan.Cameron@huawei.com, alison.schofield@intel.com, rrichter@amd.com, rppt@kernel.org, gourry@gourry.net, bfaccini@nvidia.com, haibo1.xu@intel.com, dave.jiang@intel.com, Ira Weiny , Fan Ni Subject: [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size Date: Mon, 13 Jan 2025 12:44:37 -0500 Message-ID: <20250113174439.1965168-2-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113174439.1965168-1-gourry@gourry.net> References: <20250113174439.1965168-1-gourry@gourry.net> MIME-Version: 1.0 X-Stat-Signature: ko6471xic3mb6xr8bcau5hbyrt1xhaeb X-Rspam-User: X-Rspamd-Queue-Id: 40D0C2000A X-Rspamd-Server: rspam08 X-HE-Tag: 1736790292-419417 X-HE-Meta: U2FsdGVkX18dQXXNGQiUR7btBkeE5+YbHYmiDW89f6V/foVOz9gTVwjmgxyrol9rWVIbYg2Xh9WMY0kY3y6y2ld9BqLwulVTl6iR9YFcDvUQgj7+2sYLNErZXp1uRA870QcI1cJtHfQdddikZlq43GsPi8pMZnfO4HUlEnjs3jaNNPSPCwOpnxDgYfYmDfRh3DJyZx3nSYw87JFnJyvX9dL8dcEa3OLxQeWlPlrM2bOHVsmpnMHCgZTqlo2M0mmvirO0POEyGLgvFcfLRi7G/YKywlNqzVDklCaOoCv7sUiqAmjE4h6ZFhH0AOFJG9X80dHDt2wzppDbhHuT7orvPba4aXdFVKOQ7EFE0FkKJw/a72y9mK5aOJnfEWgV5ZuVFbDnwZaDla/o1QuixjtTAdPHWc3RGM6HjoqqgiLbaBpIFx1H8hoB+60Eq138QkfOXz+oStjYvgnwQvmB4OXot6OByoWE3GjK1aSIklu7lBaWDpep9zBECK4QM67Qmufjhkqe8qXvjZ+I1xVwKSPCL62sOYLc2BgdsPS9BKwEV8VMlh1YU0z56QmCMORJjR7d9fj1Fc7gdig4VUSmhmud/T7w7kWTcXQL1mtXH3yfBZH59hCz3CpGUmEtggRLBMJJauBvKVAhe03oBnHods4tk+yMRvW7hQMHxJox40DHwjBCj4H9I2t7WAWOD94XYDf4ZYl51hLBQ9y+VZhhrcziTTimhGR6hsB6LSaYXLpzENwpyOt014al5kYLO9+3YdXDZlZ1IH9n7XVldPFcEZelO/zINcBXbKTn2UVbrz5oFGuzUCoB0E5TTW5ygFqUEWfr0D/g4vQqSLgbewEh9EdAyNq9WG2NtZkFsma1wtQhcroAiF3pSYkl3J5IBzP8+TyCpC9EEzG+gMLx9Iysn4z3F6h+RXhVINVjHCV+VVlRnz6wOgkA26yovWanNS5N7O7iHyOM1S8wehND0R0UX9y Mr5tJyiq tbwhsahUEwCWsItNPwcmOsiA08DktmwIc1BWm5cSzPNTy+dBWRilMxwem2CNflO3OaUto3WLRnkIWFfsIuh5w+yFWgMKiA0ZNfgc9rQGBOpAlJGXbPMIB9uHN9FbETl6li6TuuJm+gZAw8T2mTNpV/D8QtwXHK7j266zllIfk8n1hhR9hH8H6Tcyo8CAkPuKZ1Xk/YOETSuWMm2Vtc1iiApfmJ1oodjuLctb/sJVQg89taUpZu2pQID+jcIKT0qJMpmoyFinFFstkR7kNaoZlW058mX0JmO1I1t4SSK6H5yLaNOUZ17shuUx7qlTXLFt3yvyvI9/8HwRaOIGIQaXfxBVQ7njTc2xwe4jlb1BlsUiCaH1ss3SmjtfQGcdxjURUBY/64uMuXD7sTaYeVn0SKiVGAeDnmd7CSHt0eisScTTeMC9rn47vT8RKXWRjgFA8hWdV 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: Hotplug memory sources may have opinions on what the memblock size should be - usually for alignment purposes. For example, CXL memory extents can be 256MB with a matching alignment. If this size/alignment is smaller than the block size, it can result in stranded capacity. Implement memory_block_advise_max_size for use prior to allocator init, for software to advise the system on the max block size. Implement memory_block_probe_max_size for use by arch init code to calculate the best block size. Use of advice is architecture defined. The probe value can never change after first probe. Calls to advise after probe will return -EBUSY to aid debugging. On systems without hotplug, always return -ENODEV and 0 respectively. Suggested-by: Ira Weiny Signed-off-by: Gregory Price Acked-by: David Hildenbrand Acked-by: Mike Rapoport (Microsoft) Acked-by: Dan Williams Tested-by: Fan Ni Reviewed-by: Ira Weiny --- drivers/base/memory.c | 53 ++++++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 10 ++++++++ 2 files changed, 63 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 348c5dbbfa68..e59378ec5b00 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -110,6 +110,59 @@ static void memory_block_release(struct device *dev) kfree(mem); } + +/* Max block size to be set by memory_block_advise_max_size */ +static unsigned long memory_block_advised_size; +static bool memory_block_advised_size_queried; + +/** + * memory_block_advise_max_size() - advise memory hotplug on the max suggested + * block size, usually for alignment. + * @size: suggestion for maximum block size. must be aligned on power of 2. + * + * Early boot software (pre-allocator init) may advise archs on the max block + * size. This value can only decrease after initialization, as the intent is + * to identify the largest supported alignment for all sources. + * + * Use of this value is arch-defined, as is min/max block size. + * + * Return: 0 on success + * -EINVAL if size is 0 or not pow2 aligned + * -EBUSY if value has already been probed + */ +int __init memory_block_advise_max_size(unsigned long size) +{ + if (!size || !is_power_of_2(size)) + return -EINVAL; + + if (memory_block_advised_size_queried) + return -EBUSY; + + if (memory_block_advised_size) { + memory_block_advised_size = min(memory_block_advised_size, + size); + } else { + memory_block_advised_size = size; + } + + return 0; +} + +/** + * memory_block_advised_max_size() - query advised max hotplug block size. + * + * After the first call, the value can never change. Callers looking for the + * actual block size should use memory_block_size_bytes. This interface is + * intended for use by arch-init when initializing the hotplug block size. + * + * Return: advised size in bytes, or 0 if never set. + */ +unsigned long memory_block_advised_max_size(void) +{ + memory_block_advised_size_queried = true; + return memory_block_advised_size; +} + unsigned long __weak memory_block_size_bytes(void) { return MIN_MEMORY_BLOCK_SIZE; diff --git a/include/linux/memory.h b/include/linux/memory.h index c0afee5d126e..8202d0efbf46 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -149,6 +149,14 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri) { return 0; } +static inline int memory_block_advise_max_size(unsigned long size) +{ + return -ENODEV; +} +static inline unsigned long memory_block_advised_max_size(void) +{ + return 0; +} #else /* CONFIG_MEMORY_HOTPLUG */ extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); @@ -181,6 +189,8 @@ int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func, void memory_block_add_nid(struct memory_block *mem, int nid, enum meminit_context context); #endif /* CONFIG_NUMA */ +int memory_block_advise_max_size(unsigned long size); +unsigned long memory_block_advised_max_size(void); #endif /* CONFIG_MEMORY_HOTPLUG */ /*