From mboxrd@z Thu Jan 1 00:00:00 1970 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 24CEAC25B48 for ; Thu, 26 Oct 2023 06:00:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 648A36B0370; Thu, 26 Oct 2023 02:00:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F8646B0371; Thu, 26 Oct 2023 02:00:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E75B6B0372; Thu, 26 Oct 2023 02:00:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 411996B0370 for ; Thu, 26 Oct 2023 02:00:05 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0FB59160CE5 for ; Thu, 26 Oct 2023 06:00:05 +0000 (UTC) X-FDA: 81386561970.29.7D5045A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf12.hostedemail.com (Postfix) with ESMTP id B254740017 for ; Thu, 26 Oct 2023 06:00:01 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DxCfxY1K; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698300002; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t6u4LYCpZ7VEa7eWIIzhykPNXK8uzErIJSSbrGNQWps=; b=imcK+tFEsSOpWJTlyQeV8Ywt+mRxdfKTwQ0HoJTCtOFIPwowlLhcwhUseTyztNBHKibgzw BzI+BdikY5pcMzWLsmCr3j/cHZa97NNshx97Pd9X2pF6qCUzDwEib4RrqHWQfxSvwXlyyT wFnUsU9CXObyeFSulr1AfivpKU8ZybA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DxCfxY1K; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698300002; a=rsa-sha256; cv=none; b=Q9xLtUC9iFBowFYlGBICTuW1EtcXbqkfWPYMrrmXAI7atAYj6nN9u/a+xJlxfhFmiauHeA GjNIlfm7Vjq2xa3zOssuRZxlS4dlqgMzAzW93Hh43298m62fkRR9w++FKTCPC6r9AOpMTW hkAumD3gt/7PuSYDtTJbb0LGu6sE5Zk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4AE2BCE35C5; Thu, 26 Oct 2023 05:59:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDAEFC433C8; Thu, 26 Oct 2023 05:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698299996; bh=t3J9H/h2snw+b56w9zIz6vz35i/sxpaoxI32J+Gzy5I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DxCfxY1Kmyk9puXLiX3QWldxdqhhHYeeKrw7GPEdnlQ7bWr6ni7VPdkfmANFQ4fCz ++ILmouYywP335eyCjg8+XjeV8zS8ibSEEQDtTnZqYZjzk+UotDtGpPIw4DWGBXlV7 D0HY9lEJ3NVE7ZjDH7AEHkBRnWkDReOcmxhm5R3YoaVETRTPKFc0N+HLbUknEgaKar PzLaVpbEzyLjKzFqlP2g1WdWTx6yQYXd1gMu6PVdI1kF78OGf/VpU5PaVhXbYWzk0n /URO4tzbJMk2O5Vpp26iyn7kxYnNMTkHiB/TegrBsR3gp/KZTPJIZsKRtHwWRpbAS/ TrU3e/uK2ll7Q== Date: Thu, 26 Oct 2023 08:59:40 +0300 From: Mike Rapoport To: Liam Ni Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, chenhuacai@kernel.org, kernel@xen0n.name, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, akpm@linux-foundation.org, maobibo@loongson.cn, chenfeiyang@loongson.cn, zhoubinbin@loongson.cn Subject: Re: [RESEND PATCH V7] NUMA: optimize detection of memory with no node id assigned by firmware Message-ID: <20231026055940.GH2824@kernel.org> References: <20231026020329.327329-1-zhiguangni01@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026020329.327329-1-zhiguangni01@gmail.com> X-Rspamd-Queue-Id: B254740017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: mwp41q4yurac5r89cp5sj8wqshgj1nmb X-HE-Tag: 1698300001-722722 X-HE-Meta: U2FsdGVkX18uCvrylmXMYR4MUtKR0gRGdhpgeKav8J3jDN+vplLCqRMr4549wH649r8Qjd5mSohTH/8iT0PfCpzExYKE9bpyq+m3eZuMRgm2g/LZvwAS6EWE1l9tLDcfULKBziACSBqDHprBkAGRdwdzlueSZHwltdVYfFkErkbTBkKQWgl03ibv+l2zHGoMrcRfAbdg4Ag6RIiyUmzhZ3rQx+hCMuM+LTYg9ryM2XiJZLnZYnyxL8jRVS8MI/s82C5GQZYKMm9m2Xli7xNuvqA8l6ImrY4wthW2yqkfsRk7BDY89iHFPGOHfS02m0PzLuN2ZbrM7EzAM2XpIqcjixuWXxTLwR3+xPgP+tIfdAUUkLERCei3aRb3d6EZoyLQXMzra5CWPqYqm70HFFD7IQmtMUrAVGiyHn+byG7w6p/aZF+lGHl5DImykvQQgL6MIdLVpwTMxbYV55JzfyhT5/APlKrGzzOYkPMuuNn0WVzwdlgfUN8GP5Wlbumf5kzBQU/jbQmxbPYCajRzWYqM82xdjY4/IioRGEHr74uwrPWqPTsd91qIA0PsOlosy4Kr6pWcu/g2XHWtM9xm9tOVKAnoY8RWeWCd8S6ThdDnaAG1sk7EQE9sUEZk4xPW21kpXrnVQS7Ev5RWV2mlevzQwSNpk0gr5BiS/Ww1unLACs3AkIvUZap76r59N+mFX0QX/s1T4daht4eVlT7yY2k9DVqMInqgw2GR4QuEHItidABXVAmQntYFWcUHckpDOLIJ6kV3KTx62XMh6qECuMbchzt3D91BhcwRgXchSIrExvDFa/GMPbYnQhS7neL7+p+cpEXyxmk0rLhziUuc3wfXrZ/i+NJJi19vI55FJGAkYgzjmeZi4D1Gdw6/utI9xb4IBWZUYctRqr6CO81x5w41eQCdmiTlLNH6clubAbk6Omctt7d52+7odB74JMus1EHcVMxoVqXia6pXik587zR CbUvnmFw 83uxbN7ek77ssFALO0rMOwyXJoQzTz8tvTr5XdDB3NmIlR8YU+47uo3optQ31qlQvQmTpiT/bzuO2IK83Me9iDMwTwOokqeOpI5WcMH9ZMAmb9zCn6cWVrIS0NxMgrtregz9lBdOwdmaDbT0cO4cWpK4Gq51AmhKkNlcrzAMGQKzZiEzImPeSzdKOvEGc8uyo6647GGGx4FqjcCwZpJtyr1EQxpr1bTRpdBz+AThqyWlpFsqRnas9B7Tl//FgyIR8uAJpazgk54t3dyY= 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: On Thu, Oct 26, 2023 at 10:03:29AM +0800, Liam Ni wrote: > Sanity check that makes sure the nodes cover all memory loops over > numa_meminfo to count the pages that have node id assigned by the firmware, > then loops again over memblock.memory to find the total amount of memory > and in the end checks that the difference between the total memory and > memory that covered by nodes is less than some threshold. Worse, the loop > over numa_meminfo calls __absent_pages_in_range() that also partially > traverses memblock.memory. > > It's much simpler and more efficient to have a single traversal of > memblock.memory that verifies that amount of memory not covered by nodes is > less than a threshold. > > Introduce memblock_validate_numa_coverage() that does exactly that and use > it instead of numa_meminfo_cover_memory(). > > Signed-off-by: Liam Ni Reviewed-by: Mike Rapoport (IBM) > --- > arch/loongarch/kernel/numa.c | 28 +--------------------------- > arch/x86/mm/numa.c | 34 ++-------------------------------- > include/linux/memblock.h | 1 + > mm/memblock.c | 34 ++++++++++++++++++++++++++++++++++ > 4 files changed, 38 insertions(+), 59 deletions(-) > > diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c > index cb00804826f7..0e69679bfc8d 100644 > --- a/arch/loongarch/kernel/numa.c > +++ b/arch/loongarch/kernel/numa.c > @@ -226,32 +226,6 @@ static void __init node_mem_init(unsigned int node) > > #ifdef CONFIG_ACPI_NUMA > > -/* > - * Sanity check to catch more bad NUMA configurations (they are amazingly > - * common). Make sure the nodes cover all memory. > - */ > -static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi) > -{ > - int i; > - u64 numaram, biosram; > - > - numaram = 0; > - for (i = 0; i < mi->nr_blks; i++) { > - u64 s = mi->blk[i].start >> PAGE_SHIFT; > - u64 e = mi->blk[i].end >> PAGE_SHIFT; > - > - numaram += e - s; > - numaram -= __absent_pages_in_range(mi->blk[i].nid, s, e); > - if ((s64)numaram < 0) > - numaram = 0; > - } > - max_pfn = max_low_pfn; > - biosram = max_pfn - absent_pages_in_range(0, max_pfn); > - > - BUG_ON((s64)(biosram - numaram) >= (1 << (20 - PAGE_SHIFT))); > - return true; > -} > - > static void __init add_node_intersection(u32 node, u64 start, u64 size, u32 type) > { > static unsigned long num_physpages; > @@ -396,7 +370,7 @@ int __init init_numa_memory(void) > return -EINVAL; > > init_node_memblock(); > - if (numa_meminfo_cover_memory(&numa_meminfo) == false) > + if (!memblock_validate_numa_coverage(SZ_1M)) > return -EINVAL; > > for_each_node_mask(node, node_possible_map) { > diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c > index 2aadb2019b4f..4079c9edaa93 100644 > --- a/arch/x86/mm/numa.c > +++ b/arch/x86/mm/numa.c > @@ -447,37 +447,6 @@ int __node_distance(int from, int to) > } > EXPORT_SYMBOL(__node_distance); > > -/* > - * Sanity check to catch more bad NUMA configurations (they are amazingly > - * common). Make sure the nodes cover all memory. > - */ > -static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi) > -{ > - u64 numaram, e820ram; > - int i; > - > - numaram = 0; > - for (i = 0; i < mi->nr_blks; i++) { > - u64 s = mi->blk[i].start >> PAGE_SHIFT; > - u64 e = mi->blk[i].end >> PAGE_SHIFT; > - numaram += e - s; > - numaram -= __absent_pages_in_range(mi->blk[i].nid, s, e); > - if ((s64)numaram < 0) > - numaram = 0; > - } > - > - e820ram = max_pfn - absent_pages_in_range(0, max_pfn); > - > - /* We seem to lose 3 pages somewhere. Allow 1M of slack. */ > - if ((s64)(e820ram - numaram) >= (1 << (20 - PAGE_SHIFT))) { > - printk(KERN_ERR "NUMA: nodes only cover %LuMB of your %LuMB e820 RAM. Not used.\n", > - (numaram << PAGE_SHIFT) >> 20, > - (e820ram << PAGE_SHIFT) >> 20); > - return false; > - } > - return true; > -} > - > /* > * Mark all currently memblock-reserved physical memory (which covers the > * kernel's own memory ranges) as hot-unswappable. > @@ -583,7 +552,8 @@ static int __init numa_register_memblks(struct numa_meminfo *mi) > return -EINVAL; > } > } > - if (!numa_meminfo_cover_memory(mi)) > + > + if (!memblock_validate_numa_coverage(SZ_1M)) > return -EINVAL; > > /* Finally register nodes. */ > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index 1c1072e3ca06..a94efe977539 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -120,6 +120,7 @@ int memblock_physmem_add(phys_addr_t base, phys_addr_t size); > void memblock_trim_memory(phys_addr_t align); > bool memblock_overlaps_region(struct memblock_type *type, > phys_addr_t base, phys_addr_t size); > +bool memblock_validate_numa_coverage(unsigned long threshold_bytes); > int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); > int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); > int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); > diff --git a/mm/memblock.c b/mm/memblock.c > index 0863222af4a4..397d61c4896a 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -734,6 +734,40 @@ int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size) > return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0); > } > > +/** > + * memblock_validate_numa_coverage - check if amount of memory with > + * no node ID assigned is less than a threshold > + * @threshold_bytes: maximal number of pages that can have unassigned node > + * ID (in bytes). > + * > + * A buggy firmware may report memory that does not belong to any node. > + * Check if amount of such memory is below @threshold_bytes. > + * > + * Return: true on success, false on failure. > + */ > +bool __init_memblock memblock_validate_numa_coverage(unsigned long threshold_bytes) > +{ > + unsigned long nr_pages = 0; > + unsigned long start_pfn, end_pfn, mem_size_mb; > + int nid, i; > + > + /* calculate lose page */ > + for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { > + if (nid == NUMA_NO_NODE) > + nr_pages += end_pfn - start_pfn; > + } > + > + if ((nr_pages << PAGE_SHIFT) >= threshold_bytes) { > + mem_size_mb = memblock_phys_mem_size() >> 20; > + pr_err("NUMA: no nodes coverage for %luMB of %luMB RAM\n", > + (nr_pages << PAGE_SHIFT) >> 20, mem_size_mb); > + return false; > + } > + > + return true; > +} > + > + > /** > * memblock_isolate_range - isolate given range into disjoint memblocks > * @type: memblock type to isolate range for > -- > 2.25.1 > -- Sincerely yours, Mike.