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+xblF8wjlovmIRMTQrQI9YPE2iGDAEwbygJJs7nG9ITOIUYCgB7gYUdfNKhqdwWH2/M4hWucZ+CyZy6ZBmWDyVLj/AJWb46a6pqUnPwKMPPp115xDGPMpkFaGcwwQC1FLgAUCPCqZ2hqXN+cybaXUfwwzosgzCQR+JGXC1qRlPcAoxQxMYctintQ/3I0OWXXU1bnSLHXWcncW7tIS0frMayVvUzd4NpzIUFAN0LtPZGCvyshjxq5w2GFFUfkPTTvcIPTfatOWewikGLSw90cB8+esfxGUO8IbJ5+ytV2xZKpkMfDfbvoZIhE1LlYaewqzODUjkBk5mZXXCg3yHuhFGyhYkh3Qd170WXErF6P76eZchFLypUGiFSIQgF9EigaZGOPXiPRk6SGvcC13zOl9p+l7joishn5imCEZuZcpcBmWPvTBHtryIfxTQQAQJAexky5H/4CIVx/a9AXZKs0+Dhf5ixytPV4hqsA5RSNsOIk8ifVC3lWn6a3jEntdaHg59MIzeqWZ1Kl4NUWAkaty8DWDPLY95wSRoWqiLjzyACerScIl8es1WUt+DzQzWxgPWi5m/jCLrLOqdRf1fwrTSdGuBheb05ZMh+AC7FNByiAw283ga3ZaD7LJE6bwIfby+u9yKQtdlQEnPOl7AgU5yDKPw04jpA8QwO6QFabTli+BADYfvKO9jjF3YS036rW5B3tcjxwMl8g4rU6+GaRBBjAU//sMXs2Ua/O4PiLF5DQ1HpOr41ld4YRM+BUIGkIBGlzwMumzJwNsNTM8tqemyxKAdxBeIpE63oDjlK3CBCJ6grRhHh5dlYsDhb8OJ55pHGrupkNs37lW768WC7DdECzbZUUAtwM1emUwDUDkfuMm29Dz5II53oRgy19OLEZJsVu27YJLLXv8vrnR7tEQUJWj806ga/k4o5qvGHolMjdhC5NpExBKiyO5hm1ZZo TzExuL1N yZ+hkSDAWg7HzswRGf/r+GvEmTl1joq+7Ag6U8DsqSJ4y70MgCQlcK0HLny2QnIISm7BoxTbBs82tIl8HM5LHSuzyPlfeYMelI1kFDE5ph4P5Dyq3TtpjmpGuvdKwlcB0547GWSbj2eQGwny4uDeGLYlaAaqm/8n9RFkGkBXeqLUFPIrXvTp4kDWuE5dq2ghC4uN0FmPPSwSmDe20gFEJf205DAbnyLmvRflDMdjURoGK7ooG6zqX5q50PXWLNfGGKpZ5IL1WLhlIQB3LYzPqjYQE+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 */ /* From patchwork Tue Oct 22 21:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13846187 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 226FDCDD0EA for ; Tue, 22 Oct 2024 21:35:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63CA66B00AB; Tue, 22 Oct 2024 17:34:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EC816B00B4; Tue, 22 Oct 2024 17:34:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48FC96B00B5; Tue, 22 Oct 2024 17:34:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2A7D36B00AB for ; Tue, 22 Oct 2024 17:34:59 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D2DCF1A053D for ; Tue, 22 Oct 2024 21:34:28 +0000 (UTC) X-FDA: 82702543014.30.C8404C6 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf21.hostedemail.com (Postfix) with ESMTP id 7650B1C0016 for ; Tue, 22 Oct 2024 21:34:25 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=i7kzuVo5; spf=pass (imf21.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.180 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=1729632845; 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=AqCv7heAkmMbGyHort0yESB5tthHSXy3Avmci0WyUUs=; b=kR9zR75ZF/IuTdf+IEY/oGjUVtmoAu/yZ7eJ9CvAlGnFsqeY8kZpvh+2Xr1DX85A1B5BqK zID81YvTJWrbEtdMmQt0OLBU0fafkHOTbqFhWKYOFGkbmqGkeaDOhubkI/APmEdNchaDSP HUZPxSSpl5h0DcUrMrojFhAUZZ25714= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=i7kzuVo5; spf=pass (imf21.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.180 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729632845; a=rsa-sha256; cv=none; b=Ermtow9huBy4xcpfFxJ7nBKhgMTQCqHqCK2XxS1lv5fdFTqNSq2yQ9jB72HzfA+gp0JQJ1 KhfWUJ7/8XbEC4zX9Z1MV7RQfNLy9kzvhWM+5SSk07FzEIE208XuQ8Q83AW/fxVdmr3AUi eTUA+PsYC8p8UAgMXGNrKtaUbjGGhDQ= Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-460b2e4c50fso29640961cf.0 for ; Tue, 22 Oct 2024 14:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729632896; x=1730237696; 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=AqCv7heAkmMbGyHort0yESB5tthHSXy3Avmci0WyUUs=; b=i7kzuVo5cdoMYRGe9T1skeuwiGcvF4hyxZeqQncYS1d/h6BHqw9O2zRsGEkTPAg6JH q4B+kJgq2zYpLvAK5b6k3nbifuCP58xHslhbRx7MbJqHy8vEcMSkaHkynUuzNlXmG7v+ kho2SZOXMX7FKIQOakTRo95BqzGxGr/GgwghuK0za268PhGoDtpWuwE/JAOxhGepek7o lwDB4z7nqEAdpFq3wBDQ/vpyDWvRWgU+22fUfgSfL0nf9czzkxxdqa0+stgL/Oq4xkAQ gor0bi7dYBIawc0ml6daiUf6AEjhH6DAasz8bcKhsKHTy9KYSarO2/l/ERARbpH9OhQH OHGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729632896; x=1730237696; 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=AqCv7heAkmMbGyHort0yESB5tthHSXy3Avmci0WyUUs=; b=DLIPIzQz+CXIPJn/iRqeXgf2aWTHgXQrQ3tlf/v4Xsn80IsH1/+c0yjev0j8pRpAly IZS3c6das0YSHlI9Wz5bryVwiZoz+vN4RNSjy9Vt5ZZqLgh8lNvKIkhqjCLTUJ2oN2+N gyje1Hpi62urdaCGGVLtvvKS5xE1mg3INlvC5SCfrgiBS70pIviN+f5Ur7tMJ5ztzlN9 Ilkx3DVmeCcnKETee8hqYsCZS2MQkVpxOPMxrkhkRsKU+8CAGkVOjYJuXHL5S08UJGfr z8lKhAuPhUx4FKH8L5stIJjoEVrOaXUgofK0HIJthvsVMgii+DITv5XTCOxOt2/xhm0P O4dQ== X-Forwarded-Encrypted: i=1; AJvYcCUCoY6SDl4EBVzuLZTCaLq0HiujZFAMmFDpg/WEV6ryprZsetRMEkQhf3hf4y1/DikVK8wVuLlhug==@kvack.org X-Gm-Message-State: AOJu0Yz+ePISw3u7rHt5IijQoCUdJ4vKPqRw6i/Y538xVEmEhDIhutS9 r9+VeQhB3oQ33NOyw+hkG1nHyy28hAP0LmT75gy84q4oY9LsSoQfkPs4N/iK38E= X-Google-Smtp-Source: AGHT+IG6u8nXwqeHHa2iAZjSeQvjzXX9LlJNqnqKjo6O88p7xQbadR2zh6+g2YkgEfRojyf8qrAQmQ== X-Received: by 2002:ac8:59d4:0:b0:460:8e3b:6790 with SMTP id d75a77b69052e-4611470b2b0mr4519561cf.48.1729632896082; Tue, 22 Oct 2024 14:34:56 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 14:34:55 -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 2/3] x86: probe memory block size advisement value during mm init Date: Tue, 22 Oct 2024 17:34:49 -0400 Message-ID: <20241022213450.15041-3-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-Rspam-User: X-Stat-Signature: pw3pj93e3j6nhb46515fi4tkmqna7q6u X-Rspamd-Queue-Id: 7650B1C0016 X-Rspamd-Server: rspam11 X-HE-Tag: 1729632865-995240 X-HE-Meta: U2FsdGVkX1+MtHcNDQ9+hXQwWwYcMEwr8xlHbYOF5+eG1AXxgGggT3a3+h6cZcOnNeY/tOAenbvBSt1GALoHgrTG7gsvRBYIeYAEj6o8pvXH/fPkAEraU21Wz1aemInA/kWIOs9LQ+AIYSISl++iPabyj2hRVCU5hEpNDnHJansLbmxbEj503m/jJhd2rd0vuMyS6S6ov/ox924EonJCvwADgjsrMf3FnzcFRYiwu/c4GzxdyxciCRK1hnpqvGQxygndeFEU1SiFayQ6AwToRIr/nnmPMgStJ34RmxghpdclJG0c3z/Na6CEZILTVBzFtqw7EikAmXou8x3XEvJ2nLk0Kdx+Mz5OvvKiuFfL8lWgmQH8wkugRbhzg0pPyOulya/TQqqhqx2yWIaf10qnZ/4wLzIRvY7WttSFHKBXmwmDn2/Dufq8cXSZob3RnC+PbvSyocegGIUloXevdEw/UhssRpRHAHc869FvH0M/zR9ylm7GStwKBrfcon6HTGhRnLnpbD2Yl2zZOHsdURPOrVZFvCP/hPTpNqiwOC0tKfb+Eebkqfmc9uYY5EmoyPGd7ZRuxFwXkDMkwjuVyGt9D1tixdx5lAIB1gEQAhBIiVe4EH9PS3yzjuOdSMMkdwCuSxo09lLXF1ElClEkv2+8+oQxbBsNKBBwjWC/5H3kq6l8pTO+Bpd1aKa7sF8JEUOsCb5OWHFOe1MMOOkXaFg5Gy4/hYnDtfEfzQyxHk3Xs/37sOsQ2nOHdseXq6wPq1fV4Z68lCoXZ81ZC+1zsBj+1EXiAKHeqalYlIPjE1revKq0CoVZzy+iCBqRwIFnil8XxO2sElTFfYwxwDv1dA1suHpJquv8TpmYU1UdKpMkF1k3E95eK++n626KgKKZI+XyKj/wNnmVN0vNU4E0qEVVqrQ+xDPUzRg67MPKgSSE7vxhOgeqQhQtZm+56yiNz6/nfOrR4TROF1XViZQPZ1y utoszLAg KzzwigGZPnnEnn5/6qCLNIXUErUPjm4h+DO80u2T+xqkBlyMtHEHZS75p+JyY9Gw9mJAaSvLqZgPhqMqOmiZjCV+9onfzy76bMWKV9U5YJGXpfV1N4gkNmHt+VRcYAp4aHUYksYb/rf+PGaN2c4vkZ47ZcYTBlzrrOeGLOT5DOfsz9hb2p0r4UgSVEjvymRSPN00SptOGtxy5s2ANF7vPpNunmr0aAs4T5njB/rNUwAE9CnEs60oyrEdoYbhl2r694Hu2lI5jzYMD+mqVDg10J+QWHubY92AAIv64wjeskkliIWt3bSCj8RwfNYoDZsh1V1KK4+ARaGtPfO4= 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. Suggested-by: David Hildenbrand Signed-off-by: Gregory Price Acked-by: David Hildenbrand --- arch/x86/mm/init_64.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index ff253648706f..93d669f467f7 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1452,13 +1452,17 @@ 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_probe_max_size(); + if (!bz) { bz = MAX_BLOCK_SIZE; - goto done; - } + if (!boot_cpu_has(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) { From patchwork Tue Oct 22 21:34:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13846188 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 BE6C9CDD0EA for ; Tue, 22 Oct 2024 21:35:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DCF86B00B5; Tue, 22 Oct 2024 17:35:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3C46B00B6; Tue, 22 Oct 2024 17:35:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B9B46B00B7; Tue, 22 Oct 2024 17:35:02 -0400 (EDT) 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 F3BDC6B00B5 for ; Tue, 22 Oct 2024 17:35:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 283961405A3 for ; Tue, 22 Oct 2024 21:34:44 +0000 (UTC) X-FDA: 82702543434.14.39677FA Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by imf05.hostedemail.com (Postfix) with ESMTP id 9B8B610000D for ; Tue, 22 Oct 2024 21:34:28 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=heTnrYEx; spf=pass (imf05.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.169 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=1729632748; 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=2Y78ubexqEa4jb5hMLl30/Xq5Y9Xokfp+mSha683Q8I=; b=zzIt6Y4llL5M014oXnXtUHPVxYGj9y5qvZfbxFQy+iLEN8dDb+OhzBi1vkq01KCE9bVn5d 8ytK85Tm0iajgZmSxI9D0itfLwmWdfMkK67tTDXmN8AH5FHzPcLgRxyQZW5LsBr0wwUBzi wDaskHmAY7cTO1sXUkjEdzzfulahQBw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729632748; a=rsa-sha256; cv=none; b=CgV8JHpeB2w25/7cH0KVXLj5JP+4/1vyYJuyBOAm6zpqGeHAr4ZzSasTB21wtEknPairHq xMl/8/BXaIUfGIuf1h0yNBYM1bR8TlwuIXo0yLx0dakUiOofyDIn2suQoV6zXh/bMpB0r1 JdqMHpIvJvothIz2WbNNGT5wOiCC7Ho= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=heTnrYEx; spf=pass (imf05.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.169 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-460a23ad00eso2412001cf.0 for ; Tue, 22 Oct 2024 14:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729632899; x=1730237699; 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=2Y78ubexqEa4jb5hMLl30/Xq5Y9Xokfp+mSha683Q8I=; b=heTnrYEx+A+Aw67+3TRHXJACqYd9QYw/mmLBohxgE0j/5NI4fj1i5ltIjMEtDaZKZS +7ETw4FVx7aa4IA8JSABtyAvh6YHBM+STlUT05wfXoA8xeX2t2EnNoX6SKIRlfUDP3hQ d8SjLNGlZrbYoJCSknfQRPXrE3UX/7nQN229XzgV7UqgzFKUoJoXJdOwc8CEYDFUSb2q xsD0d1Vtv+8ycbl4y3rs8JE+3IUf9i5C/9cmcJWGL8uPxoi1l/+sx+Ay40fyP94/gPYH naBzwHEwNSXhg8opWle5V/UXi6u2dnIedtFQp5+RWq2h2p4sd7LhuHoHi2tb6Hdh6aLk xvyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729632899; x=1730237699; 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=2Y78ubexqEa4jb5hMLl30/Xq5Y9Xokfp+mSha683Q8I=; b=NOM/erYW7jBsrm80B32yejhXYjLuZ+3pIDSFn19hXbL8Jt3VPdHkJdZpdDFLeKcihf rvFod6sMphAGLcH823N60zkcQo9BeKTRn/TX7/PoSBloJqYgV9ShnrrUli1zXR6j8ur3 s5T0ohxozSnMLCfVREim8NaYJVbUVUC3t9J495Zmk7EmjyfQxI6q1J1GF0K7YT5owQeZ Yj9XyaN32nPhvXed38QInBrBP5D+4+1FozBmt8ka/e2Zhzrq12LPog/ZWT7pXlT+T/Dk LlCH2Qjho25CY6od7BIMMzIkSPhT+1ygfkcOtxGV9mQ3Qz6TOjiWCEakCeJzCrAve85J NziA== X-Forwarded-Encrypted: i=1; AJvYcCV7EN/0jGaUxiYAPZj5j6GX9Aq6FePa+K/bUq4VX35tA0dWhH9eWGmej4jDlWmZ/FwQaeuQWHvR/w==@kvack.org X-Gm-Message-State: AOJu0Yw5EvcOSdZZqKt+Zmtk5jRg/6Po1Cm19Z9IjeKmQ7NZhen2JB1y yWk+tLk4q038aX2QiC1yZnMb7PVNM71DED6bOjWpCkkHb34C3PUw3f7bGCf4m1A= X-Google-Smtp-Source: AGHT+IH7eGA0cnfOQp14jPD3sIr1Ycw9daRo5ztpuW4QPmIXbYkKfaWizk6DGwzl4TxDDXn1JCZDPg== X-Received: by 2002:ac8:7d04:0:b0:459:a824:a1c2 with SMTP id d75a77b69052e-46114102e22mr12146281cf.22.1729632898984; Tue, 22 Oct 2024 14:34:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 14:34:58 -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 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Date: Tue, 22 Oct 2024 17:34:50 -0400 Message-ID: <20241022213450.15041-4-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9B8B610000D X-Stat-Signature: r3fsyj3e9bqdcc7nccrj8ygpwpeydnrp X-HE-Tag: 1729632868-285178 X-HE-Meta: U2FsdGVkX1++wqobIlcjM2gg19hbrPFGM1JAL5OCSbz+3UKQu8d6cHOVGHcnDTYGAcWqvcPSCPzNXCCcVORD1rM8rOfIJ6LueIabIHzbslDCFRLuOq/J9UgwTWnclaKtNMxSDHdR/qYPaRJPw5pHzStLdZdH61f+nmHJ2BGNS0xVuUWzJSOUKWhzCJy7ZQAwawrnf/HEUfngXT2pAn6VFpMGTolnDhCEsoE9P6clBtzV6w8V3JcaYsN2wYcvLXb5y3BOsAiuXZ/KurYSmKR0ouZfPOT5MbKPHQSfjabg4gzeoDYuU075Ne61U4QuygbLmJkg7/LMLyYf2tticzwkyIfczMIfnvia7MiL7pWD8nMFxP9TzcdBoG81RrONQ5ShRUe96Xz/tLcW34LnsVyso1/grrh8na5G6FYs4dx0Fe5pk0ZIzOXXUC3aNtaO/24ZYE2oXNNYW9yIWH/DmU85flwq1VpT+QxjX76a5OUlGQRLgYMAt4vvq4uDWX6CvPmzIXl0PfJ4jEwqUtNV2FltgWKwhgFtpSVNl1ei3dEAjQSUr3RcSNXZGQ6rdpe/PKWzAAsjGQkgbbyUy3wCitYVhVBr3FZpxgdF/TxuwJymAmLFuJNioPTas7O690OD5m8r1DLNoswRa+EIOFrkD2J7EjUeTdz7D7ql6HiUih4ygXmexMHvNf02V0O2QdlznaR4P3Qu1v7cmVJLZPLpT/KWU0/eRiHOhkHKGuWJ/pyGBNJQhr7/kOzzGATm9WGtFNHjM0zDgAKuGfl22YYEn719ohcW7HQI614w1sEaqsY4hGdakG9EeJh++qWyOCqLSRUe3OEBtgqXe0WIwlj8a8RDJv0noHNfvvL1+bljB6HQaGW1YIifKfG2YBT4Zw8ZkMEdZzv2+19sYY1CdmQ2ouF2PHZU86Rt1PKmOu27h//hYmgUO0EZABbTw+KnwsVxrD7jzXaAT3oDRiQtfYrqJvi MOO0Xm07 6FLNyMaZ+avaUGOAq5P1mDUHTpeFQZ+pbxzn4Qi2u9CGY6JNd5rodtB92L0aEnlko8ZwgY5+oATZpJz+e0P66Wu2RWXK5wTZ3SA6F8FZ+HY9+PR/9Gv4AQ7vuXuEAkMJLMOQI1TCpnGQTpkR0EMsb2rmAQoljIcrt5GkrMoK2ys9EN3GjavfhWGCCog6XDNPBrTJaFvXMMUk2CQYtDP0kN1kCGXfoah0Ud1QYpUetMICmbWZPEGV9HI2L9VCzuuPauO3LqVRGYPcSbzBFFV7BzjlccH1N43gbyg9Yg1n60yFi3vG43JxxCWvmFAMA7+Qx4gbo8LAVZk6Fuak= 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. After the alignment, the acpi code begins populating numa nodes with memblocks, so probe the value just prior to lock it in. All future callers should be providing advice prior to this point. Suggested-by: Dan Williams Signed-off-by: Gregory Price --- drivers/acpi/numa/srat.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 44f91f2c6c5d..35e6f7c17f60 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -333,6 +334,29 @@ acpi_parse_memory_affinity(union acpi_subtable_headers *header, return 0; } +/* Advise memblock on maximum block size to avoid stranded capacity. */ +static int __init acpi_align_cfmws(union acpi_subtable_headers *header, + void *arg, const unsigned long table_end) +{ + struct acpi_cedt_cfmws *cfmws = (struct acpi_cedt_cfmws *)header; + u64 start = cfmws->base_hpa; + u64 size = cfmws->window_size; + unsigned long bz; + + for (bz = SZ_64T; bz >= SZ_256M; bz >>= 1) { + if (IS_ALIGNED(start, bz) && IS_ALIGNED(size, bz)) + break; + } + + if (bz >= SZ_256M) { + if (memory_block_advise_max_size(bz) < 0) + pr_warn("CFMWS: memblock size advise failed\n"); + } else + pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n"); + + return 0; +} + static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, void *arg, const unsigned long table_end) { @@ -545,6 +569,15 @@ int __init acpi_numa_init(void) * Initialize a fake_pxm as the first available PXM to emulate. */ + /* Align memblock size to CFMW regions if possible */ + acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS, acpi_align_cfmws, NULL); + + /* + * Nodes start populating with blocks after this, so probe the max + * block size to prevent it from changing in the future. + */ + memory_block_probe_max_size(); + /* fake_pxm is the next unused PXM value after SRAT parsing */ for (i = 0, fake_pxm = -1; i < MAX_NUMNODES; i++) { if (node_to_pxm_map[i] > fake_pxm)