linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mm_init.c: remove spinlock in early_pfn_to_nid()
@ 2023-06-14 11:03 Yajun Deng
  2023-06-14 11:09 ` Greg KH
  2023-06-14 11:28 ` Yajun Deng
  0 siblings, 2 replies; 7+ messages in thread
From: Yajun Deng @ 2023-06-14 11:03 UTC (permalink / raw)
  To: gregkh, rafael, rppt, akpm; +Cc: linux-kernel, linux-mm, Yajun Deng

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 <yajun.deng@linux.dev>
---
 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;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-15  6:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 11:03 [PATCH] mm/mm_init.c: remove spinlock in early_pfn_to_nid() Yajun Deng
2023-06-14 11:09 ` Greg KH
2023-06-14 11:28 ` Yajun Deng
2023-06-14 11:53   ` Mike Rapoport
2023-06-15  3:02   ` Yajun Deng
2023-06-15  6:20     ` Mike Rapoport
2023-06-15  6:36     ` Yajun Deng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).