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 C9E1DC369A8 for ; Fri, 11 Apr 2025 10:59:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A59852801AE; Fri, 11 Apr 2025 06:59:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A095728019B; Fri, 11 Apr 2025 06:59:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AA8F2801AE; Fri, 11 Apr 2025 06:59:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6A30D28019B for ; Fri, 11 Apr 2025 06:59:47 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A6916C2438 for ; Fri, 11 Apr 2025 10:59:48 +0000 (UTC) X-FDA: 83321467656.04.A2BCE1C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id DC2A91C000A for ; Fri, 11 Apr 2025 10:59:46 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GwF8Kcp7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf20.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=1744369187; 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=CE2VXOHv1y6dbES+IdiZTyAVNbMN+wFCWDFaXMVJi4o=; b=lPa2nAvLAlSG/nsd9vqqAAqbTjhsQACcC5yhDelweQ25Yj5LoBrIUut5WG8D7ybPznTN8X B2HpzT/2i2Vm1qGziNiCRfiJv60XrtpUWA/0Oy2AxSWyrhiJWciggVtyopxRXtgpHNS8mp PFq+7HPMtZKV2Q8jpVM/GVv3lTdSUmc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GwF8Kcp7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf20.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=1744369187; a=rsa-sha256; cv=none; b=TuogJVYNDRHc7Z4YnKvOthveIR8Za3en69btqfwtLTDo8qqPQjUi5xJgRGXLlPQtdH+1aQ kSjU+pKXX8eRSV8fyA3EMaHwaIlVGgmzVz4qn60w48zE+b3yvaJEu9uL+Om4VOBM5xBxco QuvJDfoNn44gEk/eBCao/FfdFk7QNF8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8FB565C6862; Fri, 11 Apr 2025 10:57:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 662E9C4CEE2; Fri, 11 Apr 2025 10:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744369185; bh=wc0UpXn6sUdus2QycRrAxOVVMt10J2WNcT8yUwvY1O0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GwF8Kcp7+j1uVnsw6jVXeh65S2ekxKGXg+t2nQ8HwMpF6UpVIXPvaMAhGBGdVsix8 ok5d3wvmWB8v4QmXPWsEW83xp9/YIg3eNGqKJe7Qbi+C3jajuxrfL22c0YLsnNoZ84 EZlPoC7n0NPLAuTnhvo1oP6Gng8gqC4Y7xlO7MNBUQtvWAOiXe3s7xMD9gQM9IqK4H TsKtL6UrukOnfL5HHij0QKOOTRQ6VQQuJQY4GHeU8cU3n0dLANzEpT6nmhgRv7Pnvw YPboFa70FF5EM3gloLm31Hvp58KHKSD+TrAn2zAT+TzZuILeRnb8OwdKKXXysyfFt7 i2MhX9zdxXkTw== Date: Fri, 11 Apr 2025 13:59:38 +0300 From: Mike Rapoport To: Donet Tom Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, David Hildenbrand , Andrew Morton , linux-mm@kvack.org, Ritesh Harjani , rafael@kernel.org, Danilo Krummrich Subject: Re: [PATCH 2/2] base/node: Use curr_node_memblock_intersect_memory_block to Get Memory Block NID if CONFIG_DEFERRED_STRUCT_PAGE_INIT is Set Message-ID: References: <50142a29010463f436dc5c4feb540e5de3bb09df.1744175097.git.donettom@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam01 X-Stat-Signature: w3q5gborhk67ffbba1b8kij8ppbk5144 X-Rspam-User: X-Rspamd-Queue-Id: DC2A91C000A X-HE-Tag: 1744369186-859709 X-HE-Meta: U2FsdGVkX181I5uRJgknaPMiJPAkhtnknkiBRWR1RnvUoC2P0A3X/P3hCkxYt7ejckqQi+qFoLuQT4fKz6wTGtbqUNfn8rdOa0lH1cX7iK+Owo61DszLsQe0tGwpxmwMgRZgTGWo4K9QZ3WJOR6Zz4YqArK2f1gTNhe1c/PoQ0NNkriLZ5+f6Ek4xjZIUPIF7Xd1IrWiX2OToRT+NnWIXnhQ4rcjzRxbN2lopfxaKK8qHkbyMdpbm/KdHusBSvJshFn2878Gpq3geAFntEg4Np5dlmd4hRCxMcFvoOFr7QjQ/WbkwDGf/zcNPBfLe/fE8osIL7X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icity=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: On Fri, Apr 11, 2025 at 12:27:28AM +0530, Donet Tom wrote: > > On 4/10/25 1:37 PM, Mike Rapoport wrote: > > On Wed, Apr 09, 2025 at 10:57:57AM +0530, Donet Tom wrote: > > > In the current implementation, when CONFIG_DEFERRED_STRUCT_PAGE_INIT is > > > set, we iterate over all PFNs in the memory block and use > > > early_pfn_to_nid to find the NID until a match is found. > > > > > > This patch we are using curr_node_memblock_intersect_memory_block() to > > > check if the current node's memblock intersects with the memory block > > > passed when CONFIG_DEFERRED_STRUCT_PAGE_INIT is set. If an intersection > > > is found, the memory block is added to the current node. > > > > > > If CONFIG_DEFERRED_STRUCT_PAGE_INIT is not set, the existing mechanism > > > for finding the NID will continue to be used. > > I don't think we really need different mechanisms for different settings of > > CONFIG_DEFERRED_STRUCT_PAGE_INIT. > > > > node_dev_init() runs after all struct pages are already initialized and can > > always use pfn_to_nid(). > > > In the current implementation, if CONFIG_DEFERRED_STRUCT_PAGE_INIT > is enabled, we perform a binary search in the memblock region to > determine the pfn's nid. Otherwise, we use pfn_to_nid() to obtain > the pfn's nid. > > Your point is that we could unify this logic and always use > pfn_to_nid() to determine the pfn's nid, regardless of whether > CONFIG_DEFERRED_STRUCT_PAGE_INIT is set. Is that > correct? Yes, struct pages should be ready by the time node_dev_init() is called even when CONFIG_DEFERRED_STRUCT_PAGE_INIT is set. > > > > kernel_init_freeable() -> > > page_alloc_init_late(); /* completes initialization of deferred pages */ > > ... > > do_basic_setup() -> > > driver_init() -> > > node_dev_init(); > > > > The next step could be refactoring register_mem_block_under_node_early() to > > loop over memblock regions rather than over pfns. > So it the current implementation > > node_dev_init() >     register_one_node >         register_memory_blocks_under_node >             walk_memory_blocks() >                 register_mem_block_under_node_early >                     get_nid_for_pfn > > We get each node's start and end PFN from the pg_data. Using these > values, we determine the memory block's start and end within the > current node. To identify the node to which these memory block > belongs,we iterate over each PFN in the range. > > The problem I am facing is, > > In my system node4 has a memory block ranging from memory30351 > to memory38524, and memory128433. The memory blocks between > memory38524 and memory128433 do not belong to this node. > > In  walk_memory_blocks() we iterate over all memory blocks starting > from memory38524 to memory128433. > In register_mem_block_under_node_early(), up to memory38524, the > first pfn correctly returns the corresponding nid and the function > returns from there. But after memory38524 and until memory128433, > the loop iterates through each pfn and checks the nid. Since the nid > does not match the required nid, the loop continues. This causes > the soft lockups. > > This issue occurs only when CONFIG_DEFERRED_STRUCT_PAGE_INIT > is enabled, as a binary search is used to determine the PFN's nid. When > this configuration is disabled, pfn_to_nid is faster, and the issue does > not seen.( Faster because nid is getting from page) > > To speed up the code when CONFIG_DEFERRED_STRUCT_PAGE_INIT > is enabled, I added this function that iterates over all memblock regions > for each memory block to determine its nid. > > "Loop over memblock regions instead of iterating over PFNs" - > My question is - in register_one_node, do you mean that we should iterate > over all memblock regions, identify the regions belonging to the current > node, and then retrieve the corresponding memory blocks to register them > under that node? I looked more closely at register_mem_block_under_node_early() and iteration over memblock regions won't make sense there. It might make sense to use for_each_mem_range() as top level loop in node_dev_init(), but that's a separate topic. > Thanks > Donet > -- Sincerely yours, Mike.