From patchwork Tue Oct 22 21:34:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13846186 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 2476FCDD0EA for ; Tue, 22 Oct 2024 21:34:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A82AF6B00AA; Tue, 22 Oct 2024 17:34:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A31BD6B00B4; Tue, 22 Oct 2024 17:34:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AC5E6B00B5; Tue, 22 Oct 2024 17:34:56 -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 6BFA76B00AA for ; Tue, 22 Oct 2024 17:34:56 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9DAACA0578 for ; Tue, 22 Oct 2024 21:34:25 +0000 (UTC) X-FDA: 82702543224.14.A189FF6 Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) by imf19.hostedemail.com (Postfix) with ESMTP id CA63C1A000A for ; Tue, 22 Oct 2024 21:34:33 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=svPXjyP6; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.217.53 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=1729632817; 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=ufKC44gX2rTxHnQ7e/iieQk2KCFejx60Yu8CtfOC82k=; b=qSHsehyysR4WHyJ91TZ01Hmd8ZEqXHUKe1D6NkiNiWU/qiXi472ad71Izv3+2werMJm5H/ jHiZLVSYqN/JuwIASp7+Jgg463XMA/ihv5xctPy4xrx9Vc0yJiO/FtwqevYdzjLM4IUCU3 N2hYeA8bZFiGoSdEicC+q9fIMKW+EJk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=svPXjyP6; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.217.53 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729632817; a=rsa-sha256; cv=none; b=Rr3nqgtJjh/AY+LQoa29F9CknW3TJtn17cvwpWwrXiyyeNG0+ZwaC+VMqGWXfUOwyZgHMn g0BamImsx1RlTLsnsBOuLCihh9c5sidefVOpQ4p7jVLwCYJpF97cFn0KtCZ6HYso0RB7kN jMzxAePCOrUqMNT8g2+xX67lDAbIEXY= Received: by mail-vs1-f53.google.com with SMTP id ada2fe7eead31-4a492f73befso1745070137.2 for ; Tue, 22 Oct 2024 14:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729632893; x=1730237693; 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=ufKC44gX2rTxHnQ7e/iieQk2KCFejx60Yu8CtfOC82k=; b=svPXjyP6Y1Q1FPNh4U5JIpIE4bjki1dfspZxy5GyOvWzSLujejXNkQukOnAeNCIGSU k7QZb7SVgGESHwdvAE3EH3V2YG2ciNXLt3C+MXOrq9jsghVJxJ01t8l4PUy+H31kYEtx ZgUJnpdhkTBp35d/SYMdJFvdP7Jbp6jq8/YTpSRzNxMBXiA529Bh5THNiPAmSdf3Wlcb JmBL7VHrMBc7wQ64hcMYxbJQrnHSZBj8nynwgkT4QXtTwnYLliAKmqNO45Loqv780dBi youQM9cM/Fusu5wkVOhSlk0H0bKRqQyDQlS7N534jAJLCpJ6ltdqB/vMgsQi+PIsoLnK NiPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729632893; x=1730237693; 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=ufKC44gX2rTxHnQ7e/iieQk2KCFejx60Yu8CtfOC82k=; b=hk/cQ6dXKdA2QJ6vkt/2iKhYJL/YuHVGec6laKCudG4aUa7pD3vlrh2ZdRxKjsP76z 21T3qdad+kLmJpVJzw+9T5ctjsIuT2JJqMJ/FcBqfQ8clKRuQtr0YaXjtdthuAS96yiR vfskxuByxo3EYfaq26JYjfuh3ZDLSf+FicO2CW3HagH5CGdy7AhegzMwJ+6ijwj3QBvv tgajx+/E/UFGL2JDlL4GFcHT24XP3d6Iqp4wPyzXHtY6yD1cTROS4/ZzifrY0gBINLNI FSYVF+51KVS0YrnG+Xgv2HV8OvXpaBZGI3PRh3Cps/JrTShaDKv/58ln1HzlUAGW3QCr B3qw== X-Forwarded-Encrypted: i=1; AJvYcCUzhpZ9YAMG+FVb4rRER8ocab5s55+RqVxUlbYue/LIH1cspIFzg52dcq1q+/E5kLFsQuEA8GYb7A==@kvack.org X-Gm-Message-State: AOJu0Yysk+lQEcIfLDKYJe/T4IznVJ83NFcyZpIywUWgTC7YAgF8Z1at f1yy2A/AAt6NOgHAnRlLpN+e7HUZnoYYza46Js/CuomKDnIaH0cOjuT+k7qjT/I= X-Google-Smtp-Source: AGHT+IE++oEhimUSC/n6odFHU11d3lmzvoMxQ3GR+KJvVhAk1j85ECkXjUx948Kl/hJd8+RlCzZn1g== X-Received: by 2002:a05:6102:3a07:b0:4a5:c74b:66a7 with SMTP id ada2fe7eead31-4a751c94d11mr591818137.19.1729632893322; Tue, 22 Oct 2024 14:34:53 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3c62f4dsm33845841cf.28.2024.10.22.14.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 14:34:52 -0700 (PDT) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@kvack.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, gourry@gourry.net, 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, rppt@kernel.org Subject: [PATCH v3 1/3] memory: implement memory_block_advise/probe_max_size Date: Tue, 22 Oct 2024 17:34:48 -0400 Message-ID: <20241022213450.15041-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241022213450.15041-1-gourry@gourry.net> References: <20241022213450.15041-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: CA63C1A000A X-Stat-Signature: w31i6yxc7oqp7dikbkeidxbuz975y59p X-HE-Tag: 1729632873-815775 X-HE-Meta: U2FsdGVkX1+FLptuDZRz+xblF8wjlovmIRMTQrQI9YPE2iGDAEwbygJJs7nG9ITOIUYCgB7gYUdfNKh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uE5dq2ghC4uN0FmPPSwSmDe20gFEJf205DAbnyLmvRflDMdjURoGK7ooG6zqX5q50PXWLNfGGKpZ5IL1WLhlIQB3LYzPqjYQE+NRD0N2DZdxX9JMIBNs4GnhjiE+i7tio5QkY5zxg+BsVHOuuRjqTZ7NlWfDh+IIcYHoX8o5292gaMIgmku7Mr1sWLaZni9pL2A== 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 --- drivers/base/memory.c | 43 ++++++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 10 ++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 67858eeb92ed..a0fd9e1451aa 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -110,6 +110,49 @@ static void memory_block_release(struct device *dev) kfree(mem); } +/* + * @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 dependent, as is min/max block size. + * + * Returns: 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_size_probed; +int memory_block_advise_max_size(size_t bz) +{ + if (!bz || (bz & (bz - 1)) != 0) + return -EINVAL; + + if (memory_block_size_probed) + return -EBUSY; + + if (memory_block_advised_sz) + memory_block_advised_sz = min(bz, memory_block_advised_sz); + else + memory_block_advised_sz = bz; + + return 0; +} + +/* + * memory_block_probe_max_size provides a suggested maximum memory block + * size value. After the first call, the value can never change. + * + * Returns: advised size in bytes, or 0 if never set. + */ +size_t memory_block_probe_max_size(void) +{ + memory_block_size_probed = 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..47c00d6e1165 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_probe_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_probe_max_size(void); #endif /* CONFIG_MEMORY_HOTPLUG */ /*