Skip to contentSkip to conversation

mm/sparse: remove unnecessary NULL check before allocating mem_section

PATCH Applied Sang-Heon Jeon 4 participants 5 messages Apr 19 – Apr 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/sparse: remove unnecessary NULL check before allocating mem_section

Commit 850ed20539a4 ("mm: move array mem_section init code out of memory_present()") moved mem_section allocation logic into memblocks_present().

Before that move, memory_present() could be called multiple times, so unlikely() matched the common case, where most calls found mem_section already allocated.

After that move, memblocks_present() is called exactly once from sparse_init(). Under CONFIG_SPARSEMEM_EXTREME, mem_section is always NULL when it is called.

So remove unnecessary NULL check before allocating mem_section. No functional change.

---
Hello,

While looking into boot information, I found a minor enhancement point. If I misunderstood anything, please feel free to let me know.

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
 mm/sparse.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
mm/sparse.c +4 -6
index effdac6b0ab1..e13f9f5fa090 100644
@@ -201,13 +201,11 @@ static void __init memblocks_present(void)
 	int i, nid;
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
-	if (unlikely(!mem_section)) {
-		unsigned long size, align;
+	unsigned long size, align;
 
-		size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
-		align = 1 << (INTERNODE_CACHE_SHIFT);
-		mem_section = memblock_alloc_or_panic(size, align);
-	}
+	size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+	align = 1 << (INTERNODE_CACHE_SHIFT);
+	mem_section = memblock_alloc_or_panic(size, align);
 #endif
 
 	for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
Signature · 1 line
2.43.0
reviewer Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 8 lines · Sang-Heon Jeon

Commit 850ed20539a4 ("mm: move array mem_section init code out of memory_present()") moved mem_section allocation logic into memblocks_present().

Before that move, memory_present() could be called multiple times, so unlikely() matched the common case, where most calls found mem_section already allocated.

Quoted 8 lines

After that move, memblocks_present() is called exactly once from sparse_init(). Under CONFIG_SPARSEMEM_EXTREME, mem_section is always NULL when it is called.

So remove unnecessary NULL check before allocating mem_section. No functional change.

Quoted 5 lines

---
Hello,

While looking into boot information, I found a minor enhancement point. If I misunderstood anything, please feel free to let me know.

I would say it's more a cleanup than enhancement :)

Quoted 33 lines

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
 mm/sparse.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
mm/sparse.c +4 -6
index effdac6b0ab1..e13f9f5fa090 100644
@@ -201,13 +201,11 @@ static void __init memblocks_present(void)
 	int i, nid;
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
-	if (unlikely(!mem_section)) {
-		unsigned long size, align;
+	unsigned long size, align;
 
-		size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
-		align = 1 << (INTERNODE_CACHE_SHIFT);
-		mem_section = memblock_alloc_or_panic(size, align);
-	}
+	size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+	align = 1 << (INTERNODE_CACHE_SHIFT);
+	mem_section = memblock_alloc_or_panic(size, align);
 #endif
 
 	for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
Signature · 1 line
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
#2 lore raw

Hi

Quoted 23 lines · Mike Rapoport

Hi,

Quoted 8 lines · Sang-Heon Jeon

Commit 850ed20539a4 ("mm: move array mem_section init code out of memory_present()") moved mem_section allocation logic into memblocks_present().

Before that move, memory_present() could be called multiple times, so unlikely() matched the common case, where most calls found mem_section already allocated.

Quoted 8 lines

After that move, memblocks_present() is called exactly once from sparse_init(). Under CONFIG_SPARSEMEM_EXTREME, mem_section is always NULL when it is called.

So remove unnecessary NULL check before allocating mem_section. No functional change.

Quoted 7 lines
Quoted 5 lines

---
Hello,

While looking into boot information, I found a minor enhancement point. If I misunderstood anything, please feel free to let me know.

I would say it's more a cleanup than enhancement :)

You're right. Thanks for your kind review. That's my poor english :-(

Quoted 29 lines
Quoted 29 lines

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
 mm/sparse.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
mm/sparse.c +4 -6
index effdac6b0ab1..e13f9f5fa090 100644
@@ -201,13 +201,11 @@ static void __init memblocks_present(void)
      int i, nid;
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
-     if (unlikely(!mem_section)) {
-             unsigned long size, align;
+     unsigned long size, align;
 
-             size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
-             align = 1 << (INTERNODE_CACHE_SHIFT);
-             mem_section = memblock_alloc_or_panic(size, align);
-     }
+     size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+     align = 1 << (INTERNODE_CACHE_SHIFT);
+     mem_section = memblock_alloc_or_panic(size, align);
 #endif
 
Quoted 8 lines
Quoted 4 lines
mm/sparse.c +0 -1
      for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
--

2.43.0

--
Sincerely yours,
Mike.

Best Regards,
Sang-Heon Jeon

#3 lore raw
In reply to Sang-Heon Jeon

Hi

Quoted 35 lines · Sang-Heon Jeon

Commit 850ed20539a4 ("mm: move array mem_section init code out of memory_present()") moved mem_section allocation logic into memblocks_present().

Before that move, memory_present() could be called multiple times, so unlikely() matched the common case, where most calls found mem_section already allocated.

After that move, memblocks_present() is called exactly once from sparse_init(). Under CONFIG_SPARSEMEM_EXTREME, mem_section is always NULL when it is called.

So remove unnecessary NULL check before allocating mem_section. No functional change.

---
Hello,

While looking into boot information, I found a minor enhancement point. If I misunderstood anything, please feel free to let me know.

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
  mm/sparse.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
mm/sparse.c +0 -0
index effdac6b0ab1..e13f9f5fa090 100644

mm/sparse.c static void __init memblocks_present(void) · line 204

Quoted 4 lines
mm/sparse.c +0 -1
@@ -201,13 +201,11 @@ static void __init memblocks_present(void)
  	int i, nid;
 
  #ifdef CONFIG_SPARSEMEM_EXTREME
-	if (unlikely(!mem_section)) {

LGTM

Reviewed by: Donet Tom <[email protected]>

-Donet

Quoted 13 lines
mm/sparse.c +4 -5
-		unsigned long size, align;
+	unsigned long size, align;
 
-		size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
-		align = 1 << (INTERNODE_CACHE_SHIFT);
-		mem_section = memblock_alloc_or_panic(size, align);
-	}
+	size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+	align = 1 << (INTERNODE_CACHE_SHIFT);
+	mem_section = memblock_alloc_or_panic(size, align);
  #endif
 
  	for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Sang-Heon Jeon
Quoted 39 lines · Sang-Heon Jeon

Commit 850ed20539a4 ("mm: move array mem_section init code out of memory_present()") moved mem_section allocation logic into memblocks_present().

Before that move, memory_present() could be called multiple times, so unlikely() matched the common case, where most calls found mem_section already allocated.

After that move, memblocks_present() is called exactly once from sparse_init(). Under CONFIG_SPARSEMEM_EXTREME, mem_section is always NULL when it is called.

So remove unnecessary NULL check before allocating mem_section. No functional change.

---
Hello,

While looking into boot information, I found a minor enhancement point. If I misunderstood anything, please feel free to let me know.

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
 mm/sparse.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
mm/sparse.c +0 -1
index effdac6b0ab1..e13f9f5fa090 100644
@@ -201,13 +201,11 @@ static void __init memblocks_present(void)
 	int i, nid;
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
-	if (unlikely(!mem_section)) {

mm/sparse.c static void __init memblocks_present(void) · line 208

Quoted 10 lines
mm/sparse.c +4 -5
-		unsigned long size, align;
+	unsigned long size, align;
 
-		size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
-		align = 1 << (INTERNODE_CACHE_SHIFT);
-		mem_section = memblock_alloc_or_panic(size, align);
-	}
+	size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+	align = 1 << (INTERNODE_CACHE_SHIFT);
+	mem_section = memblock_alloc_or_panic(size, align);

Given that there is no other code that assigns mem_section

Signature · 3 lines
Cheers,

David