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 */ /* From patchwork Mon Jan 13 17:44:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13937846 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 601B8C02180 for ; Mon, 13 Jan 2025 17:44:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BAF06B0083; Mon, 13 Jan 2025 12:44:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 143876B0088; Mon, 13 Jan 2025 12:44:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED4B96B0089; Mon, 13 Jan 2025 12:44:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BF5F46B0083 for ; Mon, 13 Jan 2025 12:44:55 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6B260A016F for ; Mon, 13 Jan 2025 17:44:55 +0000 (UTC) X-FDA: 83003154150.05.6C2F38E Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf10.hostedemail.com (Postfix) with ESMTP id 91259C0018 for ; Mon, 13 Jan 2025 17:44:53 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=jaMSx2Ih; spf=pass (imf10.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.172 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=1736790293; 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=xZSM7cd0rzVSNSrAghH4+54a5vGC27L1Y4nGLMrRkSY=; b=oRGbX4RIneWUC+WGq7LX2BXgNgV4l5H2y7bjet8IWFM0b6XuQoo6Y9qTQh7NhRW0Bx3lNg SxunB+bVZLhlLMKFBjU66wF5UOsiHwGZpJBTez4J3ymtMxodpMWn2ol6sL5+4Ow2REKojp h9xkW27QzHMZpXhftPnrBFkv7id/eWE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736790293; a=rsa-sha256; cv=none; b=B+/oR/ycAaCLId9/DA/KX+ruhMrvGfla5bUoJPJaZ+d7INeZ4m8bdbDslQA6FXq/ahzHAg Xi0Wsc9gxt0QwDKZSXaV+2gxI7TewqVj1SNvAdm/VqLdsd7MM/mKqJcPk7oNHM6+ft3JDa hz1uUTtb9fEIw/ieHCuZlbwkVqrjNng= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=jaMSx2Ih; spf=pass (imf10.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.172 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b6eb531e13so253019085a.0 for ; Mon, 13 Jan 2025 09:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736790292; x=1737395092; 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=xZSM7cd0rzVSNSrAghH4+54a5vGC27L1Y4nGLMrRkSY=; b=jaMSx2IhvQfnSXX817Z5DpvLnKWVqrweTUqbIkSAwqF6mVu+5t3x6Qh+yRTrd6xCaL U0p0wH1AJ6LCZ6hei8sOyYbvQEBZ+eFHKLBBX6aDIR03WAsQX1HR1CQUXhgkXizO6JD8 0IIy+MjSOwDmNvWwM4SEZTfzpfMlBxw9YliDl97AerJwulVdYvA+owH62k4obDBiJCip sPcYj9M+NMfMFVUQ6wlx9/g9DvuiFZro7f5gK+G3ayBpjrQ4DN8RUrjaar7dpWZjy11w 1Nrq2QK33Ujncb8WmBkf2mNSnzrMia/iJcd3epb6zU4wsW5n0BlOIt19S3dfVhdlVOv8 KFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736790292; x=1737395092; 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=xZSM7cd0rzVSNSrAghH4+54a5vGC27L1Y4nGLMrRkSY=; b=oz+v8YNdDXWel6agPupv2M/blUPBScGluml3w7d+nk8AXEVP7DBa2bIjtwNRCcTB5C XFVU+UJ6S/+2cstdh4qEI3VsqEFhBcQoz4bQiv6y9L+8JjjxP3THXFI6CrQStw78VI8T RPVFweoge11aXBKjFdKqWbrA2nFUnIHsaEZ6Lt94Mil3OMXJtnN34UrWcqDNcVbet8ea 1Ig5/iQ+uVTy220yJN+KveCryNEx6cIIr8UHz6IPKoNgX3DnDgNmin8oEOFe6mPeleaA WMvEJfImy3qeFrMwzzuUnIu5YFF5x5CQwUdurB1brfHD9ABm7EMhK3z3pDMw99iVPxts B4pA== X-Gm-Message-State: AOJu0YxuaeMRKp9xwsd1u+TN98zeotveulbM/CPqiwEMlPIqXY3uGdjg 0SoHni1XhyWTbwkMYHbIBarlbT3Z8xRFM1AQywmObA/tfoQ4c3RmpzACNX5RPeYzkxFly7D3tgo 4 X-Gm-Gg: ASbGncudSD04kAogobJG+p9ZenanXvSTZpyUGqtSZZ3YdD8nQjcqF8QbbvsQdwh5WUP XgeutgemrAq1QyOxuhbdyUfv3Clu8fUbrGgvOc+eQVSS4CBzZeacjruma743YlSSoufUCrW9ds/ rP12c62IkwHCHxtvSZpueBImlcLBlbeyxCy5bmGLNKnhp84KflWKi1To+Ch1DXWlNFTMgt8aLqJ vDphqB5PY+XWi8zn7wAhbLBMs9dw6CPgYcTCPHuS2jimngn71IwEzabl7DQ392PI9qFyO1BO73f IQxKdCkvlRlX+505TDlU2nrh/yu+rHVibpeSUo9YXSEh X-Google-Smtp-Source: AGHT+IF+IF6Rv5no47DpWYrkZUPK0sDnR8tgi7nlXfUyokU9C1+7BbgLKk1J4eOLXpCwFls4u2oImw== X-Received: by 2002:a05:620a:2697:b0:7b7:24b:dc58 with SMTP id af79cd13be357-7bcd97627d1mr3005432485a.43.1736790292471; Mon, 13 Jan 2025 09:44:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 09:44:52 -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, Fan Ni Subject: [RESEND v7 2/3] x86: probe memory block size advisement value during mm init Date: Mon, 13 Jan 2025 12:44:38 -0500 Message-ID: <20250113174439.1965168-3-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-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 91259C0018 X-Stat-Signature: qb4paaot4eok97wxmp6dynecuzzjdyh9 X-Rspam-User: X-HE-Tag: 1736790293-510977 X-HE-Meta: U2FsdGVkX19oqNRcnJUTZnvg7OJdH04Nd+KRYrKEnCMf2mW6QqHdmwrzWdT87BAmnOtwH2prAFc+TFl0fzGL4UkqdEv1TVtWm2oeU/xrshchpu7zASD4XHv5LF2g2vTBEgH1+/VjhBP/bSwUaBzEkH1sS/cHbT5CbuQvy39sMi8KQL4mwphuAScZhdHeMZIU55W0fZtAbxWhW3J9lvek4J1Netx3u0iH6gv/TbfKBcksFuvrLvJEsZLkjsXUpR41rwMi05ME3TqIM5qAEWxvEprUOnSw66IedX7gPWDbJAbZMs+7DqURqRI4UaMuZBUY+zMf8qLFgWT4pvLvzlRG59KWGZ66gXy+zfhqPNgRfNy90W4Buukq/sg+VtSKPTCdExaFF6jBv6OcMrWdv8DqdHnw7GJMmT8aompVJiAoYsx/BR6mbdVJG59Fj3YvWOqQV4nnsWgCJc8zotcNCIajPwz55Cuo8G4jvq1FPyik6OX9EWZzY/vXbH1AtepG9gjyFDa5NznG0TjtrItpqmUX2Qiq2UrPlKTzp9FOU9B4oGTf/oUhQpYYYBSWP8TbAkO5AalohAFlK9og8s4dKP8Vs6luTiR2Raf9To0GBVSigNYOHTQFM4fowsYBICH9RShFt2TtbQ7Vr0fCMx1n+SVCM0Fp0f40GDLaFZR/P0I+6j7lx+Uu8KWWVaeyI2iHLeurRMgeKQWvA61HQziE7MgU4SdZV5aHAhrGEPBnC356EkccU9MgMpBmbxtCExwQOTwApSAevTrF6xX77maclHH7Qic8h3TAD2sC/UU6JJ8EAzxw/l7tCA1Z5qPPRBP2qNjNzTdMMNF7QB1F2dD1DFEEQaLq+ipt3zZzAtqLfgZtlS5nDzXwLcSIyrxMkX1+q+ZllFmluABKyu02S7LFQ03bYYVbtsrp6yST/OirET+ovKRhl6HXsz5ZPB99XKv+mX+q+RQWm0GUFb4ljm67x5C B6vBZsbT wXE7iiEqqCuZs9fvdSBVa0lp89+m8jiHUP6GD1kI0RNkLiN8vGbzNhMMOXS0SyTOJAU1heO9hvIcpO2cv8UvzSV15YxEzBv3NXoDg1gGg2CpjAAvUWjddq8G2ykICcGIPlLJGf8bLqozWZwKBn13cHEIo2AqFRqDC++Bjs5w7DVdssnX+HhFOKg7JfBJ+UFewAdbiENSquoa3AIUxqZJXhAnImxgOQAukpV8TntY9DhN0a3JCAg32ANkyihB+2IBxvyxsGl6p1bn5bb0lNiV/esdDdSWM4+W5CAgRjC4EQeWrPfKptGvhXZI8CrFq9nEUVOi7vUwDs641D747oeB7YH6o15H8s19trbbuN7obP0SqnQITL4FCg83vTq5CPwlnPSHbdPELEEd9cH7BwvL3vSAiOQ== 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: Systems with hotplug may provide an advisement value on what the memblock size should be. Probe this value when the rest of the configuration values are considered. The new heuristic is as follows 1) set_memory_block_size_order value if already set (cmdline param) 2) minimum block size if memory is less than large block limit 3) if no hotplug advice: Max block size if system is bare-metal, otherwise use end of memory alignment. 4) if hotplug advice: lesser of advice and end of memory alignment. Convert to cpu_feature_enabled() while at it.[1] [1] https://lore.kernel.org/all/20241031103401.GBZyNdGQ-ZyXKyzC_z@fat_crate.local/ Suggested-by: Borislav Petkov Suggested-by: David Hildenbrand Signed-off-by: Gregory Price Acked-by: David Hildenbrand Acked-by: Dave Hansen Acked-by: Mike Rapoport (Microsoft) Acked-by: Dan Williams Tested-by: Fan Ni Reviewed-by: Ira Weiny --- arch/x86/mm/init_64.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 01ea7c6df303..58ace82874eb 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1462,16 +1462,21 @@ static unsigned long probe_memory_block_size(void) } /* - * Use max block size to minimize overhead on bare metal, where - * alignment for memory hotplug isn't a concern. + * When hotplug alignment is not a concern, maximize blocksize + * to minimize overhead. Otherwise, align to the lesser of advice + * alignment and end of memory alignment. */ - if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) { + bz = memory_block_advised_max_size(); + if (!bz) { bz = MAX_BLOCK_SIZE; - goto done; + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + goto done; + } else { + bz = max(min(bz, MAX_BLOCK_SIZE), MIN_MEMORY_BLOCK_SIZE); } /* Find the largest allowed block size that aligns to memory end */ - for (bz = MAX_BLOCK_SIZE; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { + for (; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { if (IS_ALIGNED(boot_mem_end, bz)) break; } From patchwork Mon Jan 13 17:44:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13937847 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 49C47C02184 for ; Mon, 13 Jan 2025 17:45:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16A2D6B0089; Mon, 13 Jan 2025 12:44:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F3956B008A; Mon, 13 Jan 2025 12:44:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E880E6B008C; Mon, 13 Jan 2025 12:44:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C45D86B0089 for ; Mon, 13 Jan 2025 12:44:58 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DEA87801F2 for ; Mon, 13 Jan 2025 17:44:57 +0000 (UTC) X-FDA: 83003154234.28.1EC51F8 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 021D110000D for ; Mon, 13 Jan 2025 17:44:55 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=FYLItdRL; dmarc=none; spf=pass (imf14.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.172 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736790296; a=rsa-sha256; cv=none; b=3sz1qXTNq057Yx+cGItFnFdl5ZKfyBrhGWf7FIp4Km8O8US4HQQ/29wVg6VPrgHeYm6W5F mGs2/G6P4f2fYny1nNHwe17IH863wq2OTv9C9ga5RzjpHtoQ9dy5T4uBQ2141WU6QudNHv XZ0RlkWbTYH3XAqUNXHHKKXiKCE6ZMY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=FYLItdRL; dmarc=none; spf=pass (imf14.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.172 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=1736790296; 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=yl2EwUT2VKVvGiWjqp0to7EI8yUq6Zt171XOZkuZj5A=; b=v5z4y8OMmPGkNqCU9iBaoDZTX9itecOgp8zjx/DAUBFWTmekiKLWqwNd/yyw9BET8tAw09 +J2zB8pjjgvVkxI0DViQdWvMe1gN4T19KZV1WLcfiy03rc3sueXeoUe2fwTSLVc4S/a5he 9aBJiQXM0elxZ1botgdJojWZzGMt0l4= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b6eb531e13so253022685a.0 for ; Mon, 13 Jan 2025 09:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736790294; x=1737395094; 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=yl2EwUT2VKVvGiWjqp0to7EI8yUq6Zt171XOZkuZj5A=; b=FYLItdRLh22l6v/LHwa+H/t35UbZ740B3kijNu1nORbhlzPt/ChjKxkPBIbTg+2iGx 2F/YyfCoplStLZ168WvJY4OwRxyyhWI69SgsUSyxiC8p7puY7fg/EMQQE3vv8asuK35o 8uqdMzSYld/k0UHkMu04hpVbXW/3DMOfLW05JUtDgb1BpBLqflp4Eg7+lXt+roB8cDzy qicMskeDb1mlW7xSrFf/l+dUc2s+y7mz9+cz7FUKf74c3imRkGckxsj1qnZKgXXiqaDf aQBTylHLpIwc0UkZxb5JdaUwsO4mAGI1zYPhPfISCvwiZOxFZRheS2aKdHb5Q1WUkdu/ j08g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736790294; x=1737395094; 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=yl2EwUT2VKVvGiWjqp0to7EI8yUq6Zt171XOZkuZj5A=; b=SHwIo7gyiAidaNUEhzLOxWAeq2zuqq1TyN13E65trNtbcLAK/o/Qo2H2XduspAyQWm fHPbqLIi+HZ6SaDQO/BugShfA77PD6cdMrQXMAB1pjhdyEcwJmdTqkbZJYcrowvFrtyp V6ihNzDPYhc0W4jyi6FphgTKLzpXzaOLqzj1Ott9+RTELzvjq8oMmEC4Oo+cQLmb7H+0 Sgvw11xC3Diphx7CqkFH7/oBjLfniPT9MxAtX7Gox2CoCefinW1QOzxe8Wyso+yQ/WcF bpj0PfKFpmVbLcCQVsPTuf7NEwfGGQuIUFQ3qsHD0GiWnmVACsFGoMFVNt8Azv6euCCx 65MQ== X-Gm-Message-State: AOJu0YybxbPzUuvFnSicRwYhFrH/3qNKMrR7mD7JZyE3ZZ+RLLkc6HEU eP95m9aeyykSLi3J1okiMDAAut09s5IsrEXzrrhue4Y/9FM0xAIYHF6gwXoa64U0Cen3kDWibuh E X-Gm-Gg: ASbGncuTEjVQCu6y6Zq3zcI+SIjwK/Hr9bgy00noqAKZRf/x/t8GdCtZP/uV1JNLG1D lGCc1IQciiasZ9nCJtrCIcBJI9tZUfGpCfaFJHZi82u0a0AO8Z0jx/7oSdA4Sj4Fj8Km41Rlvqo zjcpLy7wH3iavYtFy6szbhLoHP7g7sc2S+plaN17OEvh3c74iU+qFxMPuq/uYpQNRXSIEcKLeJL z5X0LBvVZt5RdJ8xMKvCaZ6BOhQuo3pRoqmPYpSBgsSxHdfHUpcwVqO4IymbyqlPxQdWX8q+6l/ JNfLEr8GFC1z5y0agXcUGmtXzcQlrnoKoDC7ot3d4+Kk X-Google-Smtp-Source: AGHT+IHjZNO++490q5I1chUVLoFtrxzaVQ8wh+7ZzlHK7PMYF+bXoOp6mvzhXoNAdBo9KngXvoeIQg== X-Received: by 2002:a05:620a:4095:b0:7b6:6b88:cc00 with SMTP id af79cd13be357-7bcd96e8d37mr3639424985a.5.1736790294598; Mon, 13 Jan 2025 09:44:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 09:44:53 -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, Fan Ni Subject: [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Date: Mon, 13 Jan 2025 12:44:39 -0500 Message-ID: <20250113174439.1965168-4-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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 021D110000D X-Stat-Signature: nbmbiwzmonquh6hojmt8uscdbc81npgd X-Rspam-User: X-HE-Tag: 1736790295-999113 X-HE-Meta: U2FsdGVkX19HTw8LDlw4ZG1/qeEsTiMRC8MJSyVB4C5pmZuD7ekZslGiUz38+KAhvEd9st1uWtr88TyVx95s9jTIi28GScnilQ354q5nJKYtpkudOv/fgJ6pU6mvrov6rj+pSPbmWt+HMCEhYMitjT3q+jVNq0iT1kBfuBCUj2oomD+xrP8W5Vz+mDyPNHoLApMFoMrjIuWFJPW/TbOSdMgJUyhfGwtFHkwfz3NhbbHk4nFzM2pIPfoOlYHHjpRfZKgM1FB/aWXPwMKi3F8XzxSsyFdEb4rHRE5dBlBizZDdsm5k7o7UMXYZC+KFxRXwjpwTx6TjJ+nq8HA0KL361ie9B9RJAu5mOefgA2trIrIWmcEN1haeV/mzJ32WhJNSey2EocdYlKokk9fnDMW+wDLOAMc54fFz5meVCKuSZ3NYjB0VXPK6ialVGAbRXaum4VXaAeUuZdDRtItQZablP0HxgGwnLoi9HVeHm31d7Xiq2GhqVlt1ISkdU/xZF6xgUlvquKQI/p56I2EYqbd8d+g0Gr6hnTTuGo9NsuOqoddYW9GMNYr0l3rGCfl/YMCW+0I93ANzsmvYTB/Mn+kGc4AcR8J/vvjfpqZzpRx3XQr466O69Z/l6vxz+qCfzDrLQXOerVUwlVqlvTboiKQHgq+CKN/zq+lqvtr5fUg84s7sEWLj35x2pS3O3uxu3WA6zNSBCrbgDc7LJnlyrBPYndYKhHMCrE0S3hrjyt9ky/lHwoHck+IgebSl4d1FKJb65bdixPTSB4Jt8VBEslsIbO8h3/swFbx+1HQ/A6+RlhhPO4+SMFM3CoMw7FYy07zBWQANkbQXG1FX6F2DPqExA3FJ2Q9dUXI+GKcMAnj/hT28yjZL1SguQOvD9r3WV4mAwI7i2CAy/ExX0RdEkf8rw/fEQ40btv8STZehVJ1i5zZOqK0iAZosHY3xV4Ap1SRZjwq30iOtCnpDA4oM68O olVwfZ4P Qi0ji0IzFtd73W8A9SQD85J7Aa0yhvxd4BjipKWSlBRDDTbtp/gRm67Dn12dn8xai0PE7Ymn/BrkxfmW9OJYQrZlXHVNHQDb12SsP1iyiyogep3JsNGA41ZzMcayZkJFAyoDLo/7Etz0OtFh2v6CsnIVFP2VQAoP8AZKa9b4NXTbkGKr3eQ5A92JUN+h6fFOI/ryamJ6teBeLFCxiMOLaXNvH3jJKNDGfr/wyGaspQ0bBbrQRJG8wYGbLjjBGVXa4qilbTOdV12xTmCDRxgJkWR4zWjgyvju6dHeJTgIvJiL+cC3YAR2EpJ7GOo1vskbK2PrVNPEJJyl7rxYIwTNjq4kXhtCGIDhJqhP8y+GnJ+3ezjR2Ede9wbIfxyY5u0IIG54R1RxJUQF4FHjrfcBi9V5GeA== 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: Capacity is stranded when CFMWS regions are not aligned to block size. On x86, block size increases with capacity (2G blocks @ 64G capacity). Use CFMWS base/size to report memory block size alignment advice. Suggested-by: Dan Williams Signed-off-by: Gregory Price Acked-by: Mike Rapoport (Microsoft) Acked-by: David Hildenbrand Acked-by: Dan Williams Tested-by: Fan Ni Acked-by: Rafael J. Wysocki Reviewed-by: Ira Weiny --- drivers/acpi/numa/srat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 59fffe34c9d0..7526119fe945 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -425,13 +426,22 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, { struct acpi_cedt_cfmws *cfmws; int *fake_pxm = arg; - u64 start, end; + u64 start, end, align; int node; cfmws = (struct acpi_cedt_cfmws *)header; start = cfmws->base_hpa; end = cfmws->base_hpa + cfmws->window_size; + /* Align memblock size to CFMW regions if possible */ + align = 1UL << __ffs(start | end); + if (align >= SZ_256M) { + if (memory_block_advise_max_size(align) < 0) + pr_warn("CFMWS: memblock size advise failed\n"); + } else { + pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n"); + } + /* * The SRAT may have already described NUMA details for all, * or a portion of, this CFMWS HPA range. Extend the memblks