From mboxrd@z Thu Jan 1 00:00:00 1970 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 6004BC0218A for ; Mon, 27 Jan 2025 15:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C53BC28016A; Mon, 27 Jan 2025 10:34:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C03EC280165; Mon, 27 Jan 2025 10:34:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7D4B28016A; Mon, 27 Jan 2025 10:34:17 -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 81EEC280165 for ; Mon, 27 Jan 2025 10:34:17 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 31A7045814 for ; Mon, 27 Jan 2025 15:34:17 +0000 (UTC) X-FDA: 83053628154.07.B475AA2 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf27.hostedemail.com (Postfix) with ESMTP id 67FBE40002 for ; Mon, 27 Jan 2025 15:34:15 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=foaVcCuj; spf=pass (imf27.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.178 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=1737992055; 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=WEKgJJf51nUXgtjwZFRtEbK89HKdrqyuzjYJ58simEs=; b=lRdNaFa1lLCz0JuGkYCQFKgSf7g/tqU4/nWlU4zaj8brQCpIP4XYwRvj31Q7LhF7voKpgI rYPi1DZzyxyGsPg/Zv1O0yQfXH5kKhfhvcSKzTh9O0Zg0taRwSlxX1Jh8yKrNMoWLQIyMZ NseMsdtfSYBF6nfUrXSGLpju/BikuNY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737992055; a=rsa-sha256; cv=none; b=0ZnPRRWJ/UihiueClk1z2gHxjqrxQJhC8G+si/XOJ2K1B4FfNgHmPpfWECV9td7bc9Qg5N DRrq5ojDkCvULK+ImbwAKH/Fse8VyXw+W2t1SESUGPWP0x1f1+SH2e0Ii0Ry1jqC4foH8E Z3BxlDFAsqLzfbZ9GsnAYL/Q33rca1Q= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=foaVcCuj; spf=pass (imf27.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.178 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7be8f281714so428846085a.1 for ; Mon, 27 Jan 2025 07:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1737992054; x=1738596854; 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=WEKgJJf51nUXgtjwZFRtEbK89HKdrqyuzjYJ58simEs=; b=foaVcCuj8bs8eZOA4bHnhIpqgQzX+Ne3A7KiBfeyiGAAzwWwR1W0e+2sv2/wJ3ilKu KFRp5CyD8kXeOi8eaQze/ECVlFxu8uLWuj9oP1u4Q+J8OoYbhcWbdjirNXitoEuPtT+E jIp2kqIKRuKMbdh2wntvb6aGA4bZj1mYROeAOsi8S+BmGCWkcconqZIINRSlENcein/T wsDsc52mbLofTgjLtdunkYZV1mmcrGvONBgjs7lP8Q0TpWJPuwPfbnTQpwOpTALQ9sPz OridSOEdL0rPHjRoW5wSFt7f8stZTCRHfZpQCLTvCUyubTgCdQ0C14VOwSxNa+beTjvB ZX5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737992054; x=1738596854; 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=WEKgJJf51nUXgtjwZFRtEbK89HKdrqyuzjYJ58simEs=; b=VWDuhG5YFgpKALNEgmZaAwyEGScSJQYLgM75n1Yvn6mG0hGowkbVTnuOMvsvOvCJCU UDg4c7NQXZq6al5k64Cr3RNxtkOnZ4UMzeraLIOC3jGWDMQc3VL0Sp414lDA3w85iIKC 1VCjvypcCpgZFM64riN7oMluUzgzLR91emKhoRjgOMZHqHCgIeu/0xdt6XX6kO6JXYk9 Bqrvm0iMi0IgXteBpcPMiactoba60a8e+BCYUK6Q6hi54VgsUOixszK7QwkKrA8RzUBK tJQyihdIbeHjyqx+Zm2OTJ7VUvnpX90GX2sDWogrkLI1DUqFSDvwHYMTBWBeKw5/Nah5 33lg== X-Gm-Message-State: AOJu0YwYXO3Vw+c9LJ2XXOGeN3xYGN2m9Ft7XioIyMy/irnKwsd20Cff qHlepKFyht389MGn52Ao0yfgItskOPj9sNNdYua+1+N4OSWfs0u9+51/Oi9K/rT2t3DGUQlqvvE A X-Gm-Gg: ASbGnctrO1sugxpFKiCYkeVugxIZ4c88CLerhBeamKmPWuvWwLYMa8JO/0xt9BNu/kT cRsrSf61Gmd+oANlmqBnaSJ97UYVxvoO1ZwSqz9x+u5ZxHmO7mGTqZBm7Von4sZeE0yB1zsaCIT YizULVuAvYyots7N/x0HicygeiCpEQnpeFviveW15g2wW0bjdxmUkwAfssxtHt0kpF7+rVVcvjh v3fwAZVvnuHMbHQVepDNW1mWZtfJbcBMe4f1GeU9UkX7T7TffduEHRDQrqbF6WEAZG/ebqdJYO/ TDW8euSqjIWw9nFdY9KkBvZq7PJeG8EXSCUz7ogZIrxRQ54d/ROd+k7CAzc6HZkFuPtp X-Google-Smtp-Source: AGHT+IGoKs+d0lqDKVI9i+teoRAx9CQCD+e8LPsJoU6HHbn9z9w7GdlOVjcgcKDj1hULyXcfAypH2A== X-Received: by 2002:a05:6214:4b0f:b0:6e1:a36b:3445 with SMTP id 6a1803df08f44-6e1b21857c6mr708814736d6.19.1737992054132; Mon, 27 Jan 2025 07:34:14 -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-6e2058c2a51sm35380476d6.109.2025.01.27.07.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 07:34:13 -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: [PATCH v8 1/3] memory: implement memory_block_advise/probe_max_size Date: Mon, 27 Jan 2025 10:34:03 -0500 Message-ID: <20250127153405.3379117-2-gourry@gourry.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127153405.3379117-1-gourry@gourry.net> References: <20250127153405.3379117-1-gourry@gourry.net> MIME-Version: 1.0 Content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t5zwvW2yryWW5hQCGph9oCLFwZjvf5vVWg9WlvrH/ eC+hRpnL DXHc3jyT6XqKScGStzMHgXhmrsV/6vuxfnx+iTm/fjGRaK4A+5HRB5Idgt/xy2rCWqeVrTVHccO8bQXHIuceXRcbvCIoDcPC22wRLh6OkJyBPktQe07KLSpuWaiTF2yttyxS5ZaVoN1kH5IYItLg0O2Lj4gajFUtdpBL9h2SkHWJX167HCUnIGKORcXn17SrsBP3qW+bXkI4pf66KnJbDOoZGcU39zbGh7eNrnQcnfJ7Sce8hosc8rqav55bOMW051/H7RdSVrgApkEyMvCPHq67gWC8S1u14eT/zzR/0hunCeV9tgdHlI9xzXZXRWATjYSHgiZHn0pYLb3NDm6BPjC9ynVY5ruK14fk6Iibb0cqk0PI6VDrKQMhtWoB0mhMKYLrk4roDobBEHlE+NygqkSv4KShZkHeJPhffLNb8XszjCSzGQjX7HTCyGdBe1fv5xaGv 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 Acked-by: David Hildenbrand Acked-by: Mike Rapoport (Microsoft) Acked-by: Dan Williams Tested-by: Fan Ni Reviewed-by: Ira Weiny Signed-off-by: Gregory Price --- drivers/base/memory.c | 51 ++++++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 10 +++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 348c5dbbfa68..69feacbac3da 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -110,6 +110,57 @@ 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 */ /* -- 2.48.1