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 B1A34D767D6 for ; Thu, 31 Oct 2024 14:35:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCFCB6B007B; Thu, 31 Oct 2024 10:35:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7F4E6B0082; Thu, 31 Oct 2024 10:35:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C470E6B0083; Thu, 31 Oct 2024 10:35:09 -0400 (EDT) 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 A520B6B007B for ; Thu, 31 Oct 2024 10:35:09 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 593A4141632 for ; Thu, 31 Oct 2024 14:35:09 +0000 (UTC) X-FDA: 82734142890.20.12FDC24 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf10.hostedemail.com (Postfix) with ESMTP id B014BC0025 for ; Thu, 31 Oct 2024 14:34:55 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AzERKkIR; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730385130; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lLbnuW6RY4mTNtvqJAdKWQzGehqHG4zbOJspGmJeYKY=; b=MvvSokqpwPIjyneTXwmGMDGuI6MASl7lUHUVH1eaTOPVh5cnalJbxpe6NxB3Vgv995IM1Z OOPCGZW+m6TFZUG3STO0VOTYumB7bfK+FDBo0/s6tvFG7p04eL8QeFnFYaBlu0x8K/Hs/k nMmjf3NDtDHYjM5hUWjEV2abkip/558= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AzERKkIR; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730385130; a=rsa-sha256; cv=none; b=0xAsL4Mh++ZJN0bHhSUeYMTvl7mXSUeB/xslEaa2W6WgeKlN336YCZquGZkqOeDQOhrmQu E/wIEPzRfnWXlT3KX+2wKt+EpT00lHDuF4/TBDqK7dt2pLpPooq6DpXdO5PRjqk0Ygj81K TAw5zuNjMKutz/tqufMRdSmhmET2KEs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 27A80A44247; Thu, 31 Oct 2024 14:33:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84EEAC4AF1B; Thu, 31 Oct 2024 14:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730385306; bh=908GH7IBG1XfA0L7MNM6eq8gsxx7GOrv1X37ET8DUyw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AzERKkIRwC/O4kQ8lXH0L4xaw8lcCpG9teRlnbXLQORdNS/jid5oXobAIqrFBvnMj 8TavotafNAjfch6gf0LzZd7t4y0STCY6OrBp4+pmufLdZw1Fob2IJ4RKCx1QlAfwV9 igjdjueqvbXLikgcF2avFhhxK4GjtzcQFneRgzqKo5j+kDvdftzhJhDxhFK67/RAo3 ZZnTPKmuxzBoEiw+4Nr6Ej07BMw2Avy0n+cNU0B+udrtpRzcAdUbRXmmbF8dH36io5 ZNTxQC63JDz1vnx9yl/KoBYUc48LeRNVURbhd+I75R8XMmmDJU2+T05l6ZtsAZv4qg xvwr8D+8DX0Bg== Date: Thu, 31 Oct 2024 16:31:03 +0200 From: Mike Rapoport To: Gregory Price Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, Jonathan.Cameron@huawei.com, dan.j.williams@intel.com, rrichter@amd.com, Terry.Bowman@amd.com, dave.jiang@intel.com, ira.weiny@intel.com, alison.schofield@intel.com, 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 Subject: Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size Message-ID: References: <20241029202041.25334-1-gourry@gourry.net> <20241029202041.25334-2-gourry@gourry.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241029202041.25334-2-gourry@gourry.net> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B014BC0025 X-Stat-Signature: w956uix6ndr3a7aypzngs61pzof7aref X-Rspam-User: X-HE-Tag: 1730385295-279780 X-HE-Meta: U2FsdGVkX1/Zf1NzcVFBy/836qir7C5rc0MPicg2kluBStMmkFJufNp6VWfY2/B4FQzhWd5M0oLRa1R0GAnJv0Vz5YxHZX83d2cPcgS8J/e4QUBGezWK2L2iISMxwuyVgfm5ToONE8M2+BWATClglf8oZsC867l7lda9ByLJH0g4rlaV4eGbdLDKtn5nSkP1ac4O4C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HD7rg6nTMcBdchABdK9KkaHZUJWt5EaF4F2GGFeZvovd+qknUPNrEHxEoK6ARAGMUXK041SfS3LiwBk88ZjzT7u5PVW4aT7/vbpACbQdObiDmOjU8LjF1 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: On Tue, Oct 29, 2024 at 04:20:39PM -0400, Gregory Price wrote: > 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 > --- > drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++ > include/linux/memory.h | 10 +++++++++ > 2 files changed, 58 insertions(+) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 67858eeb92ed..099a972c52dc 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev) > kfree(mem); > } > > +/** > + * 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 > + */ > +static size_t memory_block_advised_sz; > +static bool memory_block_advised_size_queried; kernel-doc will be unhappy about variable declarations between the doc block and the function it describes > +int memory_block_advise_max_size(size_t size) > +{ > + if (!size || !is_power_of_2(size)) > + return -EINVAL; > + > + if (memory_block_advised_size_queried) > + return -EBUSY; > + > + if (memory_block_advised_sz) > + memory_block_advised_sz = min(size, memory_block_advised_sz); > + else > + memory_block_advised_sz = 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. > + */ > +size_t memory_block_advised_max_size(void) > +{ > + memory_block_advised_size_queried = true; > + return memory_block_advised_sz; > +} > + > 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..07e20a77b717 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(size_t size) > +{ > + return -ENODEV; > +} > +static inline size_t 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(size_t size); > +size_t memory_block_advised_max_size(void); > #endif /* CONFIG_MEMORY_HOTPLUG */ > > /* > -- > 2.43.0 > -- Sincerely yours, Mike.