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 */ /* From patchwork Tue Oct 29 20:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13855354 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 81584D3A696 for ; Tue, 29 Oct 2024 20:20:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0AC26B0095; Tue, 29 Oct 2024 16:20:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D906E6B0096; Tue, 29 Oct 2024 16:20:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B47346B0099; Tue, 29 Oct 2024 16:20:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 92C846B0095 for ; Tue, 29 Oct 2024 16:20:49 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3D4B01A05CC for ; Tue, 29 Oct 2024 20:20:49 +0000 (UTC) X-FDA: 82727757714.04.28388AF Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf04.hostedemail.com (Postfix) with ESMTP id A7F0F4000D for ; Tue, 29 Oct 2024 20:20:15 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=f3wAUqPG; spf=pass (imf04.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.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=1730233167; 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=RLCkoovWy+4BTP/Blm5LQHaaqE7ZHx2x3Kcfu38vCw4=; b=SjoUCf5I7SV1LdzZ43V5HRvuXBbcWcPXkb6l03FHQQF3d95wd/qs1Gh9TAxtl2d5MgHNvU 0uxqepHFLjQpWcDp2EiipwCzdLzpGXMKUoDInWuXt0+pAZ5v/T4iz3wlcP3oDcNCLgsnsB 3MMT33rinXjTP3rDbDHaWDRCu96xXAs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=f3wAUqPG; spf=pass (imf04.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.169 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730233167; a=rsa-sha256; cv=none; b=g5yPhd5BJU8qIIlbMTjxsP5/vg5N++jJNfe3BzPfK3Luzz/MW4XtXKNBwQROPB6dJOtMZg pNgZm3mgcM+vwSzlLw3JfS47ax2jLA+leXAo20d5ey18nPaKfeD0dQCQc9FAKCj+aOXR7g rDuNAnOghNFjpVDXkizMBdtxTpyyZ2Q= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e29267b4dc4so6151581276.0 for ; Tue, 29 Oct 2024 13:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730233246; x=1730838046; 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=RLCkoovWy+4BTP/Blm5LQHaaqE7ZHx2x3Kcfu38vCw4=; b=f3wAUqPGxii5ctekiZttzG/CVqRg5d8Sg8/PUp6TXRKvJnrozM4rtc1/GOe8GiL7hg qSqVP4LueF/vzb52XH0jopHISM28XOaPwve62EMTdXBg1lSn+VBN24t09nnfGpNt3JG5 Ql4mi5hK988l54rZKEi0iHnWLdyAWEsl99YM8n31UwrA/bKo2XIvdkLfRyMLhGT+XphE e4xEKGYh2kgoXTCUA3DRvUWkSFaLEh7LPYNS0okXzLwHks+j8ZLlnBomkagu70OFMQZz zac2PhW3TrI+jGJlpadpcTbCVszQhI65ZDCvuYW8yOjYAiYntHt/z/YxW1m1Xy/UMxMQ LreA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730233246; x=1730838046; 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=RLCkoovWy+4BTP/Blm5LQHaaqE7ZHx2x3Kcfu38vCw4=; b=QkgsykkCaHlh1d9XbeeC+Y+MKX0E2BsnXOBeo+zBC2863gJ27tUMrsSI2klm6auk2C 0G/735e4f21/oJK3E/bQfDswvy2mm4xaLgtZPxYwgd80qJCWD87l8TzrFL0ZgkrD16OV O3TlWqz90U4AqEKRmKvuhXiTBeiLi3Eezr3vG5bAc9og272KHFkubvJ9+68H5jVmGDPJ 94VFiYvbDBb3psFJYI29LhVuG0ofgw5ERqs55u/gvFoTcQM+PG8GVoIbnKwi7/k1gAJo 1mFf7mQHzMT86x0HUOn9YjIxD4sr1q0ZVKY7INsloRJxqzmdtkvLRoNH8I7GXF/gf08c x48w== X-Forwarded-Encrypted: i=1; AJvYcCVBgzp9dCWTL4VStWsAzn2PuG/JXSsEP9LAJOlrdbsLWEwV19Y64/K8rIFjwvwPiJA8WQG+bwKTEA==@kvack.org X-Gm-Message-State: AOJu0Yz2Rw6wvkIzRPAm1CQsW8Yz2rgiFxBHT+uH9eOTibijJAO6mZk1 l7gKx5wsmwJGZOvxDQRx3vD1Z3j/oXtp/w4PX8+YPBAF6B3gOhjYi26jnd9EhZ0= X-Google-Smtp-Source: AGHT+IHrVUT2Y/bn1A2eEhZ3B/4Cio2x63OgV+iZejuf4OHZLNTMyIcoastoD+p+X+Hd1T8kconCzQ== X-Received: by 2002:a05:6902:102c:b0:e30:c8db:34cd with SMTP id 3f1490d57ef6-e30c8db3652mr2549661276.3.1730233246317; Tue, 29 Oct 2024 13:20:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 13:20:46 -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 2/3] x86: probe memory block size advisement value during mm init Date: Tue, 29 Oct 2024 16:20:40 -0400 Message-ID: <20241029202041.25334-3-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: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: A7F0F4000D X-Stat-Signature: 1khniza56znb56ad8qjfotfy3kzkhwju X-HE-Tag: 1730233215-3052 X-HE-Meta: U2FsdGVkX1/Y4tvyIjEl6yAwUuz8dJeNG/BoR7uh4CyKtt5PSXfPhVnt+1a6NYZqNXBsUzq7MjsrBbBi3NsLOw28ymalcYqnA0rVsDTlHLgYzHXuhqUoGDPF9xOozDaVAU7Xxe85MJ0p5WdodVgl6FVn+Q9+HkD5BCjPg3Q/aqxuRoeU4mwdh9WiyvKjKhAFQ0YjvNWEahOI/8LpyazJlFERiQluW6osVUMpmo8Did+tRom4G8X+zNEFPS1iIZQXW2pBiNPwgXsxGacX9xdOqd8g64trVTHuZeIzGZCImZEM+ZQVtO54J7SYUKoS+WguUNfUbxm7dbxydhhqZRmEpCC/NxEyOM+LbBumzB46tx3bEruIqvtzkAJGhJgc0223c6Cq8wrQAKF+TK5rWJve9bFLdNUULPlhcppTGmVEI6blUPt/uNjZp9cO5NHJ9+0Z1BuUx2OqnHK2Bod4LMhW1vHZwAZh12heQdCFOwaDEKD2DP7l/Z2U5lcHE42lscbsvZq3Kl6UANBomq3SqScWQ70swh+St3y13HcmTuCAtQTIrVzsvkFtds1tv2yzCUJub7zgSJXXXUe7gEDOaKPMOYcOIRetu44YRo09vpMylVIpGHAXbGOgo8VLy+oc8XR6a/qWHMYaBN2CtTR6MBEqgMkgkGk2P2R14J27oQEpFBIvH4W7QKd4VafyaMfxv/ZSrJSXqNrpd2WlBPuxPvsm83TH6uAMiP+LJ3DjhNH8FuysIkgQaovbRTT4sWEangoILh4+fGYVMMHnBY1oUtVpBHWBA7jJ64t1+/yPlQW33pA+XUFxVES3ZUhnI4q0NFRX77/3vfFG7tcQs77S8JFJeq7lkNUbVq4qYvGvZbUNMEbPuuvylJ6wEoLix0OdEsuGVQ43fJktC+uMZSTAWfFUQJLzGT1oYxYM7kNURQ33wdB/jxsSKiREs9DaAJLM3LC1zYruhkSxLQDY5cvILVZ pBjo1SyN AbFgoVwIBut8dhLLrAcwVeaNx05MaAGCA6F6bsDiy4t1iKM9e8qSapuxtHPjVew+d/yAYIeIw1xF9n3Q4vjcgS+jRLodh6YFDMx2GDkqlOuLmeYIrJUoP77qCcfAbzjgXqm1XFilU/hZ0UojtjdHQsGw9JpBGM/lZyg7CiyET1yM9UcpgI/voz60qKvp6R+RjM4cTVOOmoEJEtL9ESqS+43iaYZRdbF5o72e2OhlkNsICrJFd3hNxGuw0ojF+WCv9ujqil6B6u8WlXlmV4PxOOiDLqFnQDTa3OwS/N81T79HlWgm+IDh2xHZ4MfH+yESYwBGQ7lVYqN9bVg8= 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index ff253648706f..01876629f21f 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1452,16 +1452,20 @@ 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_advised_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) { + for (; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { if (IS_ALIGNED(boot_mem_end, bz)) break; } From patchwork Tue Oct 29 20:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13855355 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 0ACB6D3A697 for ; Tue, 29 Oct 2024 20:20:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B4D26B009A; Tue, 29 Oct 2024 16:20:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30B6F6B0099; Tue, 29 Oct 2024 16:20:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C1296B009A; Tue, 29 Oct 2024 16:20:50 -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 D72266B0096 for ; Tue, 29 Oct 2024 16:20:50 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7110FA057F for ; Tue, 29 Oct 2024 20:20:50 +0000 (UTC) X-FDA: 82727756580.20.1C85489 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by imf29.hostedemail.com (Postfix) with ESMTP id 0871012001C for ; Tue, 29 Oct 2024 20:20:14 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=rBilL826; spf=pass (imf29.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.50 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=1730233088; 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=Oy7XVkWRraFdetQ8jpQD3fWOiMh3kGBraLt2py6f48c=; b=Tphg5ShEuF7u47dWL0PCDCXx1RpssDuENXyBxCSfBRfEiPPwz2auUqZOZ2huCM6rBP8/Uj pNxZ9UND8JMEKYtTLKYWjdODuugZYUTeVWhao1pmjL07NLEot7rF5O4g6jZ110FNV0SiA/ ngTEMPe42y19VAI51sBXmNWn8Bco5WA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730233089; a=rsa-sha256; cv=none; b=etaRlLmobEWMqApTvJsCyvQN+G1UjPsarz/jfCvpemCQciDWGIRcWafB7iRnxKohJzlZSg cdDHD6MfmNxpHFsvfNWENkX3eyYv8FNAgA2YkUfhRfTMQElLCFoKy/RM5jiYORXL52S9V5 d/KxDsLGdz6nNuR4etIdffR6pbWvNSc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=rBilL826; spf=pass (imf29.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.50 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6cc1b20ce54so47602776d6.0 for ; Tue, 29 Oct 2024 13:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730233248; x=1730838048; 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=Oy7XVkWRraFdetQ8jpQD3fWOiMh3kGBraLt2py6f48c=; b=rBilL826n2JS3Hd4AWknLgUwSeWO9tCyhog6lwqm00IpEytqJ1QR5+Oi5t/wfZsSSb MIVHoTbj9YXAL864X5hoe9HJrHP8uywNXprS4hT7lx8pLAptD/pPnVEqSwghfQslH4vW QmsCC5q6dlycx9evbo7Gm/fOt4YJy6gHZNdbc+SpLgHEjZRVBb56wTK1cWBHfWwtHka3 Tcfw3Q7Jfw06wB4uZF03SNSPDWSLq81/jtuLC1YMZtb3ISeEQChNyUYW7QKK66Bx9XbR P3e7fMhc7ZYTxMJMm5RTdfM5M8JX9V+l5I3EvO5zcCERbwwgINTDjGkTkTh0TXzhtSr7 pe+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730233248; x=1730838048; 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=Oy7XVkWRraFdetQ8jpQD3fWOiMh3kGBraLt2py6f48c=; b=PmV68yAUT89kW7LUyyR/bcz+eWZQZ/vF4B2tFQlLJAbO30FmUx4WJL6OWcWIyl2q6B 6+6pEWjF6SN36reJeVoY1rriI73n90RvkwX9sp3/exfsg2Kyu36AONVHi/JUulo/FWg9 aXnjrG7ISGgGOo5t+zhIbgdfDETmAP3a5cA8rMe7/3oU3aGCW4eBCT+EypxrB+VUE4Yt zsbBPdtWAMhZ4Qybc/g2fVoq6Z9qG/QN8rYz26k4bXKm62kxBjUpKbjRIoe9KLQqhmuV xiNHSsr6D0c2g/YSlrCiSqXlBhCyVoJiyBNHaaUUnyFqWErYjUfHB2lJhDMdxBHGMgIi CwUw== X-Forwarded-Encrypted: i=1; AJvYcCU7LuSsrSFyBr3y0RmkY+v6JYM5WTdcqT+tNK1NOItH3vnrEtGknhcDZVN6PB2eruv3nuYjVv+XBg==@kvack.org X-Gm-Message-State: AOJu0Ywcf9w9mKXbZwCem5LAT50p4bSj8gxX3puMcHIbzca4g7q5e/O3 2kHBEybsL3znxkxIROTi0k7W7JU2F9wFgkEGTKTnUTeVxbZ2+7RrdHuSB99lsgo= X-Google-Smtp-Source: AGHT+IG8wR2VNJGr8w4nEF8K7TLnCCm88h4+MvvrazJR7tXK1WVS/iZtDKaRFV9lJM5ZTXQsS64Xjw== X-Received: by 2002:a0c:f40c:0:b0:6d1:7434:55a4 with SMTP id 6a1803df08f44-6d1856c7483mr158035446d6.19.1730233247766; Tue, 29 Oct 2024 13:20:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 13:20:47 -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 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Date: Tue, 29 Oct 2024 16:20:41 -0400 Message-ID: <20241029202041.25334-4-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0871012001C X-Stat-Signature: inx8388yopab3shtuskp3m8i4s7xm98p X-HE-Tag: 1730233214-139049 X-HE-Meta: U2FsdGVkX18i4Ls3T+XCFPp4bnVCAM3Bmyo1W0Gk6iIxvIHd+9HRDsXoiqtYKoN+9KOrXD0x9e8LzKVOUTbLUetkZ8wW5WL1DmMHSS2j49akE5mxDAFf8lLHvd4vTM4gJ7HE2jKA8run/rBdAJVZLwAlNEaNZF5NksiTotlRuAnUVZKkIZ7TOdEmMR/X83zEgSiTxQF821y70DaPkYFYdt9+DJ307ONKol0MFJ4YJM/i6s6Rv6GPTE+LFb1Pcm23Fpjup3U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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. Suggested-by: Dan Williams Signed-off-by: Gregory Price --- drivers/acpi/numa/srat.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 44f91f2c6c5d..a24aff38c465 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -338,12 +339,26 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, { struct acpi_cedt_cfmws *cfmws; int *fake_pxm = arg; - u64 start, end; + u64 start, end, align, size; int node; cfmws = (struct acpi_cedt_cfmws *)header; start = cfmws->base_hpa; - end = cfmws->base_hpa + cfmws->window_size; + size = cfmws->window_size; + end = cfmws->base_hpa + size; + + /* Align memblock size to CFMW regions if possible */ + for (align = SZ_64T; align >= SZ_256M; align >>= 1) { + if (IS_ALIGNED(start, align) && IS_ALIGNED(size, align)) + break; + } + + if (align >= SZ_256M) { + if (memory_block_advise_max_size(align) < 0) + pr_warn("CFMWS: memblock size advise failed\n"); + } else { + pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n"); + } /* * The SRAT may have already described NUMA details for all,