From patchwork Mon Jan 13 17:44:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13937846 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 601B8C02180 for ; Mon, 13 Jan 2025 17:44:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BAF06B0083; Mon, 13 Jan 2025 12:44:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 143876B0088; Mon, 13 Jan 2025 12:44:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED4B96B0089; Mon, 13 Jan 2025 12:44:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BF5F46B0083 for ; Mon, 13 Jan 2025 12:44:55 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6B260A016F for ; Mon, 13 Jan 2025 17:44:55 +0000 (UTC) X-FDA: 83003154150.05.6C2F38E Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf10.hostedemail.com (Postfix) with ESMTP id 91259C0018 for ; Mon, 13 Jan 2025 17:44:53 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=jaMSx2Ih; spf=pass (imf10.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.172 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=1736790293; 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=xZSM7cd0rzVSNSrAghH4+54a5vGC27L1Y4nGLMrRkSY=; b=oRGbX4RIneWUC+WGq7LX2BXgNgV4l5H2y7bjet8IWFM0b6XuQoo6Y9qTQh7NhRW0Bx3lNg SxunB+bVZLhlLMKFBjU66wF5UOsiHwGZpJBTez4J3ymtMxodpMWn2ol6sL5+4Ow2REKojp h9xkW27QzHMZpXhftPnrBFkv7id/eWE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736790293; a=rsa-sha256; cv=none; b=B+/oR/ycAaCLId9/DA/KX+ruhMrvGfla5bUoJPJaZ+d7INeZ4m8bdbDslQA6FXq/ahzHAg Xi0Wsc9gxt0QwDKZSXaV+2gxI7TewqVj1SNvAdm/VqLdsd7MM/mKqJcPk7oNHM6+ft3JDa hz1uUTtb9fEIw/ieHCuZlbwkVqrjNng= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=jaMSx2Ih; spf=pass (imf10.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.172 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b6eb531e13so253019085a.0 for ; Mon, 13 Jan 2025 09:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736790292; x=1737395092; 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=xZSM7cd0rzVSNSrAghH4+54a5vGC27L1Y4nGLMrRkSY=; b=jaMSx2IhvQfnSXX817Z5DpvLnKWVqrweTUqbIkSAwqF6mVu+5t3x6Qh+yRTrd6xCaL U0p0wH1AJ6LCZ6hei8sOyYbvQEBZ+eFHKLBBX6aDIR03WAsQX1HR1CQUXhgkXizO6JD8 0IIy+MjSOwDmNvWwM4SEZTfzpfMlBxw9YliDl97AerJwulVdYvA+owH62k4obDBiJCip sPcYj9M+NMfMFVUQ6wlx9/g9DvuiFZro7f5gK+G3ayBpjrQ4DN8RUrjaar7dpWZjy11w 1Nrq2QK33Ujncb8WmBkf2mNSnzrMia/iJcd3epb6zU4wsW5n0BlOIt19S3dfVhdlVOv8 KFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736790292; x=1737395092; 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=xZSM7cd0rzVSNSrAghH4+54a5vGC27L1Y4nGLMrRkSY=; b=oz+v8YNdDXWel6agPupv2M/blUPBScGluml3w7d+nk8AXEVP7DBa2bIjtwNRCcTB5C XFVU+UJ6S/+2cstdh4qEI3VsqEFhBcQoz4bQiv6y9L+8JjjxP3THXFI6CrQStw78VI8T RPVFweoge11aXBKjFdKqWbrA2nFUnIHsaEZ6Lt94Mil3OMXJtnN34UrWcqDNcVbet8ea 1Ig5/iQ+uVTy220yJN+KveCryNEx6cIIr8UHz6IPKoNgX3DnDgNmin8oEOFe6mPeleaA WMvEJfImy3qeFrMwzzuUnIu5YFF5x5CQwUdurB1brfHD9ABm7EMhK3z3pDMw99iVPxts B4pA== X-Gm-Message-State: AOJu0YxuaeMRKp9xwsd1u+TN98zeotveulbM/CPqiwEMlPIqXY3uGdjg 0SoHni1XhyWTbwkMYHbIBarlbT3Z8xRFM1AQywmObA/tfoQ4c3RmpzACNX5RPeYzkxFly7D3tgo 4 X-Gm-Gg: ASbGncudSD04kAogobJG+p9ZenanXvSTZpyUGqtSZZ3YdD8nQjcqF8QbbvsQdwh5WUP XgeutgemrAq1QyOxuhbdyUfv3Clu8fUbrGgvOc+eQVSS4CBzZeacjruma743YlSSoufUCrW9ds/ rP12c62IkwHCHxtvSZpueBImlcLBlbeyxCy5bmGLNKnhp84KflWKi1To+Ch1DXWlNFTMgt8aLqJ vDphqB5PY+XWi8zn7wAhbLBMs9dw6CPgYcTCPHuS2jimngn71IwEzabl7DQ392PI9qFyO1BO73f IQxKdCkvlRlX+505TDlU2nrh/yu+rHVibpeSUo9YXSEh X-Google-Smtp-Source: AGHT+IF+IF6Rv5no47DpWYrkZUPK0sDnR8tgi7nlXfUyokU9C1+7BbgLKk1J4eOLXpCwFls4u2oImw== X-Received: by 2002:a05:620a:2697:b0:7b7:24b:dc58 with SMTP id af79cd13be357-7bcd97627d1mr3005432485a.43.1736790292471; Mon, 13 Jan 2025 09:44:52 -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 af79cd13be357-7bce3248c80sm511214185a.49.2025.01.13.09.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 09:44:52 -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 Subject: [RESEND v7 2/3] x86: probe memory block size advisement value during mm init Date: Mon, 13 Jan 2025 12:44:38 -0500 Message-ID: <20250113174439.1965168-3-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113174439.1965168-1-gourry@gourry.net> References: <20250113174439.1965168-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 91259C0018 X-Stat-Signature: qb4paaot4eok97wxmp6dynecuzzjdyh9 X-Rspam-User: X-HE-Tag: 1736790293-510977 X-HE-Meta: U2FsdGVkX19oqNRcnJUTZnvg7OJdH04Nd+KRYrKEnCMf2mW6QqHdmwrzWdT87BAmnOtwH2prAFc+TFl0fzGL4UkqdEv1TVtWm2oeU/xrshchpu7zASD4XHv5LF2g2vTBEgH1+/VjhBP/bSwUaBzEkH1sS/cHbT5CbuQvy39sMi8KQL4mwphuAScZhdHeMZIU55W0fZtAbxWhW3J9lvek4J1Netx3u0iH6gv/TbfKBcksFuvrLvJEsZLkjsXUpR41rwMi05ME3TqIM5qAEWxvEprUOnSw66IedX7gPWDbJAbZMs+7DqURqRI4UaMuZBUY+zMf8qLFgWT4pvLvzlRG59KWGZ66gXy+zfhqPNgRfNy90W4Buukq/sg+VtSKPTCdExaFF6jBv6OcMrWdv8DqdHnw7GJMmT8aompVJiAoYsx/BR6mbdVJG59Fj3YvWOqQV4nnsWgCJc8zotcNCIajPwz55Cuo8G4jvq1FPyik6OX9EWZzY/vXbH1AtepG9gjyFDa5NznG0TjtrItpqmUX2Qiq2UrPlKTzp9FOU9B4oGTf/oUhQpYYYBSWP8TbAkO5AalohAFlK9og8s4dKP8Vs6luTiR2Raf9To0GBVSigNYOHTQFM4fowsYBICH9RShFt2TtbQ7Vr0fCMx1n+SVCM0Fp0f40GDLaFZR/P0I+6j7lx+Uu8KWWVaeyI2iHLeurRMgeKQWvA61HQziE7MgU4SdZV5aHAhrGEPBnC356EkccU9MgMpBmbxtCExwQOTwApSAevTrF6xX77maclHH7Qic8h3TAD2sC/UU6JJ8EAzxw/l7tCA1Z5qPPRBP2qNjNzTdMMNF7QB1F2dD1DFEEQaLq+ipt3zZzAtqLfgZtlS5nDzXwLcSIyrxMkX1+q+ZllFmluABKyu02S7LFQ03bYYVbtsrp6yST/OirET+ovKRhl6HXsz5ZPB99XKv+mX+q+RQWm0GUFb4ljm67x5C B6vBZsbT wXE7iiEqqCuZs9fvdSBVa0lp89+m8jiHUP6GD1kI0RNkLiN8vGbzNhMMOXS0SyTOJAU1heO9hvIcpO2cv8UvzSV15YxEzBv3NXoDg1gGg2CpjAAvUWjddq8G2ykICcGIPlLJGf8bLqozWZwKBn13cHEIo2AqFRqDC++Bjs5w7DVdssnX+HhFOKg7JfBJ+UFewAdbiENSquoa3AIUxqZJXhAnImxgOQAukpV8TntY9DhN0a3JCAg32ANkyihB+2IBxvyxsGl6p1bn5bb0lNiV/esdDdSWM4+W5CAgRjC4EQeWrPfKptGvhXZI8CrFq9nEUVOi7vUwDs641D747oeB7YH6o15H8s19trbbuN7obP0SqnQITL4FCg83vTq5CPwlnPSHbdPELEEd9cH7BwvL3vSAiOQ== 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 Signed-off-by: Gregory Price 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 --- 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; }