From patchwork Wed Apr 9 05:27:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donet Tom X-Patchwork-Id: 14044078 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 32115C369A2 for ; Wed, 9 Apr 2025 05:28:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06A5B6B012F; Wed, 9 Apr 2025 01:28:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F328B280036; Wed, 9 Apr 2025 01:28:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAD266B0131; Wed, 9 Apr 2025 01:28:22 -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 B8D126B012F for ; Wed, 9 Apr 2025 01:28:22 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DABEF161DAD for ; Wed, 9 Apr 2025 05:28:22 +0000 (UTC) X-FDA: 83313374844.20.7FB5B6C Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf07.hostedemail.com (Postfix) with ESMTP id BB40C40003 for ; Wed, 9 Apr 2025 05:28:20 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=ob2FhZlU; spf=pass (imf07.hostedemail.com: domain of donettom@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=donettom@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744176501; 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:references:dkim-signature; bh=g69eVT1ol18IO6QR4WSJPXpCjVxrf+G4BquZYxF4yzU=; b=BZlJLCZlWet0Zp53VzKLhzpH4HHcJyEjsl7scnf1QkDDxxVuXplz26ZM7hd0vvvBzOz4qp dFVfaj9/r54/iYbwSsu6sayuhHEX8lU1M6x59TWzWrfYIriDfmNoV9UAsO9JcAU8M+DYgo YHmah6Lx5aM2OjWIo9Vk63J5rRxqdNo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=ob2FhZlU; spf=pass (imf07.hostedemail.com: domain of donettom@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=donettom@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744176501; a=rsa-sha256; cv=none; b=PRPCtDGBfgp8E3VfoyMPf2gbvE2BEdmpT6UrZixZ7x71gjJUi71BhMhKHxa7e1frrAkVg0 6nU4Ii33+yTiuT4YTkHB/v5C25XlhtD8VX/0MKerVK5S9xTLXVc7+twhAtuPjLkzJsusva UeNLqJrfVHgKb/N+dpCPN9pWsHJzXXE= Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5390e11H013886; Wed, 9 Apr 2025 05:28:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=g69eVT1ol18IO6QR4WSJPXpCjVxrf+G4BquZYxF4y zU=; b=ob2FhZlUPXLhBUXx54RCSnK0+bfs0Scd1dDYNMZ51OG9Ajc8cnFgEtocd 7x1QYrv3OJD6wwNXPgTNsRUtkTQRGPJDmWwfVFQswoPzjtWvYA9/drKE4ioYa8hH YjD887xtoTkEIbf7HilYOFU4Ch3UnhZaL7B9/1CPqVXmcMeUaDA0l2yO/O8+Xlsa J2moOe3TPDTyUkA8YBF9igbJZstkUREIN1bt5SwOjAvUZNYzVehxaySwRrZv+fWy fxvMAzrRM2krU2VVn1pb+ajwYoCdN7dnmvGNpwVwHBIlubUeINjDl029WoHJjDEe F+0CZ5TuWIqQSYWUbanozet8N3bNg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45w57putk4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Apr 2025 05:28:16 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 5395QNJR002530; Wed, 9 Apr 2025 05:28:16 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45w57putjs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Apr 2025 05:28:16 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 53955Kc9014473; Wed, 9 Apr 2025 05:28:14 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45ufunp6g5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Apr 2025 05:28:14 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5395SCON52756914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Apr 2025 05:28:12 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9AC7F20040; Wed, 9 Apr 2025 05:28:12 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 759D720043; Wed, 9 Apr 2025 05:28:10 +0000 (GMT) Received: from li-06431bcc-2712-11b2-a85c-a6fe68df28f9.ibm.com.com (unknown [9.124.222.191]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 9 Apr 2025 05:28:10 +0000 (GMT) From: Donet Tom To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, David Hildenbrand , Andrew Morton , linux-mm@kvack.org, Mike Rapoport Cc: Ritesh Harjani , rafael@kernel.org, Danilo Krummrich , Donet Tom Subject: [PATCH 1/2] mm/memblock: Added a New Memblock Function to Check if the Current Node's Memblock Region Intersects with a Memory Block Date: Wed, 9 Apr 2025 10:57:56 +0530 Message-ID: <50142a29010463f436dc5c4feb540e5de3bb09df.1744175097.git.donettom@linux.ibm.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: LA20b6d-QkhrqUWu8HLC1sjClDJeKaK6 X-Proofpoint-GUID: ZOWH6i46-zSl6W0_NELOitU5EhlJIuV_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-09_02,2025-04-08_04,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 impostorscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2504090020 X-Rspamd-Queue-Id: BB40C40003 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: jgji3tyq5p18pgehm6mcarccrcjhj8m3 X-HE-Tag: 1744176500-904707 X-HE-Meta: U2FsdGVkX1/qL+pCYhcWuAVv/prPrp64LD0rkR3fbVhjVsemilsyEVfjTrtrNZ+XT1n3SIarGvpM5cuAya5zNd6o+rs4YCGsBs4gSkk/TqWIeQ78Q7+GNZBXOPtdnU+VXQQwOgBudmFZPmTrwxw6++B2jJcgtRI0+fhtiucI2CZF4iD0hjbecC7YMYMRdsiET6HjvE4IIqyqJdVJsvvJPjknd5yiVwyAEwAsQ/JygMaDNsN6fpMNJO/lvVfDp+V98qxLK6Xe9sn3NWicoc5UhCCnxjcqSfTbpZWsybvl9ycG2FW9EW3iPkz/xVda9kpAVrecHEYOQEk2VwvFRcPX+cNe0+iGtldjHTGwtdlrP1ThPtF1zAfP+eVmf5HugH9NB+AuTEp3KR9t3TenVOQ2cspjrC/tZr/A2XndMYAjVa7LwY6LbDnrV5GHjB7l1zlFm4U2LwQC1LDZkW6yZKJWA/yBWoZ6s0EppVdZqJ8YRF1xHEfJJmfDq5m3PjazsagdGXW50y8rTvj6+c87Mt8D0XAhzx+ss2kS4K5JND9jkFXl+qrrAwVkD8re2g1y9BSr29lJLHs6ZsPFKzwp/LAIu5RgV2FRqIqp3xH+th/+Q79MQFPjI+tzXZyXE/s++C2+r2CppMvkoBifxKEzXXPB14zuwJ9DItk9NKAFXJr/Y4haw//uUuotCo/Gzpkr21yH2zQB/JV6hPmG2HPuYKtX5FRXnDZrV+Om30SfmzjEydBqP9WBzqHFkIrjoq/Vv3B+vwh8Lf6CNgIdOSnEuvYIwmbTMwPn2KCghJ0s04M7ZyPqpmvaMNU01Duf0qxxxpG9j0GeBAbp+WUbrvRauFucY1Z8xjURqsIgyatTF3Kiv7ZqP5j4gkZ7geNYZYhVIWHn+9tqh9a74Z+SOvu9dAxYzD3VXNregYHfG3UELYGAN4faz8R4ifr6cZDUxcFOFZYJ 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: A new function, curr_node_memblock_intersect_memory_block, has been added to check if the current node's NID intersects with a memory block. This function takes the start and end PFN of a memory block, along with the node ID being registered. It then finds the memblock region of the current node and check if the passed memory block intersects with it. If there is an intersection, the function returns true; otherwise, itreturns false. There are two scenarios to consider during the search: 1. The memory block size is greater than the memblock region size. This means that multiple memblocks can be present within a single memory block. If the start or end of the memblock is within the start and end of the memory block, it indicates that the memblock is part of that memory block. Therefore, the memory block can be added to the node where the memblock resides. 2. The memory block size is less than or equal to the memblock size This means that multiple memory blocks can be part of a single memblock region. If the start or end of the memory block is within the start and end of the memblock, it indicates that the memory block is part of the memblock. Therefore, the memory block can be added to the node where the memblock resides. In the current implementation, during node device initialization, to find the memory block NID, it iterates over each PFN of the memory block until it finds a match. On large systems, this can take a long time. With this function, the boot time is reduced. Boot time without this function - 32TB RAM ========================================== Startup finished in 1min 12.413s (kernel) Boot time with this function - 32TB RAM ======================================== Startup finished in 18.031s (kernel) Signed-off-by: Donet Tom --- include/linux/memblock.h | 2 ++ mm/memblock.c | 67 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index ef5a1ecc6e59..db87f7daa46c 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -277,6 +277,8 @@ static inline bool memblock_is_driver_managed(struct memblock_region *m) int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, unsigned long *end_pfn); +bool curr_node_memblock_intersect_memory_block(unsigned long start_pfn, + unsigned long end_pfn, int curr_nid); void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, unsigned long *out_end_pfn, int *out_nid); diff --git a/mm/memblock.c b/mm/memblock.c index 0a53db4d9f7b..570ab7ac4dce 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -6,6 +6,8 @@ * Copyright (C) 2001 Peter Bergner. */ +#include "linux/stddef.h" +#include "linux/types.h" #include #include #include @@ -17,7 +19,7 @@ #include #include #include - +#include #include #include @@ -1909,6 +1911,69 @@ bool __init_memblock memblock_is_map_memory(phys_addr_t addr) return !memblock_is_nomap(&memblock.memory.regions[i]); } +/** + * curr_node_memblock_intersect_memory_block: checks if the current node's memblock + * region intersects with the memory block. + * @start_pfn: memory block start pfn + * @end_pfn: memory block end_pfn + * @curr_nid: Current node + * + * This function takes the start and end PFN of a memory block, as well as the node ID + * that is being registered. It then finds the memblock region of the current node and + * checks if the passed memory block intersects with the memblock. If there is an + * intersection, the function returns true; otherwise, it returns false. + * + * Return: + * If the current node's memblock region intersects with the memory block, it returns + * true; otherwise, it returns false. + */ +bool __init_memblock curr_node_memblock_intersect_memory_block(unsigned long start_pfn, + unsigned long end_pfn, int curr_nid) +{ + struct memblock_region *r; + unsigned long r_start, r_end; + unsigned long size = end_pfn - start_pfn; + unsigned long r_size = 0; + + for_each_mem_region(r) { + r_start = PFN_DOWN(r->base); + r_end = PFN_DOWN(r->base + r->size); + r_size = r_end - r_start; + + if (r->nid == curr_nid) { + if (size > r_size) { + /* + * The memory block size is greater than the memblock + * region size, meaning multiple memblocks can be present + * within a single memory block. If the memblock's start + * or end is within the memory block's start and end, It + * indicates that the memblock is part of this memory block. + * Therefore, the memory block can be added to the node + * where the memblock resides. + */ + if (in_range(r_start, start_pfn, size) || + in_range(r_end, start_pfn, size)) + return true; + } else { + /* + * The memory block size is less than or equal to the + * memblock size, meaning multiple memory blocks can + * be part of a single memblock region. If the memory + * block's start or end is within the memblock's start + * and end, it indicates that the memory block is part of + * the memblock. Therefore, the memory block can be added + * to the node where the memblock resides. + */ + if (in_range(start_pfn, r_start, r_size) || + in_range(end_pfn, r_start, r_size)) + return true; + } + } + } + return false; +} + + int __init_memblock memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, unsigned long *end_pfn) {