From patchwork Fri Nov 1 13:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13859389 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 64D62E6B27C for ; Fri, 1 Nov 2024 13:47:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCFE76B0093; Fri, 1 Nov 2024 09:47:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C80E56B0095; Fri, 1 Nov 2024 09:47:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A83896B0096; Fri, 1 Nov 2024 09:47:17 -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 86F596B0093 for ; Fri, 1 Nov 2024 09:47:17 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 35114A056B for ; Fri, 1 Nov 2024 13:47:17 +0000 (UTC) X-FDA: 82737652368.04.F2510FA Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by imf08.hostedemail.com (Postfix) with ESMTP id 6E32816002E for ; Fri, 1 Nov 2024 13:46:56 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=V3LMDSr7; dmarc=none; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.161.54 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730468778; a=rsa-sha256; cv=none; b=m9D6e6mqg26T5NcPSgIqfd4yHzwfNn0jmufePAJPSwRL/4xNhJsmwAwVMU8udA1hMimWJT tZrR5dNWydCSrVew3AHVku77kbc2dX2BOF5hA9SK5s55mhsWDCMyDEVi3w8Vi7YwUa42P5 ZiCPZKXT+/GX5/ttxB9bbeSqCXaaENk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=V3LMDSr7; dmarc=none; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.161.54 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=1730468778; 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=958SxrMmW3i4D+ZplSVQbEZWrtI+ztOMZMWNYttFV2M=; b=ZU/cS5pjw3lfrgq5XbNzvMiFW2JJd2AChGHFTpv2VUZRgWBm/6kP2lATbHpieOJJRXNNNO k0rb4aedRiE93ExkluDQsQzkRq/USOEBKx/O8I55YCDR1psqUqFEDoXUfyn232f/ncBjpB yVFrPYfdYOdVFYvnnGdnxMzi6zXmy8s= Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5eb70a779baso983768eaf.1 for ; Fri, 01 Nov 2024 06:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730468834; x=1731073634; 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=958SxrMmW3i4D+ZplSVQbEZWrtI+ztOMZMWNYttFV2M=; b=V3LMDSr7tKd/Tzl35hKLb0tToyCUVvmUoFmt33XSTq4ZNSHw8V3JH2Y5d6KayTIr2Y nV4/6VtrSmaVrEZlQMFtpZtH0iP0klXbMFhwRMz/izUsIQmlMaPMXOyVwu6IC+s6ySUy L7C2XNxQmiUTEU80byHhF9mBfno4HP59g1hWfXIr56R8GHdRfs3mfH6B/1vF5glrd4pS nX2uKDcaJqgDRvl9v0R4b8y9p7XJAf5Hmwhu8BLvv34HzlsZocqY+I6Oe0xd8wF7oOxN ww081MIapWgd33Jo18tcEDPPYkR0NYHTjwEvAIjh3tZv4GOwZIOqv40cck2jHU0QaWwB vZxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730468834; x=1731073634; 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=958SxrMmW3i4D+ZplSVQbEZWrtI+ztOMZMWNYttFV2M=; b=Fqt0DrIC06FLnE9TXleiN+PLIigC/O/zf6TZtpnCwt2ktu2Oqn9vSn+hry7itp2i2+ n7TmYxu15Ucc/fFf+nKY6CvZw0NOvU6/ZA1tMaQQLtNY+KpEk6dHU8NmGuoqbJGKlhrx I1drD9eiTLvME3o/FZk4/aZ9BcHo5UPSX9UcngcfBIsZbwlHyLasTTPnInEqnW5wbM3b duhN5uA4+X/LtyCShQata37hPzM1ZxHI9GmC8g7e0OX6Wn3rrfbXT1969f5Q4W17RS2Y 934uqOzX5ZgC0ROY1F9ovVshJmK2BwJ6EYbWt94YHQ96Jz/gtW4xYhARlCYYzsRe6Zbc A5sA== X-Forwarded-Encrypted: i=1; AJvYcCVnXOslKOP9nOJFJhuz8cE0DBCm6SPSxvYirwV7MWRMIrWs5KdJWmc1OeCr4XhsjYNf66WgHF5uQQ==@kvack.org X-Gm-Message-State: AOJu0Yxsqmy0oEXneKEf2a1HKXx/MbapRRBH+txmw2lw2kQoPbZbXRHJ 2E/yMAXkdkrhVS16B0X7TKeNROGzs1oZnIimcb0X+xZ45M7nc3ZsbbmYfExR0Zw= X-Google-Smtp-Source: AGHT+IG2zNy5gFfziJXkBV7+Rtit8XCDlH0hFpywbEzbxKc71T+qTweXHMmo2vX3g3z1Usqutl9fyg== X-Received: by 2002:a05:6358:248c:b0:1c3:9144:fde4 with SMTP id e5c5f4694b2df-1c5e32cc4c9mr790146855d.9.1730468834126; Fri, 01 Nov 2024 06:47:14 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com ([50.193.156.113]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ad0cac07sm18840631cf.48.2024.11.01.06.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 06:47:13 -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 v5 1/3] memory: implement memory_block_advise/probe_max_size Date: Fri, 1 Nov 2024 09:47:03 -0400 Message-ID: <20241101134706.1185-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101134706.1185-1-gourry@gourry.net> References: <20241101134706.1185-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6E32816002E X-Rspamd-Server: rspam11 X-Stat-Signature: mmnho63dwwwnb8xekq6g9c7t7jynq47t X-HE-Tag: 1730468816-537765 X-HE-Meta: U2FsdGVkX1+xYWc7NJoV19lSvmHIEbMaSf7qlN2yytZPBXNu0dWVVV2jXl4f7hWyRotP+OyhWJ+scwa4FJzD/pXMvSIIBcYf2C+CVe4B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cvn3xS8DE2S7Hg2/wOvnUm9+X6hsz7rBDEiDPXS7INMtNce9T28k3H+NZ7NDNaBbt6a0/3dCIa8OqKCxNKtdL2SrBjZrcxRIuMHzdNBxNei/92tZVDAEiVLCCLPtj0JBgBakzOTJGiDt9u517DbyZEDLS0i4qBD5zRpJgIGF/f3/LmotHoH7qC6HDc2JHIs1wjxgV10sHhCLMrn7+gvlzWng== 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 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 */ /* From patchwork Fri Nov 1 13:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13859390 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 4FDC7E6B278 for ; Fri, 1 Nov 2024 13:47:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAA4B6B0095; Fri, 1 Nov 2024 09:47:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0B386B0096; Fri, 1 Nov 2024 09:47:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9994F6B0098; Fri, 1 Nov 2024 09:47:19 -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 78B716B0095 for ; Fri, 1 Nov 2024 09:47:19 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3666980484 for ; Fri, 1 Nov 2024 13:47:19 +0000 (UTC) X-FDA: 82737651066.20.935CA7F Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf04.hostedemail.com (Postfix) with ESMTP id 6DB8040008 for ; Fri, 1 Nov 2024 13:46:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=mSDpSc72; dmarc=none; spf=pass (imf04.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.175 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730468781; a=rsa-sha256; cv=none; b=JgGqfcgGr/hiIk8g/cRcIPx1eTNJLukkVY3/KQFgReXnxFkko+aQlNZ1Qd0KqQi0BJ9e33 nQnNovYajGdAsvEBlMeB6rwbzDS+VDN4+KI/6YoFlES2xUFneiBWpUq6hLxkuo0cA3Q6Ln gsX6vZgq5XAtCiQXfmXnpyzMgMx9iNQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=mSDpSc72; dmarc=none; spf=pass (imf04.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.175 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=1730468781; 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=fqBWIQFF5FQxg66rq7hDVwvrkSgx0UrsiyD8ZLE5CIc=; b=gY+l3FrSZav5x4zPBGXjm6+I/R1KC7OyfYNEs0/7wBeVSufA4cLFscn7TQ37pqO1zLH4xi 0ZFoWpB7ovil06QVw0lcIgAWHw4VlKr+YIoYuEzSY/tgzVK4a6RMFtAayhmNCh45iXUeE9 kTa99cGUjBlBXOXtE9SZ5bM44tiPmuw= Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e2915f00c12so1806355276.0 for ; Fri, 01 Nov 2024 06:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730468836; x=1731073636; 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=fqBWIQFF5FQxg66rq7hDVwvrkSgx0UrsiyD8ZLE5CIc=; b=mSDpSc72jzb29szW1caMxMNpaY3HlDP5wnC5B8T1CaKk3RSItWvaz80YQap319aTMD iU0dxG4DjnM8tKFfk1En+vlgjixiXST16hpqVuxzScZHuWogY3NrJSPATmDvLwZGpQSu zDdlCm+UPkzDaP5XoMrpCw/w/lV4IRPyiY4Cu8aygerAzI5Y4AdljeO20BQtF0mKYNUL buSoGCwCFl4HACPO0EjzbXAgTYr2tS1VYsVXF2v3ZyUNBfHieX1g6/O3ENCAq2heszYb Lz1npczblsUdtqxxjBhnwZ/KffJR84x47PRBYqVSapSqg6/qqQNju2/P61Ngm6EHL6d2 3Z1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730468836; x=1731073636; 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=fqBWIQFF5FQxg66rq7hDVwvrkSgx0UrsiyD8ZLE5CIc=; b=pLEfmbAoD9hhOUxNvS/FFakEH0gLzMWB1fyg6gFp6Q1xp2EADV9vFwkzK0XcvbAExu Dfv9kgzwp4BuS0CgWcXnAS/j4ozisRMwiX6rXHP16AFL7iSfZRuAgnponmCXKafak+Re X7XvvKsjRbVmjdiGiJ9WNkMlHJ2Pv6RNQJ0dpr3OSoG7P1Hmt4AmOo2JhBLl+F1mr1L/ KZ2C1CbWwhnBMxYILmyefTUUtSNyYJxehl+OhuzE+FBOM5hjMz9XF6NRzjAOW7gHhR1+ akR+1JbFQKijYBKsvW5rBl1zFKJh7kmyclvaBd2AVNveAQhUGoErUuNyEclqHmWBKKLZ tZnA== X-Forwarded-Encrypted: i=1; AJvYcCXAy8xew/Lg/tvnnF5QHDEo9MNPYlx4MMnFyRFawn4hzgIEFfcVHatQjYR+HUL6kZ66w1SRosEfuA==@kvack.org X-Gm-Message-State: AOJu0YzyGTt5iAHeL07hMQQdNnkcMR7wQWrXH+Qpj7RyB3T2ataVbJKo UaluAMf3bJFkG9olMNL79ShXWoHYStzEtb065DwxyW0ZPOT/5+Aj/UZqabQflb0= X-Google-Smtp-Source: AGHT+IHc7ueHoeZ78qtsNy3gd8c/oEoo2nOnDyxntt3wb0tJLgWmBDNYSZb05h7Av17dwgQfREUg1g== X-Received: by 2002:a05:6902:b01:b0:e33:14fa:2273 with SMTP id 3f1490d57ef6-e3314fa232amr169232276.5.1730468836506; Fri, 01 Nov 2024 06:47:16 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com ([50.193.156.113]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ad0cac07sm18840631cf.48.2024.11.01.06.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 06:47:16 -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 v5 2/3] x86: probe memory block size advisement value during mm init Date: Fri, 1 Nov 2024 09:47:04 -0400 Message-ID: <20241101134706.1185-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101134706.1185-1-gourry@gourry.net> References: <20241101134706.1185-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6DB8040008 X-Rspamd-Server: rspam11 X-Stat-Signature: bjkmhss6a49ta5wme83u5boz6ty8y84d X-HE-Tag: 1730468801-132885 X-HE-Meta: U2FsdGVkX1/CiY1g3oGY0xjdXnSv+ob4iW1T99OdSbCKNQBRFc7MKWo8PwCVYS0tpXAkxJpuQEl9QtBzh/WCHnQcvtmTqu8jQHh1Da/1ehsb/IK7W6Of4Z9tJPWGdxZhOmBiqvOvc7bOyspBPaf+/KOwcmvLfOGqan02zegua4O9hLdIuWEFzCUaCcxKoP63ysCpQZzDMzS445Ew4GKRmCg68EPRvjTikmXGVb41Y08VmG+G5mna9dbrih0EWm8/Be80HSmFRmRHYYJFidBJQh1vu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.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 Acked-by: Dave Hansen Acked-by: Mike Rapoport (Microsoft) --- arch/x86/mm/init_64.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index ff253648706f..f1a495e998ce 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1452,16 +1452,21 @@ 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 Fri Nov 1 13:47:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13859391 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 1DF54E6B278 for ; Fri, 1 Nov 2024 13:47:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E9506B0099; Fri, 1 Nov 2024 09:47:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99B996B009B; Fri, 1 Nov 2024 09:47:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EB566B009A; Fri, 1 Nov 2024 09:47:23 -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 613246B0098 for ; Fri, 1 Nov 2024 09:47:23 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D47BF40411 for ; Fri, 1 Nov 2024 13:47:22 +0000 (UTC) X-FDA: 82737652242.10.761244F Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by imf12.hostedemail.com (Postfix) with ESMTP id 320C940005 for ; Fri, 1 Nov 2024 13:47:08 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=E97ctTQh; spf=pass (imf12.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=1730468708; 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=Y+zdKugU7xiryBghEkTtjHu3m1t20HIVG0keEZ55skE=; b=lXebF/erAab2vcmTHrfqi1ayTln8+53rDoaJLLLEJAwj2iU50wuxfy54Kp407O1Zukp9E1 FDHGmonPrMCjcUe9nQpJYaah+N4PVmc6vOQ3QuQA7zLaqFbZkHfQfzJ9y8vB976VQIew6o T7iE66tEcmdugUNUynJP+cdnkGEttWQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730468708; a=rsa-sha256; cv=none; b=Rb1RsFNQJaipUVWz8UsY6w9wEQQjZVFY1Qdkg+h+GEhucLxP5dQ7H9vo7bBCJr75Ualze0 Y/JrM5BTWbWOuWUYCBg2isUnlPz6GVNUsBZXenwT2SxrNYEN2OOzDCtYkVJxSqExjH7z7D zfU5tLJwsEDakNY4zQb1wALpzyjVqY8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=E97ctTQh; spf=pass (imf12.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-4613162181dso12460551cf.3 for ; Fri, 01 Nov 2024 06:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730468840; x=1731073640; 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=Y+zdKugU7xiryBghEkTtjHu3m1t20HIVG0keEZ55skE=; b=E97ctTQhm9Amr628HMZQRmYI0qfow3aHnCgQ7khkfrCqbLFjgaeEQDlXt/27k0gD99 KLBsEVQHE1wdxOoxfCVsSN4o20eVn4qC5LikL8132clbgs9WyCKnC4XDIs7aOJIStFtl mk8VtlOthUEp05IBpCuPIO6r+4Vneu3xSnG0ZRtmXDUh4+RmW1zaxWimbca7tqq3eSs2 yhbhIXfXsDKHssB7SEdMrHgW4YGddDkSaNQBGBGXtzoixof7Iff1KSBkbeYmsM7XFyU7 ljmsKPd4qxxuH8Wr8ssBnYKpNW2hXRHAJ37Ns//JL3nU5QLnNY4/5SHwkbVdY/5Pu+k2 BaUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730468840; x=1731073640; 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=Y+zdKugU7xiryBghEkTtjHu3m1t20HIVG0keEZ55skE=; b=xT/hVHvY5cmP+Oc3ruM0LTE4/q1m4eG/DH2HBM7yisTSN85PrNCh1X4eL95Xv3tidS PnzvrI8og7gEQCAMV5oJCPEGhG5oL/8pRzle7tyFW316GI1+EKJ3c+X21YZ3NREMSrHf cxA40p0FSTA1Qgemc4rjNKiFrJ38TVp/75lCAPG/QTlIIw/44vIjspYojU5Um7YQjTQW 3t6IBGgm/+VOu++m395cPTt6Xj54CSJVDWL+vGC5/oAGYH7ETp9zB2zt2GAVl1l/LlPb h4HyfZM0QNRjnUehg1EYpTfnHWWFZWElMJA/OSuN1Qf7f0RTZRQtliFfvPh3VUenGPad QCYQ== X-Forwarded-Encrypted: i=1; AJvYcCXHpJJOO6gCAVkwSScAi7JhSWf0aUOYnopSEWZV2TXK5km9ptMPI5oiPNFYLkNA1WlrJqogSuKJuQ==@kvack.org X-Gm-Message-State: AOJu0YwD/Xric27CMR47weW3Vx5bQ1bwTV0tB+v6XKhldtIAPkyFOJrW 0Gsp4qsNqosXMi3P8lSeiRbMt/wQonyZoIuhi14uPaOYGmw+eOTTRGNY4bGoxLE= X-Google-Smtp-Source: AGHT+IEqYRg/5UZkjuUahc1kZYI/R3+uQRVmb1D8Hw7IJxtfAawWOive+EatrYV0MOKL9iMFUrnP5A== X-Received: by 2002:ac8:5acc:0:b0:461:15a1:7889 with SMTP id d75a77b69052e-462b8680102mr46144121cf.16.1730468840141; Fri, 01 Nov 2024 06:47:20 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com ([50.193.156.113]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ad0cac07sm18840631cf.48.2024.11.01.06.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 06:47:19 -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 v5 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Date: Fri, 1 Nov 2024 09:47:05 -0400 Message-ID: <20241101134706.1185-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101134706.1185-1-gourry@gourry.net> References: <20241101134706.1185-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 320C940005 X-Stat-Signature: ixn3uxp1jwozggyfbijey9j84riighjz X-HE-Tag: 1730468828-321741 X-HE-Meta: U2FsdGVkX199exFx0592/hgpuxutLNF3D0NWL67sMxtWaIILMAYHBmiPcw5Y8ip/KVLYaLBaKlGtXo3QO2XWSaX27d3h5OEwNxeZS1CGrLn1pXAjvDOLjfcH/3XHPBuz+/eYYc18417q9VEM16tobQllM/3eK0aOfsiP0bCx6hyX9KE6dvrwPBSGuV9gz/bH778cGaG8QPKG4TWZYI5iPhX7i/sQk7G2LP9pELFleg+EvjS4qSMtRRUHBg6M0H0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= 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. Suggested-by: Dan Williams Signed-off-by: Gregory Price Acked-by: Mike Rapoport (Microsoft) Acked-by: David Hildenbrand --- drivers/acpi/numa/srat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 44f91f2c6c5d..34b6993e7d6c 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,13 +339,22 @@ 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; int node; cfmws = (struct acpi_cedt_cfmws *)header; start = cfmws->base_hpa; end = cfmws->base_hpa + cfmws->window_size; + /* Align memblock size to CFMW regions if possible */ + align = 1UL << __ffs(start | end); + 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, * or a portion of, this CFMWS HPA range. Extend the memblks