From patchwork Mon Jan 27 15:34:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13951560 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 6BC96C02188 for ; Mon, 27 Jan 2025 15:34:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9EDE28016B; Mon, 27 Jan 2025 10:34:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4DCE280165; Mon, 27 Jan 2025 10:34:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA13728016B; Mon, 27 Jan 2025 10:34:19 -0500 (EST) 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 A5239280165 for ; Mon, 27 Jan 2025 10:34:19 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5C9CFA02C1 for ; Mon, 27 Jan 2025 15:34:19 +0000 (UTC) X-FDA: 83053628238.26.325065C Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf25.hostedemail.com (Postfix) with ESMTP id 844CBA001C for ; Mon, 27 Jan 2025 15:34:17 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Rqn70QIM; dmarc=none; spf=pass (imf25.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.48 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737992057; a=rsa-sha256; cv=none; b=U+faKga2BJixZVS+yO7vfa9SxPa0Hk/Q6uTXfRxq67K1Qwugd+UBJFyUAZPAEV/dqI3PcZ h5QFJPe/rGNXMbAXJod55TfOJcBqrj/sXcZWjcfb1NbI4RpZCK0OoFzYmPLOZTHHN314HK xwATkaoZd3O87EsaYmL3sNmg0zvPGcc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Rqn70QIM; dmarc=none; spf=pass (imf25.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.48 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=1737992057; 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=cuGLm5QAWvME/iYTUeN4C38ZerEmS6SWYSvNtkJw+ks=; b=Io9VcEL8h0sq18ze/qO8pj77LFVKE0ect0x2VsXqqmucxBTM7omlCJflQweCIhszrgl1KC Kv1t+PzU01Ni76SMDwCQb5nkmbZGIz7rFHGCxN3EDs/Akr8gi5o9WslJxouPLcnADRoC4r lSGGbNV4Ay68l0h36+d4BJmjWsctqXU= Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6dcdd9a3e54so46012226d6.3 for ; Mon, 27 Jan 2025 07:34:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1737992056; x=1738596856; 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=cuGLm5QAWvME/iYTUeN4C38ZerEmS6SWYSvNtkJw+ks=; b=Rqn70QIMJnJTEV7hMUuucrhC3DzpmuIlaiIPHqYIfZmGL5M6F3nEpxnukZrxqCtFaL bRZiJc5yNV2+RIG+gn+Mn7ryOTkBlN3938Iu7fWYe0YKjRFw71j08O15faFUv7zZ3FQO 6czG+fa/59Z/qYkMCWV2tl1W5hpYK9d/ekpWfIThhCBtB1eJAcCsj+oivr+lTEyoHNMk LsdVTlirbdMzCYCQBX0J7kgIxu25kSs6yCUTqh9A4btuZsRjAzM1fYlkpxQs67s88+Ho SBot0FCl1wRtAljclyX2XcrLgvDu5W4KdNz9zWUPJng2AIWsYiLVPlYNZYkq6ie0zNed 2f3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737992056; x=1738596856; 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=cuGLm5QAWvME/iYTUeN4C38ZerEmS6SWYSvNtkJw+ks=; b=fYh+MSjO/a2V/QeN7HhxDplrJ8kx2lgjs2yL9aGa9HWRe/v15T3NftOVlDJdDNJOIH /uQaJitafjtDXqQ6VXlvPxEswYKdE5HOLNV4DUL6rFvY0DAd+LqI6c0CH/lVlm548xSv AM/ghj+uGOXhA4DQaE6ZIcIRYDFrR3CW+AsfByP/lEmqOyaM5LGDxc8xjEP0I5ye2piD omQn5vnVY19lZatuxEbk7w2vzhIlcve/9d5JQFlrXfcc1z2mn4Aqw3UEUPNYUWVhF+Nb eNwU7kMIfYzyreCm/CAfKtQXKhLinFJhOFCl5Doct2kifJXMQbldbUyrkuOiA4i13JXh +Rpw== X-Gm-Message-State: AOJu0YykBVjScvbh8PyOmjrasIfKOZHqgXVk2m9WuGFmzxZbdKv+CcpH AUhv+1jclUD4OOKUp1TEfzkewtStS7Zvu5kUoKWI202NyE4qj8502PDd4Gjs+AtpHOUAfbjOQ+w + X-Gm-Gg: ASbGncsL1attJX08qXhTS+wGe3tGL7wDCZ0VPIdU7n4B785BXPrzhM4X3zfljDSI9nA oel4n5yGsq8goTyJ4fV7Mb/gekUpC9uwBfOICIYnVnQCKourB1LP/maOzPXK0HvQWuiToRPlqgA MkE2CuVvcQEsQ3+RYFM0jsARYuMnKgtG+2zqotZ2FS6Yx/2S9zmQ/uaaYU2Cqln3eV+vHr+Aglc Vekyq+SdOZAxZLz6MTOOqiVaFKI4RMQR+E7qTTNKRNJ/QbUjQB9zGh5hbbexNmz1RA2eX49519o G8nMqI8TdszHHjlt/66L38GI8ozETsd1jAsPSt+Bl2irjnQyzILPwPmCx1+h1iqxl/g5 X-Google-Smtp-Source: AGHT+IH3YD2uq0s2UOyUMAffGvHi1zghb5NCWsDgLZca9QQje9OVBrkdwmDEWT3QH9fizy2t68UjHA== X-Received: by 2002:a05:6214:1248:b0:6d8:b3ee:8b72 with SMTP id 6a1803df08f44-6e1b2229d49mr616446186d6.32.1737992056362; Mon, 27 Jan 2025 07:34:16 -0800 (PST) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e2058c2a51sm35380476d6.109.2025.01.27.07.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 07:34:15 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org, linux-acpi@vger.kernel.org Cc: kernel-team@meta.com, x86@kernel.org, linux-kernel@vger.kernel.org, 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, dan.j.williams@intel.com, Jonathan.Cameron@huawei.com, alison.schofield@intel.com, rrichter@amd.com, rppt@kernel.org, gourry@gourry.net, bfaccini@nvidia.com, haibo1.xu@intel.com, dave.jiang@intel.com, Fan Ni , Ira Weiny Subject: [PATCH v8 2/3] x86: probe memory block size advisement value during mm init Date: Mon, 27 Jan 2025 10:34:04 -0500 Message-ID: <20250127153405.3379117-3-gourry@gourry.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127153405.3379117-1-gourry@gourry.net> References: <20250127153405.3379117-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 844CBA001C X-Stat-Signature: bytgrty51qqqydk63315uparmgh98etd X-HE-Tag: 1737992057-432039 X-HE-Meta: U2FsdGVkX18Br8WFFl3j6zZSntlqVGuS+uzKZdNQBCoNStI8H5940P3jk+gwZIsxzkFz5OW7bOxjgurmkg8fiCmhAwIokSiHrPKavotBBrnvFLP/iONqOaB4LQgRKhwBHRAxXNxy7rjTU0F0hQAr47omDMmjNQmI3yLCZosR0K49aj1grAbcN3GYF10UKLlmMATRoeCxVRvEMKYPdNTtoXt8nIYPBc3eopKOxZtr1gIoUZIi3DUH+o8gWcwL9GCd1B8Jx4AUZ/yBXMUB8WaRD7jlyjhTyM8+u2K3G2MW7m/QKkqKFCt0122AEoA8yOLCvUNAdpTQZjzTGOgAot3w76uY2kR04gnmTR+DQ9IDH93HLCSOrCblDkUYluNzxRZLjq0iTkn8SiEnJgaMzUJv56ZgWaOfYv3fPjFc9qjLF9YS/j45b772SiFW7zoFxm8mp4wjXRysVqDE66QMXd358RxehNsLyTAKf1eo5GzrFbVoZ54dAQ9lkQKoWhVk5YKiH96mtbu9opC3wBRHPb4YhZkNnslXt04IGaePG/cJGmudJUICHBQ7pkEVXfyLRN3DFWel4QMKX8jAN/zpz6509qsklrDS3+G2Y6hVIiGHM/4rnT5LE0wNuWPwrSO2lJRPcJaFNtKQ4UZQqVJUjENFgH6/glfGnv9HTtb79PpNVdXggqJY2vUThRiawMkMzmTkgy/YfMCDbiBK/nqIAjE7Vr67lKLLDUPiwEoNnA2bElH1Tnk0fq056zqoEKIKNIN2hJKHNHd7z7u3Sz9oFjJGhdMZgMQvHBvhGWRYgCXrnhFMRaWH679rbo2j/0N9bqF21v6qqyVMSFP/MS5rICflrRn0Mdql+HXhmhQPEwN2sy1MEHYj9/nBEC5pN/tA0xBXAWGioQ9a4E+P1a0Rl6TdIdCubwM+Fl54348aTPfaqsQ8Kq5S+lcjOEAMKIPQLJI6TiBSwKu8oWrlgmzefIz y19Jyw5s Kkuo6BQm517cyJEIdRiVhhGXRNR87D48TEKt0LKE1qiql0ihFEiIbIfVTkArQ8YjzVPSbkR0jKD39+OMFoaAnp2haXp7RfTdpaxFTHdIOiae4JTcSuRX21zE1poQa4S+JFougZ72icuGupPjtW0WHJIh8VqvG0pTApLomKLXIVffIVBi9vomYXic1Gqk78z9GExHdPc2jr/uzWD3WDTb/D7eXkFzqF61VpK5D7nD+eIxethoEe/f7LHYWE9YQ0NaK1ZwWy6Rs5QOEMgu+mr61Vc8MEEcwbc3d4w/oMMN8OVyEMAr5hFH+JWIcTQ0Vxer6+LfR+rXJkzlo5pqIc6s5DS+bgjwwboo1Wj807p5goVWDIsD6lV7BBgH6vjqYs+iZrfZ3ipjh4FINSCJN+K8Nzl8Tew== 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. Convert to cpu_feature_enabled() while at it.[1] [1] https://lore.kernel.org/all/20241031103401.GBZyNdGQ-ZyXKyzC_z@fat_crate.local/ Suggested-by: Borislav Petkov Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Acked-by: Dave Hansen Acked-by: Mike Rapoport (Microsoft) Acked-by: Dan Williams Tested-by: Fan Ni Reviewed-by: Ira Weiny Signed-off-by: Gregory Price --- 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 01ea7c6df303..58ace82874eb 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1462,16 +1462,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 (!cpu_feature_enabled(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; }