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 AA5FBEE49B0 for ; Wed, 23 Aug 2023 14:36:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 087C5280078; Wed, 23 Aug 2023 10:36:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 037B7280074; Wed, 23 Aug 2023 10:36:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4289280078; Wed, 23 Aug 2023 10:36:31 -0400 (EDT) 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 D433B280074 for ; Wed, 23 Aug 2023 10:36:31 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A87F0A0172 for ; Wed, 23 Aug 2023 14:36:31 +0000 (UTC) X-FDA: 81155620182.09.0AB5AD1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id EE72A100018 for ; Wed, 23 Aug 2023 14:36:29 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qZLsHVOk; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1692801390; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sgVNyPPFwInBZcvvfNd1h6nIVezo14wBUrGibolXSc4=; b=2e80KDUEdOM8ITfXEoTxrY0e3CLVhiWIVCIczfaATAhFRZ1wIyGxktPjatsFio5lRrYKas hVkiVM+slFkwsHGI2MGqPRPjCdvhu3xptdx7BpCmfnahKwjGHAaR7p3MYdRVRqiFKs+SKw +4bawz67Ge5uYaP8yrsXrezw+rRCdPY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qZLsHVOk; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692801390; a=rsa-sha256; cv=none; b=EEteMm/tPRpIQXkSZzhKTw7npnxNDSjIuR67hzR4b9cHzW7GbcCW5FBmNnsmqGZoGFpKkP YL0w9bYdkRsXdnpT/esYTEGSeOURxEovHZjN6jvYx24BAYPA3LRgE4puJPMbq1ZUKfZ4jK Lj+6nOcoDaifOtATO1qBjS85RHELOA8= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9C52066238; Wed, 23 Aug 2023 14:36:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFEE6C433C9; Wed, 23 Aug 2023 14:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692801387; bh=eRT5wpPzE2dG8Htf1U5WjVNZWKMJy4q5xPRnCCdw3jg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qZLsHVOkbIOn1hjfAmB+/RmDZAks8n7X+JQRAlO5qAuHYIP46RoFCPzYnCoKGUCnp Z2eOolqYNWZV2PQW9dxB5jwJjrxvWjHMjcWQtBg6xoG5DnSZS3dLDyUW24EKCuekIt rE3ZlfKpkUcQWNZjx9XGhO1bcpy+0l32Ltl0ool76uPBNsu1p0FqWRuwQ0BbNthHo1 2HKVGbgx5xwA/uU2bQh39yGp62AvxtIPtjuNc/t8C0INMsDxg9IpMOo37BomlTdeKu U0m1dojN3+E1f6F0fzWD6pVPmj4x8qVJoBDNEZ9SlNduy3drMmWNFVfpjWB/fNfVkk DkmwDwJ584Ajw== Date: Wed, 23 Aug 2023 15:35:56 +0100 From: Mike Rapoport To: Liam Ni Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, zhoubinbin@loongson.cn, chenfeiyang@loongson.cn, jiaxun.yang@flygoat.com, Andrew Morton , "H. Peter Anvin" , x86@kernel.org, Borislav Petkov , Ingo Molnar , Thomas Gleixner , peterz@infradead.org, luto@kernel.org, Dave Hansen , kernel@xen0n.name, chenhuacai@kernel.org Subject: Re: [RESEND PATCH V3] NUMA:Improve the efficiency of calculating pages loss Message-ID: <20230823143556.GA188089@kernel.org> References: <20230814155911.GN2607694@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: EE72A100018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: tbw6c5gi3aancemc3erpj5xp81zx7fgz X-HE-Tag: 1692801389-117761 X-HE-Meta: U2FsdGVkX18oW8ZKooW/rMVnVF02yi78RA0UMUtxSsKT7W/cPj1gQoflxoO9EnX7rWw62S4GiiLmNTkE+ghwptuhYMzqfx5H50p+VJYYE9TDGEt/c8x25x0LUEOWx0SGXh7oHZ/Tybj/4QhwV4F3pmKepoXNVSocOxl5D0vioifRshZzEF0OSW1ea5KXijT4iHUwM7LkrEySpoCdhZgHo5L0IUcCCL6M3qh1TRbblk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hvZa761BMZIOhTuaZj09DWwopR1VN+8kpJNQV+rOjc4Yw== 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: On Tue, Aug 22, 2023 at 07:49:05PM +0800, Liam Ni wrote: > On Tue, 15 Aug 2023 at 00:00, Mike Rapoport wrote: > > > > On Fri, Aug 04, 2023 at 11:32:51PM +0800, Liam Ni wrote: > > > Optimize the way of calculating missing pages. > > > > > > In the previous implementation, We calculate missing pages as follows: > > > 1. calculate numaram by traverse all the numa_meminfo's and for each of > > > them traverse all the regions in memblock.memory to prepare for > > > counting missing pages. > > > > > > 2. Traverse all the regions in memblock.memory again to get e820ram. > > > > > > 3. the missing page is (e820ram - numaram ) > > > > > > But,it's enough to count memory in ‘memblock.memory’ that doesn't have > > > the node assigned. > > > > > > V2:https://lore.kernel.org/all/20230619075315.49114-1-zhiguangni01@gmail.com/ > > > V1:https://lore.kernel.org/all/20230615142016.419570-1-zhiguangni01@gmail.com/ > > > > > > Signed-off-by: Liam Ni > > > --- > > > arch/loongarch/kernel/numa.c | 23 ++++++++--------------- > > > arch/x86/mm/numa.c | 26 +++++++------------------- > > > include/linux/mm.h | 1 + > > > mm/mm_init.c | 20 ++++++++++++++++++++ > > > 4 files changed, 36 insertions(+), 34 deletions(-) > > > > > > diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c > > > index 708665895b47..0239891e4d19 100644 > > > --- a/arch/loongarch/kernel/numa.c > > > +++ b/arch/loongarch/kernel/numa.c > > > @@ -262,25 +262,18 @@ static void __init node_mem_init(unsigned int node) > > > * 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) > > > +static bool __init memblock_validate_numa_coverage(const u64 limit) > > > > There is no need to have arch specific memblock_validate_numa_coverage(). > > You can add this function to memblock and call it from NUMA initialization > > instead of numa_meminfo_cover_memory(). > > Remove implementation of numa_meminfo_cover_memory function? Yes, that's the idea. > > The memblock_validate_numa_coverage() will count all the pages without node > > ID set and compare to the threshold provided by the architectures. > > > > > { > > > - int i; > > > - u64 numaram, biosram; > > > + u64 lo_pg; > > > > > > - 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; > > > + lo_pg = max_pfn - calculate_without_node_pages_in_range(); > > > > > > - numaram += e - s; > > > - numaram -= __absent_pages_in_range(mi->blk[i].nid, s, e); > > > - if ((s64)numaram < 0) > > > - numaram = 0; > > > + /* We seem to lose 3 pages somewhere. Allow 1M of slack. */ > > > + if (lo_pg >= limit) { > > > + pr_err("NUMA: We lost 1m size page.\n"); > > > + return false; > > > } > > > - 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; > > > } > > > > > > @@ -428,7 +421,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) == false) > > > 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..14feec144675 100644 > > > --- a/arch/x86/mm/numa.c > > > +++ b/arch/x86/mm/numa.c > > > @@ -451,30 +451,18 @@ 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) > > > +static bool __init memblock_validate_numa_coverage(const u64 limit) > > > { > > > - u64 numaram, e820ram; > > > - int i; > > > + u64 lo_pg; > > > > > > - 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); > > > + lo_pg = max_pfn - calculate_without_node_pages_in_range(); > > > > > > /* 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); > > > + if (lo_pg >= limit) { > > > + pr_err("NUMA: We lost 1m size page.\n"); > > > return false; > > > } > > > + > > > return true; > > > } > > > > > > @@ -583,7 +571,7 @@ 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/mm.h b/include/linux/mm.h > > > index 0daef3f2f029..b32457ad1ae3 100644 > > > --- a/include/linux/mm.h > > > +++ b/include/linux/mm.h > > > @@ -3043,6 +3043,7 @@ unsigned long __absent_pages_in_range(int nid, > > > unsigned long start_pfn, > > > unsigned long end_pfn); > > > extern unsigned long absent_pages_in_range(unsigned long start_pfn, > > > unsigned long end_pfn); > > > +extern unsigned long calculate_without_node_pages_in_range(void); > > > extern void get_pfn_range_for_nid(unsigned int nid, > > > unsigned long *start_pfn, unsigned long *end_pfn); > > > > > > diff --git a/mm/mm_init.c b/mm/mm_init.c > > > index 3ddd18a89b66..13a4883787e3 100644 > > > --- a/mm/mm_init.c > > > +++ b/mm/mm_init.c > > > @@ -1132,6 +1132,26 @@ static void __init > > > adjust_zone_range_for_zone_movable(int nid, > > > } > > > } > > > > > > +/** > > > + * @start_pfn: The start PFN to start searching for holes > > > + * @end_pfn: The end PFN to stop searching for holes > > > + * > > > + * Return: Return the number of page frames without node assigned > > > within a range. > > > + */ > > > +unsigned long __init calculate_without_node_pages_in_range(void) > > > +{ > > > + unsigned long num_pages; > > > + unsigned long start_pfn, end_pfn; > > > + int nid, i; > > > + > > > + for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { > > > + if (nid == NUMA_NO_NODE) > > > + num_pages += end_pfn - start_pfn; > > > + } > > > + > > > + return num_pages; > > > +} > > > + > > > /* > > > * Return the number of holes in a range on a node. If nid is MAX_NUMNODES, > > > * then all holes in the requested range will be accounted for. > > > -- > > > 2.25.1 > > > > -- > > Sincerely yours, > > Mike. -- Sincerely yours, Mike.