From patchwork Tue Jul 23 06:41:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13739446 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 558F2C3DA49 for ; Tue, 23 Jul 2024 06:45:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9D536B00B3; Tue, 23 Jul 2024 02:45:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C253A6B00B4; Tue, 23 Jul 2024 02:45:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC5E56B00B5; Tue, 23 Jul 2024 02:45:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8A0BE6B00B3 for ; Tue, 23 Jul 2024 02:45:50 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2F2D5C1C18 for ; Tue, 23 Jul 2024 06:45:50 +0000 (UTC) X-FDA: 82370082060.04.4C87560 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 7BCB9100004 for ; Tue, 23 Jul 2024 06:45:48 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pXyUTJ1K; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721717125; 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=tRIHjf2S9HbS4Z//YnS86TKWnzN+IleAIApVhVvKk/w=; b=hruQLEYfd/2UnUgn31Kp2qgeED3KYUA88O8vFgRAfAyt5/bHrzI50V69nCnyjlHG1+hL3Q 5KlkBHf4mA/rEKVCAF0jNPtSMomzl8tD7B9fKPo28nSAllrkZfM8AisHC/45rf7g1y16li /AOYm6M1eW8S1ldtN62rMfaUKNMLr68= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pXyUTJ1K; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721717125; a=rsa-sha256; cv=none; b=eP1Wd3nJMVOQ/DyfMmQZPCrVyJG4Xwg7xcFClkuAkAxAc5wbngSjSh1eMc6e0j4NWPMJNr b00AusTNV3Hkxr3jK/U4EegEsXiDTiGWbQeqREMmXFS/iR1sxS7ivVs3o0/E8IvYRwB0YU u8CfTJlTZNSxQ6qTfeHApZCdHCpY3s8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B30AD60A3B; Tue, 23 Jul 2024 06:45:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62871C4AF0B; Tue, 23 Jul 2024 06:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721717147; bh=BMzYC9t5QuwdECGq/0fBoBhxOHJUxmDFhThI+5y02vI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXyUTJ1K6KmdxcOzNFBhx10UAi7KtrWf2AC3cALBHu4GHYptWrJdZs84KnVQHe9+r 6L7sZnWwWkvamwENwdFcjOPa7Ik7CfES8b2PphVrh8Z4/TtDm8a2zXTvuTr7RxjG0Y U8yG00iMG5cROM2FJH+nUaCOsq3QjYflzEYICYyV0Bq+tuO57Wnm7MvSa5w0eTT61l riNbmax5cb3PLTX/FW5nUjwSlej24ad9+5YG1ZAjplXI46GgWTYHEC0ipmUoCbEtA+ SCCP/H+rkG97RIat7tZtGxcVnQ17gKXpjVmbibUY4TWBt31zk2JBZoWoVAZDFUP42w HhmDiQLPvcwSw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexander Gordeev , Andreas Larsson , Andrew Morton , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christophe Leroy , Dan Williams , Dave Hansen , David Hildenbrand , "David S. Miller" , Davidlohr Bueso , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , John Paul Adrian Glaubitz , Jonathan Cameron , Jonathan Corbet , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , Samuel Holland , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Will Deacon , Zi Yan , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cxl@vger.kernel.org, linux-doc@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, nvdimm@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 18/25] mm: move numa_distance and related code from x86 to numa_memblks Date: Tue, 23 Jul 2024 09:41:49 +0300 Message-ID: <20240723064156.4009477-19-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240723064156.4009477-1-rppt@kernel.org> References: <20240723064156.4009477-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 7BCB9100004 X-Stat-Signature: sce7f4e1dzikhu6zdzq714wce636pfty X-HE-Tag: 1721717148-697647 X-HE-Meta: U2FsdGVkX19lFL76U0KkfCklJihMooM70eR4Ag9gWAwPsiSB8UEMQxgPsGTsVx5py3l2+AAtifekRtys6TD+WasZjGiKtroN1wLQNixUz002kTkIkrz0TFj9I1E9KCP83x7KXU+vRgyR9wT17dwEpnxrueq3kpo/++w5Bhglormk2aOPkXZD+5as0gBw9S06S/ZWIoLA0NxoBCXX7yxeVUovxK07ccGV3A3QzxmLOEkMYagrOmorxA+YEHofOqHkMznb4SpCgGPGppqReq7y7JLC9D39yF7HOLviSepa2BTNHIjXTPEDIXMARgf1L8Lm527O7goq3D/8XUwuRru2lR5vcjvts7ts2l/U29cgnahNMY1ZXbrpLeUAV3hCFgVvLnCkrcUEF2dROhdkrtAn+VyR/TeaO0cC4BTWBkklqxlwScmJAD9nucgBKFwMZL0/zkooel53S1FwTOofzi1VMMPdgHyFU5uI0SX+V3G+JwzJybvzD9OqS4NnzYgTFNRtrHN7kACrFtQmfxO6xBzccjx5+RdELRxLrtZi9cfl+2UmM4wumoUyUN3WUSd2la56Wo14YOqNxhjbB4XgV5bOlW2ILljPEIwaUBWLxB9TaE51dmYIua5oIU9qZUfO13ifTjykbISdE9+vohYBB2KCeTAhHYujSAKKFk5G7QdKGXTIMej63wPFtqzzZ4WqoA5nrzw+jNkDYDOJq9wGKC+aVTfMOVRhdcXayw5t5l9ivJa0XsjPRk2YxkbqUzKVBIGGyjcROvI15Gv7qmTlMfkCzmY/0W2U5NERi+aVEKniTVgJ5M6urOf1y04PG9I8DkPUNYvQOU0mgeZMY95KhfcvFoLqfM/4DuJnbZvAKWIV97rGzWLsbu0asbezPl5sRx6Azz5aHnunq5fFy7AVlpSWWOuxttVYiOFhk85mr5PwKpqQbZMB1MEl1DoTwEWwYpGz4lPJy3f9ZmdfLdJ5PbM T5WUNNlc VZpe/iA9xNEqh1nrPpSXG/g3cVYwAhRDkGI7k1s/39hZ+4QOnIodwo/tHsApVO0/hgZ+0OpJzl4g8SehYGbvWIXVD37ZwhKqF7iqQF4fPbpLYRsWtuOUbeqjRnqtmQKZ6+z3kI5cuSpRJNvjEs9Zpy/lJBsvjRSMS1TJic+0Xkh/A375dc1mTuw7DFesbXJaWoKpB27YuI0JONTOLF5c7pFZP3BJI84pYvYHj6PUTiHv7LsrMgPHYXz7KTacXI+10q/Nra91macDwwhOL3Ku8kMy5wRAwJdqDtpX+GbLiz3Uoq1kYsXmGgBtb9/h9WnZs1ZhpnLod17x9GTc= 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: From: "Mike Rapoport (Microsoft)" Move code dealing with numa_distance array from arch/x86 to mm/numa_memblks.c This code will be later reused by arch_numa. No functional changes. Signed-off-by: Mike Rapoport (Microsoft) --- arch/x86/include/asm/numa.h | 2 - arch/x86/mm/numa.c | 104 ----------------------------------- arch/x86/mm/numa_internal.h | 2 - include/linux/numa_memblks.h | 4 ++ mm/numa_memblks.c | 104 +++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 108 deletions(-) diff --git a/arch/x86/include/asm/numa.h b/arch/x86/include/asm/numa.h index 6e9a50bf03d4..203100500f24 100644 --- a/arch/x86/include/asm/numa.h +++ b/arch/x86/include/asm/numa.h @@ -23,8 +23,6 @@ extern int numa_off; extern s16 __apicid_to_node[MAX_LOCAL_APIC]; extern nodemask_t numa_nodes_parsed __initdata; -extern void __init numa_set_distance(int from, int to, int distance); - static inline void set_apicid_to_node(int apicid, s16 node) { __apicid_to_node[apicid] = node; diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 6874d5650b4d..8eb15578625e 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -24,9 +24,6 @@ int numa_off; -static int numa_distance_cnt; -static u8 *numa_distance; - static __init int numa_setup(char *opt) { if (!opt) @@ -118,107 +115,6 @@ void __init setup_node_to_cpumask_map(void) pr_debug("Node to cpumask map for %u nodes\n", nr_node_ids); } -/** - * numa_reset_distance - Reset NUMA distance table - * - * The current table is freed. The next numa_set_distance() call will - * create a new one. - */ -void __init numa_reset_distance(void) -{ - size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]); - - /* numa_distance could be 1LU marking allocation failure, test cnt */ - if (numa_distance_cnt) - memblock_free(numa_distance, size); - numa_distance_cnt = 0; - numa_distance = NULL; /* enable table creation */ -} - -static int __init numa_alloc_distance(void) -{ - nodemask_t nodes_parsed; - size_t size; - int i, j, cnt = 0; - - /* size the new table and allocate it */ - nodes_parsed = numa_nodes_parsed; - numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo); - - for_each_node_mask(i, nodes_parsed) - cnt = i; - cnt++; - size = cnt * cnt * sizeof(numa_distance[0]); - - numa_distance = memblock_alloc(size, PAGE_SIZE); - if (!numa_distance) { - pr_warn("Warning: can't allocate distance table!\n"); - /* don't retry until explicitly reset */ - numa_distance = (void *)1LU; - return -ENOMEM; - } - - numa_distance_cnt = cnt; - - /* fill with the default distances */ - for (i = 0; i < cnt; i++) - for (j = 0; j < cnt; j++) - numa_distance[i * cnt + j] = i == j ? - LOCAL_DISTANCE : REMOTE_DISTANCE; - printk(KERN_DEBUG "NUMA: Initialized distance table, cnt=%d\n", cnt); - - return 0; -} - -/** - * numa_set_distance - Set NUMA distance from one NUMA to another - * @from: the 'from' node to set distance - * @to: the 'to' node to set distance - * @distance: NUMA distance - * - * Set the distance from node @from to @to to @distance. If distance table - * doesn't exist, one which is large enough to accommodate all the currently - * known nodes will be created. - * - * If such table cannot be allocated, a warning is printed and further - * calls are ignored until the distance table is reset with - * numa_reset_distance(). - * - * If @from or @to is higher than the highest known node or lower than zero - * at the time of table creation or @distance doesn't make sense, the call - * is ignored. - * This is to allow simplification of specific NUMA config implementations. - */ -void __init numa_set_distance(int from, int to, int distance) -{ - if (!numa_distance && numa_alloc_distance() < 0) - return; - - if (from >= numa_distance_cnt || to >= numa_distance_cnt || - from < 0 || to < 0) { - pr_warn_once("Warning: node ids are out of bound, from=%d to=%d distance=%d\n", - from, to, distance); - return; - } - - if ((u8)distance != distance || - (from == to && distance != LOCAL_DISTANCE)) { - pr_warn_once("Warning: invalid distance parameter, from=%d to=%d distance=%d\n", - from, to, distance); - return; - } - - numa_distance[from * numa_distance_cnt + to] = distance; -} - -int __node_distance(int from, int to) -{ - if (from >= numa_distance_cnt || to >= numa_distance_cnt) - return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE; - return numa_distance[from * numa_distance_cnt + to]; -} -EXPORT_SYMBOL(__node_distance); - static int __init numa_register_memblks(struct numa_meminfo *mi) { int nid, err; diff --git a/arch/x86/mm/numa_internal.h b/arch/x86/mm/numa_internal.h index a51229a2f5af..249e3aaeadce 100644 --- a/arch/x86/mm/numa_internal.h +++ b/arch/x86/mm/numa_internal.h @@ -5,8 +5,6 @@ #include #include -void __init numa_reset_distance(void); - void __init x86_numa_init(void); struct numa_meminfo; diff --git a/include/linux/numa_memblks.h b/include/linux/numa_memblks.h index 6981cf97d2c9..968a590535ac 100644 --- a/include/linux/numa_memblks.h +++ b/include/linux/numa_memblks.h @@ -7,6 +7,10 @@ #define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) +extern int numa_distance_cnt; +void __init numa_set_distance(int from, int to, int distance); +void __init numa_reset_distance(void); + struct numa_memblk { u64 start; u64 end; diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c index 72f191a94c66..e3c3519725d4 100644 --- a/mm/numa_memblks.c +++ b/mm/numa_memblks.c @@ -7,11 +7,115 @@ #include #include +int numa_distance_cnt; +static u8 *numa_distance; + nodemask_t numa_nodes_parsed __initdata; struct numa_meminfo numa_meminfo __initdata_or_meminfo; struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo; +/** + * numa_reset_distance - Reset NUMA distance table + * + * The current table is freed. The next numa_set_distance() call will + * create a new one. + */ +void __init numa_reset_distance(void) +{ + size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]); + + /* numa_distance could be 1LU marking allocation failure, test cnt */ + if (numa_distance_cnt) + memblock_free(numa_distance, size); + numa_distance_cnt = 0; + numa_distance = NULL; /* enable table creation */ +} + +static int __init numa_alloc_distance(void) +{ + nodemask_t nodes_parsed; + size_t size; + int i, j, cnt = 0; + + /* size the new table and allocate it */ + nodes_parsed = numa_nodes_parsed; + numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo); + + for_each_node_mask(i, nodes_parsed) + cnt = i; + cnt++; + size = cnt * cnt * sizeof(numa_distance[0]); + + numa_distance = memblock_alloc(size, PAGE_SIZE); + if (!numa_distance) { + pr_warn("Warning: can't allocate distance table!\n"); + /* don't retry until explicitly reset */ + numa_distance = (void *)1LU; + return -ENOMEM; + } + + numa_distance_cnt = cnt; + + /* fill with the default distances */ + for (i = 0; i < cnt; i++) + for (j = 0; j < cnt; j++) + numa_distance[i * cnt + j] = i == j ? + LOCAL_DISTANCE : REMOTE_DISTANCE; + printk(KERN_DEBUG "NUMA: Initialized distance table, cnt=%d\n", cnt); + + return 0; +} + +/** + * numa_set_distance - Set NUMA distance from one NUMA to another + * @from: the 'from' node to set distance + * @to: the 'to' node to set distance + * @distance: NUMA distance + * + * Set the distance from node @from to @to to @distance. If distance table + * doesn't exist, one which is large enough to accommodate all the currently + * known nodes will be created. + * + * If such table cannot be allocated, a warning is printed and further + * calls are ignored until the distance table is reset with + * numa_reset_distance(). + * + * If @from or @to is higher than the highest known node or lower than zero + * at the time of table creation or @distance doesn't make sense, the call + * is ignored. + * This is to allow simplification of specific NUMA config implementations. + */ +void __init numa_set_distance(int from, int to, int distance) +{ + if (!numa_distance && numa_alloc_distance() < 0) + return; + + if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from < 0 || to < 0) { + pr_warn_once("Warning: node ids are out of bound, from=%d to=%d distance=%d\n", + from, to, distance); + return; + } + + if ((u8)distance != distance || + (from == to && distance != LOCAL_DISTANCE)) { + pr_warn_once("Warning: invalid distance parameter, from=%d to=%d distance=%d\n", + from, to, distance); + return; + } + + numa_distance[from * numa_distance_cnt + to] = distance; +} + +int __node_distance(int from, int to) +{ + if (from >= numa_distance_cnt || to >= numa_distance_cnt) + return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE; + return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL(__node_distance); + static int __init numa_add_memblk_to(int nid, u64 start, u64 end, struct numa_meminfo *mi) {