From patchwork Thu Aug 1 06:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13749751 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 35BE4C3DA64 for ; Thu, 1 Aug 2024 06:12:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7AF46B00B5; Thu, 1 Aug 2024 02:12:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C06BF6B00B6; Thu, 1 Aug 2024 02:12:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A569D6B00B7; Thu, 1 Aug 2024 02:12:34 -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 83A736B00B5 for ; Thu, 1 Aug 2024 02:12:34 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 40CA71408C3 for ; Thu, 1 Aug 2024 06:12:34 +0000 (UTC) X-FDA: 82402657428.21.4FFF938 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf19.hostedemail.com (Postfix) with ESMTP id EEEF81A0015 for ; Thu, 1 Aug 2024 06:12:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hc6uVGpe; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.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=1722492710; a=rsa-sha256; cv=none; b=regRppU/N5uzZ17zkkFrJWs0ExdW8xlCNWBtBJGkVfinuUt6c2D86szMnRlyLR8CNk4twq SIeJ8qRhm/sIYVnxAHaXz5N5p8VkIsPQv0+pct4EWUnRaQ0eCyWvOBlJvsIytkSKLu5ij4 lWv3UObPlRVxeVlayp/PcWr+rHgS180= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hc6uVGpe; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.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=1722492710; 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=H9Z9sILq7XZ+U8gu+54pE7hQAG486x2DjNUJMHhbWN8=; b=hgMkyIhfD+UG96rPJU5RzlaL2qx0zdEUQrVkxPntDno1fweM5kgkq8JRBPmJGNaFKlgWWS q5iH78MISUDTFT9btBP3fFTQGNA47h5sgPqJhEojjP1gsRnuthzGKBca7So0t2RbPh6oK0 3Clsp0FEKSV76Aecu3Y5xED+h7HbAO0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6731CCE1805; Thu, 1 Aug 2024 06:12:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFFDBC4AF0E; Thu, 1 Aug 2024 06:12:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722492737; bh=6A0wIF55cySeIy8NiLF4qmp7wlH9rgdcaWMh1AJbYRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hc6uVGpecAI1zFcYZyBHCN2s/v1sSFhd1thfLQmuesBa3xOXeuBfexTBcgntspCRH dXB1SchKNuC8bKQlbAwfjDcR/i/R9FYc5TJ5kLWs9fy5hJuglptCZXHz4KfwCqVMn/ D3z5FascdFszO7vt9JCmOzaNHDE9uQHhAt2CzNYc06cq0vf5j/lF1yhV/JfQo9cJa5 snhcqRtI22STgHPejW0r2nk5E2leCyeVNpvm4LKvCrY9mJm5mDm1kOwSvp/LHnuPQB MnCCd+ENB07aC4pEeiqaTkovNCpkidgZsG8teItIZxO7yw7vhFSvMA+BXQz9dveoyT 3yq60hFkjkr8A== 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 v3 18/26] mm: move numa_distance and related code from x86 to numa_memblks Date: Thu, 1 Aug 2024 09:08:18 +0300 Message-ID: <20240801060826.559858-19-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801060826.559858-1-rppt@kernel.org> References: <20240801060826.559858-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: EEEF81A0015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: chfdd6na3ij9y6rr9u49x8f3pgou3p9t X-HE-Tag: 1722492751-203628 X-HE-Meta: U2FsdGVkX1/xjxxGsyPsTt9IstCSrT7BrCjY7wCsurkWLnwRyK26zmCxLXjv7dzD5nCRPkCqYxpnEiLUZq3Q13fdtJZI4tOOsm/H8ylgtHObhKPvG5wz+txyy0JWm7s3dJSWxNuxluD1G13Snsu6Y0aDRA0M15uUm0U5ILDhncBxH7GURal1x4z05kEDMUTilHVTf39M21/aZrZjJIF8CWSFOClXVazKYgs8eNbeu0ajVmIxJLuPp5UEiCfUoQDxo1lnTKvB40EVVLu98u5yFBw1SvHT8FZuljKtGnYBD1lNwNAXhVK6UPHJQJijbEyK+7G5ypKJSnIiMv0yMemek30Q7edCs9EaFOt6y2BeRUrPpst9ZNLFP2evCt6bPDylqyTewpMWWbrq9pL/JU0J7VAn838vNrmHzVqlaDUrDgc/VUrAC8FW0zYmp7ICM7+y/njNZOKyDru70hq7LF4VZGuhGaRCmO+P3mSGankeb1jdu6LNnRwzx8z87nXGts0g68XY5vv17UtxFw1gywY5zawkDPjYMFGTfHymCoK+Evhcbo13OpVhq2k3SHqpz6Ufesd/6Ot1PVojMpXPSn5H+yxGCCv+Ky7qU6Pj/xSErrwQnipzQzIt5+mAdew7V9kVCymthOOq824ojXPqj3OY8OYYaKXrAgVMjO8mp/mzIIhLgntuq2rxUoTv9Q0ATpEQMHslORtwbzot31CHBW8tgAJYQaqzYWHWniBHKHu3jrR6mAMyFJv+xMZSPYM1Z5B9lNbmP7ZE5rvsyBI12EsdZtYTfA4R7XfMnFLK3M+dfhnWnwvsmbDdaT9UmMP9ZOi8AesEdoSEzWN9axn5Rt28p54JgwnwqOttmv0rRddsXspHbxVXS8kblJlsLBA1L9A1aY8MnSjVa0GsPj28jbWQbgFLbaemQMoP+2qziKc5twIahrrQLYjAXnP7Vn7v/pSB8G0RsbiXdIOLIIdwkNN czsjKwn/ PW4mf5k6oTX+YQE7HPe/P5qIeK6WAx/akCG1mtVcrI5JMxZoNfajVebLH6MuONP7bANGKxUMZatyeacPZl2mCy1nRTmP42QaY9/aNXwVdCVVQP9CLyQtJBE8huo6dW6oreDp0q3cYkD4TVidSOFDV4539voGaH83EkQiVS0u24284OwvULz2aHWSz7QD6Pac9yOzdc+ERodO52RyF6e8DhrBzL6hkFG6Z19XIYis85v74G7btGFCA76P4kIYVZ+Rn0gwOpiqfSDcEnz31E5Jr57YRKNRPbzWnFSfDL/Ebzldjsd5jK9yZat9tCjlLKmNLwya7QTGJWPepK19/Rnm7FO/w+D2fPxBzTHdk 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) Tested-by: Zi Yan # for x86_64 and arm64 Reviewed-by: Jonathan Cameron Acked-by: David Hildenbrand --- 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) {