From patchwork Wed Jun 14 11:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 13279913 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 24763EB64DA for ; Wed, 14 Jun 2023 11:03:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83F6D6B0074; Wed, 14 Jun 2023 07:03:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EF296B0075; Wed, 14 Jun 2023 07:03:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B6176B0078; Wed, 14 Jun 2023 07:03:45 -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 5B06C6B0074 for ; Wed, 14 Jun 2023 07:03:45 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3AEDF1C842B for ; Wed, 14 Jun 2023 11:03:45 +0000 (UTC) X-FDA: 80901068010.10.3435086 Received: from out-19.mta1.migadu.com (out-19.mta1.migadu.com [95.215.58.19]) by imf10.hostedemail.com (Postfix) with ESMTP id 8BF33C000C for ; Wed, 14 Jun 2023 11:03:41 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=P06EKQSY; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.19 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686740622; 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=JUAXO3nF4TYUh7G4bGQ31E/7+rub4uhiLNTBrM2ujC8=; b=7Z+ypEcMFMgyCEol6kClDLWAIg4GmCfNgkwEgh6ETJiTF97Wkdxha661Sr7osbHlsxCQzz U289GP3/LR9RailASSagKtvsVp0ckUwJJCnnVFhyODZbqnKtL/SspGztV1G2xGqF3/CE6C jtWINqsGu2KEF53p/WZXB/6dEiVjD+4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=P06EKQSY; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.19 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686740622; a=rsa-sha256; cv=none; b=aCgBQD57HaCnrHa1xJ3mzZZMsHJn2esTyRV/uTGbmfwz9kYQYA0oDLz6+U9K7xFTtO5lcg H1xKCB4RFn4KcIjzx3IB8IJ7oViN+IvQ174B5MOUMZSAubA1XAVDjBU2OfgRDrpFrTJ/94 xzskXxLb9F2/k8DS7jpju3ohLWQeZFk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686740617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=JUAXO3nF4TYUh7G4bGQ31E/7+rub4uhiLNTBrM2ujC8=; b=P06EKQSYiSzPJZCUwYNF5LhDGDRkWumiodO74KPIgoDsJrSSb2UrF6A7dqnDxkcI4mWLjI nb9+BJDG2syeWPi7IUgLgHswlfW/eBUTP6IOeABhyIBQQry9VGuTvpKhY+7YUZVYrZN8jH k9zNpZiJ+8Ve3g+BfGPpBFZezTn8LhM= From: Yajun Deng To: gregkh@linuxfoundation.org, rafael@kernel.org, rppt@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yajun Deng Subject: [PATCH] mm/mm_init.c: remove spinlock in early_pfn_to_nid() Date: Wed, 14 Jun 2023 19:03:24 +0800 Message-Id: <20230614110324.3839354-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8BF33C000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ogiqiyebmb1ron477h3y67a3qx9c55zb X-HE-Tag: 1686740621-479744 X-HE-Meta: U2FsdGVkX18gw//9Vfl21cXAqBwItdIY2ArOTavuUYRkj949h5ILQ82drvn2II8vgYthKqBqzpEWd17FPfRq+PcNRpVQeuJ+LJiYIZhvcQq+JEUWqmry542FF83RABknTu3imMQ64rJWCNByx37Ac0DU3VVc6Fj+VAMTHKRVvaorZSaMAHpy1k98OrpTjZcTbvQiXL9SwtY6guRemFttzF2WIUwgR07qL+Cch/QZuroZmblSnf7/+vEHpKdOyLpjauzRhHf3SYynR03tSq9hYFlQn9QeUb8bGsuENQfI13QacV3iIpV7Kmq6QwH6oSwDk3gjpr/bx8Eg9xd9f/pZF2bZ1Qfgq13V4Bt6UUGgJfbHmoJJEl7pO6Mv82egE0PY05WaKCSPnH6aIpRufrmM8iyzAiwQJE4nRgMJx7JfaTsrLoSIcxjh/a3Idlqkf5nD2bf6H5yVYZyIxQ+6bMyDWdpSzz2Rr4owkU2072Z9Hdwuj2d5W0id2lMvAnmgxoSYSkEQPESATCXiaqhcOOt7JaIdt2xTIV/HXbnb/LxOtSZiaMZS3Uw16ExEPQJ808QhVxuPcSs2GL38dgff3Mo1qGhbTkl/ONpjJVYmFkxpJvbtfGFewW7u6T2RE/rN7FyT6N9TlWf99PI3GOXca8Phx+S1wH5+C3r/TdytiR3cO21bA7Gg6qchtQ8bRu6VDY7JW8YcCYS/GjUfMmRBjyi5CUE8k0Sc+AocbfqAeQtkTz/O6LIGH23mTwOYv8rarGMlZFSPiAdzXqPqnwc4KUsP/tY5y2ciA4jGzGNF6RcI3aNSuxTdbq4XMqfS8C84CnN2agfopJWtxMp+o5NNgvQVSTtllLroRCXaRRr0SXvGKeIPHiwZksLYsEA9Vb+z4triCkyZFWWHezmpCpzvwDh/nAYdHzR6uLHhfkIKIVS/5DyYxB7sRL7Ikeqj9NKUFMMA8KN/c/DAPKDozzTBT9Y uhQhZ937 5WARhKZelpG3A+6PuzIhq/Vsv/lSNWq0I5zSza3XYviED4WQYEnKkmePKd2U5OU/peHqIKfdhwX93eyBcOviEm+1/Z71DyaqCu27wfTM8JBtfZVRLeoElji6R/w== 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: When the system boots, only one cpu is enabled before smp_init(). So the spinlock is not needed in most cases, remove it. Add spinlock in get_nid_for_pfn() because it is after smp_init(). Signed-off-by: Yajun Deng --- drivers/base/node.c | 11 +++++++++-- mm/mm_init.c | 18 +++--------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 9de524e56307..844102570ff2 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -748,8 +748,15 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) static int __ref get_nid_for_pfn(unsigned long pfn) { #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT - if (system_state < SYSTEM_RUNNING) - return early_pfn_to_nid(pfn); + static DEFINE_SPINLOCK(early_pfn_lock); + int nid; + + if (system_state < SYSTEM_RUNNING) { + spin_lock(&early_pfn_lock); + nid = early_pfn_to_nid(pfn); + spin_unlock(&early_pfn_lock); + return nid; + } #endif return pfn_to_nid(pfn); } diff --git a/mm/mm_init.c b/mm/mm_init.c index d393631599a7..5895a30435ee 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -584,11 +584,11 @@ struct mminit_pfnnid_cache { static struct mminit_pfnnid_cache early_pfnnid_cache __meminitdata; /* - * Required by SPARSEMEM. Given a PFN, return what node the PFN is on. + * Given a PFN, return what node the PFN is on. */ -static int __meminit __early_pfn_to_nid(unsigned long pfn, - struct mminit_pfnnid_cache *state) +int __meminit early_pfn_to_nid(unsigned long pfn) { + struct mminit_pfnnid_cache *state = &early_pfnnid_cache; unsigned long start_pfn, end_pfn; int nid; @@ -601,20 +601,8 @@ static int __meminit __early_pfn_to_nid(unsigned long pfn, state->last_end = end_pfn; state->last_nid = nid; } - - return nid; -} - -int __meminit early_pfn_to_nid(unsigned long pfn) -{ - static DEFINE_SPINLOCK(early_pfn_lock); - int nid; - - spin_lock(&early_pfn_lock); - nid = __early_pfn_to_nid(pfn, &early_pfnnid_cache); if (nid < 0) nid = first_online_node; - spin_unlock(&early_pfn_lock); return nid; }