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 EB96BE6F06D for ; Fri, 1 Nov 2024 16:06:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85B7D6B0089; Fri, 1 Nov 2024 12:06:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E37F6B008C; Fri, 1 Nov 2024 12:06:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 685AE6B0093; Fri, 1 Nov 2024 12:06:11 -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 41A186B0089 for ; Fri, 1 Nov 2024 12:06:11 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E7EB9A09CC for ; Fri, 1 Nov 2024 16:06:10 +0000 (UTC) X-FDA: 82738001514.13.C798410 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 6732EC000E for ; Fri, 1 Nov 2024 16:05:40 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=a5zELRtH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730477087; 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=8RgBYQG6J+yULI3lFFBLMpjEWc4At/pZ3LW39A5tso4=; b=S9asQdEukBQcNZuCyGyscMt+4OsVNCShI+ZuZfrSTNcEqTeOCJl2owdzJHMBl0mzlNiNgc PXX2RJaGEhewN2k6JL3/tbaPgEpDrNWdVVHpGQhPtuJilHZSd/G1Kp1CNOsMDAA+uVQUdI pIBSKIGvpBSLYnT6RSoMTqlFulPh9Vg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=a5zELRtH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730477087; a=rsa-sha256; cv=none; b=Chgooqx02budTdxeDgIE5oyju2drwWdlqOzbP/UeQ8YG5vZ4YTM2qPC8nS5HIK8lHakpIa GUT5sur8z+VyW+u2g+Q72QN6KrHPjxAmcQcM0XC7399tl7ylVTC9plh2xeJ7doMr89UMsa 9nbtr1L2HSa+hEEhZmkdWYNJyPf1TX0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C85F95C30B4; Fri, 1 Nov 2024 16:05:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1221EC4CECD; Fri, 1 Nov 2024 16:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730477167; bh=4S+pRg+jKAU5U0sHcwkK0/Iq9498uZZRXnJEb+oAdv4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a5zELRtHls8OA0jW/I9NJV8QWjJ25s4S0RI4BX4gGobl98QHmHNj6seEnbtduRhhV dWzfY1RwUvQxPDeNU710rOM+ApwCThagAjmbno04oYmX0zqhVOGAm5mDfhDB0vtTiB 6kziyYtZX6/UcfOpGPcDzifMAsm06Y2F0axjmnb77Z7srcZHAN/+LIP+zvLjZB483J HZQcpn8RNgYY0d7THaCXPeyUYT0sBEnJzaA69GeOh/3ytpkGfYfozenx/mZFkHyT1a ayDJfiy+S6FyOWW8a1djQtUWTqcSe1keIn/JarTwH53P4uES4GTM/YBPBCjm/Yw+ru rEhoCg2PP1bpw== Date: Fri, 1 Nov 2024 18:02: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 v5 1/3] memory: implement memory_block_advise/probe_max_size Message-ID: References: <20241101134706.1185-1-gourry@gourry.net> <20241101134706.1185-2-gourry@gourry.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241101134706.1185-2-gourry@gourry.net> X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6732EC000E X-Stat-Signature: 5djfbz9mtrtim5nybq3p4ex6jues3oge X-HE-Tag: 1730477140-724795 X-HE-Meta: U2FsdGVkX1+jj4GwXi+k1yF+RMfj/75xx3dhsKDKZDQOBDjl9xHoPWIRa2tPejsmOZxcamV7ZYIMyDqYuTifRWd1DVe8ur0CxxxLwsEYdD/ayxi2A48jQFhfuZZfXiuHh48i22LEbw8WsNGsN4oYAEVTTjzISJeQhJPsNpG+yT6TC73nw2RYV4p6kZO8D5x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gnr28qMn4qxBhakMZOC4f9T7H8s9MXp4547FIz8RIMfoCY7qTPbwcnD34dAXMeC6xDre+CBzmCX+PRhJ+aGO/c37PXZw3E3PzVKih1JGyJWKZJ0nkXZpXKv1iYuyIPwDABczl8AvC946IYp/JdlsHTu5yftA== 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 Fri, Nov 01, 2024 at 09:47:03AM -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 > Acked-by: David Hildenbrand Acked-by: Mike Rapoport (Microsoft) > --- > 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 67858eeb92ed..835793150b41 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 */ > > /* > -- > 2.43.0 > -- Sincerely yours, Mike.