* [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section
@ 2026-04-19 14:42 Sang-Heon Jeon
2026-04-20 6:49 ` Mike Rapoport
2026-04-20 11:36 ` Donet Tom
0 siblings, 2 replies; 4+ messages in thread
From: Sang-Heon Jeon @ 2026-04-19 14:42 UTC (permalink / raw)
To: akpm, david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko
Cc: linux-mm, 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.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
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(-)
diff --git a/mm/sparse.c b/mm/sparse.c
index effdac6b0ab1..e13f9f5fa090 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section
2026-04-19 14:42 [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section Sang-Heon Jeon
@ 2026-04-20 6:49 ` Mike Rapoport
2026-04-20 12:55 ` Sang-Heon Jeon
2026-04-20 11:36 ` Donet Tom
1 sibling, 1 reply; 4+ messages in thread
From: Mike Rapoport @ 2026-04-20 6:49 UTC (permalink / raw)
To: Sang-Heon Jeon
Cc: akpm, david, ljs, Liam.Howlett, vbabka, surenb, mhocko, linux-mm
Hi,
On Sun, Apr 19, 2026 at 11:42:25PM +0900, Sang-Heon Jeon wrote:
> 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.
>
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> 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 :)
> 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(-)
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index effdac6b0ab1..e13f9f5fa090 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -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)
> --
> 2.43.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section
2026-04-19 14:42 [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section Sang-Heon Jeon
2026-04-20 6:49 ` Mike Rapoport
@ 2026-04-20 11:36 ` Donet Tom
1 sibling, 0 replies; 4+ messages in thread
From: Donet Tom @ 2026-04-20 11:36 UTC (permalink / raw)
To: Sang-Heon Jeon, akpm, david, ljs, Liam.Howlett, vbabka, rppt,
surenb, mhocko
Cc: linux-mm
Hi
On 4/19/26 8:12 PM, Sang-Heon Jeon wrote:
> 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.
>
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
> ---
> 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(-)
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index effdac6b0ab1..e13f9f5fa090 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -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 <donettom@linux.ibm.com>
-Donet
> - 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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section
2026-04-20 6:49 ` Mike Rapoport
@ 2026-04-20 12:55 ` Sang-Heon Jeon
0 siblings, 0 replies; 4+ messages in thread
From: Sang-Heon Jeon @ 2026-04-20 12:55 UTC (permalink / raw)
To: Mike Rapoport
Cc: akpm, david, ljs, Liam.Howlett, vbabka, surenb, mhocko, linux-mm
Hi
On Mon, Apr 20, 2026 at 3:49 PM Mike Rapoport <rppt@kernel.org> wrote:
>
> Hi,
>
> On Sun, Apr 19, 2026 at 11:42:25PM +0900, Sang-Heon Jeon wrote:
> > 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.
> >
> > Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
>
> > ---
> > 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 :-(
> > 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(-)
> >
> > diff --git a/mm/sparse.c b/mm/sparse.c
> > index effdac6b0ab1..e13f9f5fa090 100644
> > --- a/mm/sparse.c
> > +++ b/mm/sparse.c
> > @@ -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)
> > --
> > 2.43.0
> >
>
> --
> Sincerely yours,
> Mike.
Best Regards,
Sang-Heon Jeon
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-20 12:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 14:42 [PATCH] mm/sparse: remove unnecessary NULL check before allocating mem_section Sang-Heon Jeon
2026-04-20 6:49 ` Mike Rapoport
2026-04-20 12:55 ` Sang-Heon Jeon
2026-04-20 11:36 ` Donet Tom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox