From patchwork Tue Oct 29 20:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13855353 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 8CE8CD3A697 for ; Tue, 29 Oct 2024 20:20:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FA256B008A; Tue, 29 Oct 2024 16:20:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AAF36B0092; Tue, 29 Oct 2024 16:20:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E54446B0095; Tue, 29 Oct 2024 16:20:47 -0400 (EDT) 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 C70936B008A for ; Tue, 29 Oct 2024 16:20:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 769A314064D for ; Tue, 29 Oct 2024 20:20:47 +0000 (UTC) X-FDA: 82727757378.26.4F8AA57 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf20.hostedemail.com (Postfix) with ESMTP id C16541C0029 for ; Tue, 29 Oct 2024 20:20:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Tohjcm6H; dmarc=none; spf=pass (imf20.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.173 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730233116; a=rsa-sha256; cv=none; b=aeCvKX9wycBvOVgGU/WMkhaJ5m/ms+wZoBeoVIKPim1tH4qqlhLo96VSEQyfZJq+GT13fn Pg4khrc66mSZV5K6VaIZGb/jMvl9b4vcdleFL5mpuv1hGtmZM7HLWSzBCeymBIUWurhiOf uwZ1MFtJGeOVQZJT0InMalixFMVmaHM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Tohjcm6H; dmarc=none; spf=pass (imf20.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.173 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730233116; 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=yYJpDly5fR8R/Ele1I4od50o5TfHJqlCfC6WSHHqe0A=; b=aFQ/8F/f4KBuHf1MulWkyuFTIE3HTuOh6z1fklTeBcVZlgyNwv3YBY7mtaL9nSMh0Da0Mo pF6QJLqpX3TSbZ4LctcexD/4K01+FPj9vu8sV7/hRSIIEaxuKFSsOUgShS0wj5MD0MHsWf jYACNywvcBq+9Kx87jnr4+hEGyND3BA= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-460d1145cd8so46188821cf.3 for ; Tue, 29 Oct 2024 13:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730233245; x=1730838045; 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=yYJpDly5fR8R/Ele1I4od50o5TfHJqlCfC6WSHHqe0A=; b=Tohjcm6HuFRTZj2DGFHcoyYQ+sJXOFCisK7iTwDQuxK/gtSlCZynXsjwi3d+eYo3br L1LKvuMVWkK8oIfMElwnOq4mopOvgKYcbUBzED4sm0DYFj96+SrB/NPlcboXc/BMZ476 Jw4B3hk/uI4qZdXj4kFddnyqeLRf9jNcodaTGn0QgdmLEWSop3FmOli7m0VPo0HYblF7 qI7dN9HYxIxU7lHnNRJpDjpXCJ6i+Nv1Z2T0SdLPnrTMhGEaesznSvxoHAb9HFC0OpuL J+IeRU3tMRD0fkd7T3YjHTjg7nSF7ciVbJiRP2j/jiM0Gl9LtM7T1JqK49qPeoBq/q25 gF7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730233245; x=1730838045; 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=yYJpDly5fR8R/Ele1I4od50o5TfHJqlCfC6WSHHqe0A=; b=SJ+AneKdRbpxiBlCBOD7wr72qLGPzM/a5B8msLQzOZoqSq6EAIkW01DBEWazuLXNea S/nCp6UtKcfm5MZGJq6R/MkaBXK8mAaPSvDRVuytnfsG42tkb7dOot02zGKXfkPN/VnN L/LJHoO+cEgs8Cty5Lmhf052/CVE+makly2NFHAG2dMfFHpXpcbjNCXGIQhsmjy9OHCy qHXiV1wW3uFxQ1JeX32cTOUEdKL8EbuLKiMYIlmqVaeXHB0qB4+sgLiYtlZgev47aclo TGlJuTUiuBiDsdQkMbsNN0m+vm/+e3Z8pKhFyof9vYUAurxVMvdUQPvskcy3NQrRJk8i Pjmg== X-Forwarded-Encrypted: i=1; AJvYcCWBfoWIUMf23lGSGZZ2ec6ljiVsZ8pmiwtuArI3LV0oWBPh1+VUEHi93Ufzp78A31+ql+PPm0Mrtg==@kvack.org X-Gm-Message-State: AOJu0YxXtNXcwkHP/OuNMjMKoQ3RLFJ8vR9Xzr3UZ5qqIva/rJnU/Ss/ KCz2d15GoNxu/kKQhvkWRwSHAw5GIf5KM7+R8ClXDSut6PETEKbgNC2+XDZEZaY= X-Google-Smtp-Source: AGHT+IFEYRquwMMLuxm/I3OurD9YlNDiDcPqhW8mBugt6yiiX34O6cvjwJwhU0+zT5zZPMP4mvN4Qw== X-Received: by 2002:a05:622a:4a:b0:460:a287:2069 with SMTP id d75a77b69052e-4613c036755mr178235441cf.35.1730233244725; Tue, 29 Oct 2024 13:20:44 -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 6a1803df08f44-6d1798bd8bdsm45071796d6.54.2024.10.29.13.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 13:20:44 -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@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, 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 v4 1/3] memory: implement memory_block_advise/probe_max_size Date: Tue, 29 Oct 2024 16:20:39 -0400 Message-ID: <20241029202041.25334-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241029202041.25334-1-gourry@gourry.net> References: <20241029202041.25334-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C16541C0029 X-Stat-Signature: def4ddy51nihy1og744owyqw7pk3ep8r X-Rspam-User: X-HE-Tag: 1730233214-277828 X-HE-Meta: U2FsdGVkX1/4EJrUroUMg9oNcIESklkITXW4Z1ZmDkPPRICcVwULuJZ1Wq0W2QmQgEaZodA5tE6dG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ZQmZKnKrGB3j3fTuqkKeQ1JR0Pf9Kodqe8MkUKMS3PTF92MtJEWiMVz1eDzqwdkkHnHhUVF9VJ7J6eUWHQJUuThPyO1fGbdtuPOgp/cPfCCIfdM3vgLnO79CQqvpyb2PsXW3o0clwydumrCXLR08BG5mhUU1lu3a3z2et3J3AOLXykpwQGUnuCbRvwj5xrvZl4LDgboFjVKkvuOTgULfw== 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 Acked-by: David Hildenbrand --- 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; +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 */ /*