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 EA478C001B0 for ; Mon, 14 Aug 2023 16:00:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DA53900002; Mon, 14 Aug 2023 12:00:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88AF38E0001; Mon, 14 Aug 2023 12:00:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72BDB900002; Mon, 14 Aug 2023 12:00:23 -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 65CD18E0001 for ; Mon, 14 Aug 2023 12:00:23 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 10AA314052D for ; Mon, 14 Aug 2023 16:00:22 +0000 (UTC) X-FDA: 81123172326.14.C4A05D5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 7AFA84002C for ; Mon, 14 Aug 2023 16:00:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Tt7RxJi+; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.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=1692028818; 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=ODaNCWkCTgQBYp605JAVW4VA94jxhGG6SNbGm7/zexQ=; b=TlP/FT2XwCK+Zkxt2vEuk/bHQHe2HoTFp5LgM8O+/SetIg3oBxA118llZr1bGdaSwSRaE1 urA/FmhLe4rh5Cc7BE90zKECfujE/Fvl7+m8YVj5AIJN+6RCG1E4kiGmAVcKUHr0OH8CCs jd0K8CNWsO7q/VYDoyWBWNRp8eMMx7w= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Tt7RxJi+; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.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=1692028818; a=rsa-sha256; cv=none; b=pghPfMT7hH2QDI0jPouIu8aqtfGG3CPfDL3/f9p7w/NgjfdswutpFrI3FTy6EoHaykBBic PfJ1OGVSxMIWVgatD+aDOD1r55Fg1Jm28NhMFfx4ddlEk9ZERRro/P4vnpogj5JsTacdEJ sBwmzygoWOYYJ7TO2LVGhkFJx2/FrzA= 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 D7E5A6217C; Mon, 14 Aug 2023 16:00:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E1E2C433C8; Mon, 14 Aug 2023 16:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692028816; bh=jhjaS/2Y9cwyx9ts23hmnkLwn6OVV/aozByHwgTXnW0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Tt7RxJi+gxkL2yCcnmyoOFprL73XugXUVREtoBV3EASp64W/qhZkt7Mc7T5WdejI2 FNF3cINVYKlcQp4lbBCCnzBs9sQKkn3V1P1URs+eZGPq/WVnD/6XFtV4AqXlVT8OqE xA6mJBV9TK1fQBJVains9cIXKguOwxD992ctwFhwqu5lM4KMQm4+o4qm3tzODLRdDW 0e+gZtrL1LZ+RfEMIh3sCydLyiSUsmkj00KQtZ8VuM5c35XrA/recr6ZeVviLFIaBy nT3QZzAtJ/q7/Q8L7n0mq8ZxTC19iON58m+xD3wM5Sg9vw7m0o/jzDO8VrQ6kiXPBm GKHeXxQOxAilg== Date: Mon, 14 Aug 2023 18:59:11 +0300 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: <20230814155911.GN2607694@kernel.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7AFA84002C X-Stat-Signature: 7izzet115p71knx1uye4tjxc5u485ab8 X-HE-Tag: 1692028817-343502 X-HE-Meta: U2FsdGVkX1/C1VbNfIG+L3r2TbZ1omsm+IX/UbcTkqT7uugRyxiPxri9jTYqGoRRvlp7Dw3p+yOWM3T+DU1G7EwXXZfmLK3qi3dAudeUOkHd2sj7dgFNILzpyLGzny5KZAR1R2LviuvipufmN1T/HyweYcT5KI3fUA7EUU6vBATQpSl/uOUWArCL3Cms3Jh3oPxHmccRO9t8NQf2tklYCiwEUh+7arWqNHhf7f69+tWts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81QZmjxdzLtj4L5MUier2waGeseWAjoemojck6VhujUyRZrz6bz/nw== 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 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(). 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.