From patchwork Wed Nov 6 15:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13865123 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 13ABAD59F49 for ; Wed, 6 Nov 2024 15:59:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E326B00AD; Wed, 6 Nov 2024 10:59:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCFCC6B00AF; Wed, 6 Nov 2024 10:59:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2E56B00B0; Wed, 6 Nov 2024 10:59:07 -0500 (EST) 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 851C16B00AD for ; Wed, 6 Nov 2024 10:59:07 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2D2C012036A for ; Wed, 6 Nov 2024 15:59:07 +0000 (UTC) X-FDA: 82756128042.10.1585026 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf19.hostedemail.com (Postfix) with ESMTP id 21FD61A0007 for ; Wed, 6 Nov 2024 15:58:21 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=GF3i8cFZ; dmarc=none; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.177 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730908686; a=rsa-sha256; cv=none; b=DjLUhOnz82QqaD1NleaZcguBYIQwRdT51bNbkQeO/jYCKC5optsvCIE6XUrePzBs/02JyH mS4/FkS+aZU8J5SOdbn52VFK/C8lcL5jqEizSCQbfj2FnsXA4g4y/6zXHznnk5hWgtJYTh aUyknkMH1pC4kwuhW4zO9718rU5zMSE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=GF3i8cFZ; dmarc=none; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.177 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=1730908686; 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=DhjUN4fArKWWoXRi7BXSpLcpyo3J42V+ZDp+ucOnHvE=; b=SOtfBz5EJ1dAxUAM7YAliiy0b5AHQ6b6YDoeCyMrqwLqm8Dr73ye3jx/tVaa/Jkle3m3FN 90i8FFGHKSRkKZSyRSmYlvPd6KBOt6ViB2zfXTCV4koHE6MtpmQxj9kxdV4JcS+l01svl1 F853eCzgmi9Ba6KxaV3SU2VT3SZJlPA= Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7b15d330ce1so503504985a.1 for ; Wed, 06 Nov 2024 07:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730908744; x=1731513544; 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=DhjUN4fArKWWoXRi7BXSpLcpyo3J42V+ZDp+ucOnHvE=; b=GF3i8cFZYbNuuo2Ig7vUF9KoajHr8286e4/MtonU8J+ZzkqxmieayTGQtDhjZ1Oh/+ VIZeHdqUH0pk9+21U9EPhmFKF3diwJAx/Y2BH2jZbZ1rmNiADjxfEgQLdmgmfLNLTXJ1 2CMmNxXWjHOB8ZEmEcne7sLzChVU5CPg5ck9k7ybs9tzXTrVS8pqdAFjgLxZpeIsYKMM gdPVuWctN71NxUs1mD1IkmEb73TmAgYM72ZWiuG5vPhegZPFxzjhwMO8bzS9XAa4pEvh 8MFy9kBlNFnt5xeDHXe2e21lMhlmF6W2CGWtPBqwV/ZpQhBhLnfmTCaoVbYHJh9WTQ9e TzhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730908744; x=1731513544; 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=DhjUN4fArKWWoXRi7BXSpLcpyo3J42V+ZDp+ucOnHvE=; b=anr24dFqtdFfTZjyaABfNABOUx21YI4AF3gHUrGxxRcJYMsuhXve1TSEVniTfZgVXs ExI/sBWWnQBUati0w6tVyrfyiNpbYT0daPQgjBI/rWJa3lxeNHpqp1+7y+QbzO27vI2G KcKctd2sbr7dSZN8KHJkvvlIActODJ210BVe2SuGjCM+GA7bwCeG2PSI130Ns5WBubFL IUX/QefuzCk9X9S46NvXbwTKKKTf6/f327dacahEDVyXiBi1WkEfFSM3DjIT6FoE5wVe uUzq+gsBpqeVoiEj/hAORO9OjGbLPYEzjUpD6JHbfKFnbbkqcr1rq3qbZXbFCfTeDVfT BGOA== X-Forwarded-Encrypted: i=1; AJvYcCWg+7VevQ6bZJYif4r7CTMUEOZnf4UDJ6Tj+dAMmGWXX9r8tGqmeKXZ1xo8FOYH+KEfXpC1ZVBl7g==@kvack.org X-Gm-Message-State: AOJu0Yy6FbFsejmQ06Y8NsvO1m2jqprksU4bmxSb5s5vY58trbgNFpIv 2ZbPgOZCHQ8/KMtSEI6RxJLFpE2tdkCQi+pAnCoc+ViZOJ0jxhNL+bwGPslG5G4= X-Google-Smtp-Source: AGHT+IGyyNaqJP5GT84XkBpTnZi+GYICvytezSItQpJFP+BO2bYKSnE0l+VTemNGpDBYq2sb9frOVw== X-Received: by 2002:a05:620a:190f:b0:7a9:b456:c5e6 with SMTP id af79cd13be357-7b2f253d534mr3445707985a.42.1730908744203; Wed, 06 Nov 2024 07:59:04 -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 af79cd13be357-7b2f39f7b85sm641377285a.31.2024.11.06.07.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 07:59:03 -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, 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 v6 2/3] x86: probe memory block size advisement value during mm init Date: Wed, 6 Nov 2024 10:58:46 -0500 Message-ID: <20241106155847.7985-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241106155847.7985-1-gourry@gourry.net> References: <20241106155847.7985-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 21FD61A0007 X-Rspamd-Server: rspam11 X-Stat-Signature: 3mh4xunoqhc66a347z61w6o1y9wh9fhp X-HE-Tag: 1730908701-705408 X-HE-Meta: U2FsdGVkX18dmlQ+IBPnez1edmKQf02ZpmdizWjmjkc26g3qlNLnDDOFVcD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XXY9HPqItZkLQYHi38tZHo7uv3wioCpHUKWvFP9tlUpTtvUvMmLcnXoEdq8hRId0CWQ6SvgDVvr8iubkL3p6L6P0/xaJ2IL3yFooauBJDptgsdb8gIv80kOJohotiVlByInHA9zOMjiNf0HgxFi14AVHtMLsRzO0xGxUcM5JVXZC+YSD6MEaKEUad8gtxQvzTHCHBOnNTS7ccDbrIqAhwnMzJbCA== 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) --- 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..2622dc7c78ba 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 (!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; }