From patchwork Tue Dec 10 22:05:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13902356 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 5FDABE7717F for ; Tue, 10 Dec 2024 22:05:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B08588D0020; Tue, 10 Dec 2024 17:05:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB2B48D0017; Tue, 10 Dec 2024 17:05:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92E7B8D0020; Tue, 10 Dec 2024 17:05:51 -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 73FE28D0017 for ; Tue, 10 Dec 2024 17:05:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3BFAE120F49 for ; Tue, 10 Dec 2024 22:05:51 +0000 (UTC) X-FDA: 82880432292.14.DB5EA7B Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf08.hostedemail.com (Postfix) with ESMTP id 554E516000A for ; Tue, 10 Dec 2024 22:05:34 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=vLcP42KJ; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.48 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=1733868338; 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=oErJky2BLU9Af7jLve7daZWId/j12r2NaH/TqvsN93M=; b=cA6q3S0Iw4wPOGAoS5azkXYMYi3uq8FbBHBSEmXa68m2vKwjGhfpv0nt0WgH63f0IF4N9y RS59IwBbWiWHhzENQ3FhvzdzFdyrxou3Q4yWzRPmTfXrGmh4OVhTwmLQnICOWeQzmp/Jtj /D3myApk23izfb36dH8BPUWeoc+s3D8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733868338; a=rsa-sha256; cv=none; b=i6xS6tTOANByOq2f5ZZvC/tzaR+KkZwNT3z/yMOF1VQrdfDWu/ij7vbCkOwg3hGsZAjyeb Z5j+8M8B8BtYYVNr4NLthXH2aBycaYG0yuCokazjyZxXZ3DlfR5pxR8zZE4yTv21U6SJl2 whaTKoI3Z5m1dxSfhkuM9J4GGYzhPas= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=vLcP42KJ; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.48 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6d888fc8300so32758566d6.3 for ; Tue, 10 Dec 2024 14:05:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1733868348; x=1734473148; 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=oErJky2BLU9Af7jLve7daZWId/j12r2NaH/TqvsN93M=; b=vLcP42KJhZKzo54P+8HeIX4Q8/3lBLGf0VD3CC/1TzIU0p0cycHd1mkNhh5dWoVGXA Tfl8E3RSuGEY6UO8Ruajb9ADec0ghPX163QdaF0aXtVvZAkkdCRT2lLhzGwXgAZSw1Yi lDeLPpJmaufg9YsYdURxcCpFoWEgPWNVLW5r+0zVP8P6b0R4PeTSvEPchiDKzqI1gEUH Pvu83DVwu5xDBOChpXVEq4X1+8JOoem/ojoulp6DVZhdzu7pByKMhcfWK7/FlH5Rgtdc PYdTbnOR3fnOsIB91PH6f6rE681nCXDTWDw/O2/3792dg2pMTocjZ+58/4wXa6S2fCsK Grqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733868348; x=1734473148; 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=oErJky2BLU9Af7jLve7daZWId/j12r2NaH/TqvsN93M=; b=NoVca6zxl4aZiBhPBIpCD6Jn1B3a1+7kQqLLG2MwvnXQjOD4sl4ZKDCiokiMntLVjs yYp2Jw75z7tVabv6eCA0xsiYoVjI+0WXC677BZTJ1WdtqVoxSbyhJVGDOj/oUCPuL6q7 qo/GbbP+LdmJxIX++DCBbbXmiIAc+WaCU4C4Sl9RYpKII5WwfwZjq1ncrB3M5YVggm29 EPThBjuZziQrGTfbED13eST46FVbpkCQLVq6ALZgfpZfFL9WfvSRLlDm5A0XuSSmOoAD +wqtl7HjT0GMZKaJnq4wZGdkAgUqNm1OzdlFWtxLtVn5dYtWezTku5oUyTFpYTlxNikT Vq/Q== X-Forwarded-Encrypted: i=1; AJvYcCXgMy9HoRAZMyzHwY281m8op6V/bcLkDJdcwexAbGuCgSuhh0fxsZZ+0Y5kx2o6TbbBxxOPMRNFdw==@kvack.org X-Gm-Message-State: AOJu0Yy7V+DXlhzP44KH8xQsjBtgqzhvm3PyQde3IVv/FKPMddmRnQRL r53hi+JPSTBekdd0spzD7hVA3TW6DeGOgs9fF6BBem4N3OK+Rct4O075pWF8+M0= X-Gm-Gg: ASbGncvd0zkz6rT1qXqAhfBHau1HeS9FvkCo6zwC/ji4vp3NOjnb9UgxD13AWcuo2p0 amA2NU6s8kqDBPMNL/5lxTHy54iRBfP6RL72yd1MDyN2kba2sA7pMzQbiVIVeFgH07sw5E37f54 aRNNkIojNCO7ODmaMtc4707EYVePP2FW8NgXsgPCxeULj4qy/4cWwNag2Uz1DbAb4uzbdcWoWae vQJ4ipI/hXvCOTDqtMLyJTllcTjrDMkMDRcJoaL4DX1/DNkPK3ncG8t824V6JTPU2QruHT7nrZE YMzM4aEh42cT5b0Lq4KaSWmxzXVmsBH4Ja5qS2s= X-Google-Smtp-Source: AGHT+IENYQ0oAKQ+kT8P0UCH8ySBpUYpnMabT5K76y4L5ld+Nf2r6CwojmMzmHyhvdr+kBpYd1jW3w== X-Received: by 2002:a05:6214:2682:b0:6d4:254f:1c8e with SMTP id 6a1803df08f44-6d934b7cc2amr10515796d6.37.1733868348294; Tue, 10 Dec 2024 14:05:48 -0800 (PST) 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-6d8eeb132e1sm49707756d6.35.2024.12.10.14.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:05:47 -0800 (PST) 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, kernel-team@meta.com, dan.j.williams@intel.com, ira.weiny@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, david@redhat.com, rppt@kernel.org, akpm@linux-foundation.org, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, osalvador@suse.de, Fan Ni Subject: [PATCH v7 2/3] x86: probe memory block size advisement value during mm init Date: Tue, 10 Dec 2024 17:05:16 -0500 Message-ID: <20241210220517.3744-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210220517.3744-1-gourry@gourry.net> References: <20241210220517.3744-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 554E516000A X-Stat-Signature: f7hg71dt5ah515446r7r1ez1iha1en6x X-Rspam-User: X-HE-Tag: 1733868334-248366 X-HE-Meta: U2FsdGVkX198dQF8Vg57Z2MckxGIEu3n9yzpNd7aYYpD9ZQPB5WMJK4BBoJcmjr93LgBUjUyWZuNuETVxkxuPBrRbFoqiwpCgCIwL+IBGxJafokO19yZWC6CAYPCvD9nLm67M+SjDMCbEC6LiWLBCH4f91F6p2X0WLXxiUw2YPFn2gz2E7+5POJHoR5q5CsJ2lOxs3sY8+sHXWtyceLkDVIKRTKF2XLGxBYH+Zd8NpT78ovWXaaUEx3ugQciMNpw5cwI92QReOZL5sOqbGxQYqhtLGGYJMSr1coIgE3v0XVsuPzcvk1e4O7CbUTNHTosdt7Eoaagv5p9nDU6oJZwmSy4id7bne1oLrm8/SBmTXRQxCsOGLK2Rhxz3x6VxDUQnOKxO0HA0msQRJo/Scx0NPKKgih4OUlLLrPgYMO+BiwYcluwxhx1GbOQ9+O0CQnd0V5qqz+MaKYJ8pUU5q1SWgGOMmfmca4/F3RVxWvVNuq7LNKjbFmI8Rc0ZJAXpIJCc3mniUNa9xtJ4IufLq3jsh7wH8gSBgdc+VgV/XH6pBnGEIw0TqL9XH+/zCpDZTtVAiyeomrPKi2sBm6ttAY5E8sRutLwkasoVXIL7raCjzXKkVDBT+FAxeXNY5kXIom+s9pje7qPT29ku65yBgO60Bw72pRRFdYDXX1wmvsMaXFD6taDgvILOuoQ7RyycUrY9YYisHqVxrtd14e2lgSlPqM7He83yLkVbZ1ef5ZBUH9hWUbH+y4HSGZH7YIBPK7qIIhG3ZGJhlrSfh5H9F6o0Y58mQdwPPIK2KVo6NAbdeQXgnhVX+QLzgza/jWnh75L998WjY5B73MzPN5pC2rWXJO26LSSdqP3cKtfI7wCRVhJTIuWUAllf3HpsDK8tE4POITvE8OurY+blSOo6NUCMgg6NcKEqch0FvwhD7Jk1+O/FnZ+ERUaJIpU0MrhURZ7kq3nWCejwTQF/gU6Ro4 n7rWTcrL nIBr/6qrjFs/h2Qp7w+r9v3vH0K2duH9lLfyfX6/enGJ2RjYZNdwZU6psIGNAZFwiaElZmSqJKlBlbZhoVYPrBu+oPZTf+ElTYHBcBAAD6DsWViXPeKxKZUmECSZS5Ar+VidjD5oW+xvk4IEnbK5k9TPpmprjkvk49rFHqDlF4Iqpvj5CKo5ldsFew6ZxTtJ68xUKsKjyBo2n44ETE/i8lmipxiu9RdCgYG15cUNdQs9s9QeUMYQMeCE/Jmsp/Kb5qRVikyK6+Q48QYYsSyv/WkmI7hmG8FAk2/+OzgEc/Gm7dS2CnPqbieZZbwYEJgchmTXhUdq7Grm3Zl2MWw+5LAmCd80QckijDiEAJ1Ps9QM+smhJZgQR8EXlBDQmdb9XpNTLPdepzSgK8M/WkuD+B988tQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, 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 --- 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; }