Skip to contentSkip to conversation

mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE (Part 1)

PATCH Applied David Hildenbrand (Arm) 7 participants 45 messages May 11 – May 21

Subsystems (6)
lore
Share & tools
lore

David Hildenbrand (Arm)

author maintainer
#0 lore raw

cover mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE (Part 1)

We want to remove CONFIG_HAVE_BOOTMEM_INFO_NODE. As a first step, let's limit the remaining harm to x86 and core code, removing sparc, ppc and s390 leftovers, starting the stepwise removal by removing and simplifying some code.

Once a related x86 vmemmap fix [1] is in, we can merge part 2 that will remove CONFIG_HAVE_BOOTMEM_INFO_NODE entirely.

Tested on x86-64 with hugetlb vmemmap optimization in combination with KMEMLEAK, making sure that the problem reported in dd0ff4d12dd2 ("bootmem:
remove the vmemmap pages from kmemleak in put_page_bootmem") does not reappear -- hoping I managed to trigger the original problem.

Heavily cross-compiled, but let's let build bots run on it for a bit.

[1] https://lore.kernel.org/r/[email protected]

---
David Hildenbrand (Arm) (8):
sparc/mm: remove register_page_bootmem_info() mm/bootmem_info: drop initialization of page->lru mm/bootmem_info: stop using PG_private
mm/bootmem_info: remove call to kmemleak_free_part_phys() mm/bootmem_info: stop marking the pgdat as NODE_INFO mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO s390/mm: use free_reserved_page() in vmem_free_pages() powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

 arch/powerpc/mm/init_64.c    |  8 --------
 arch/s390/mm/vmem.c          |  3 +--
 arch/sparc/mm/init_64.c      | 20 --------------------
 include/linux/bootmem_info.h |  1 -
 mm/Kconfig                   |  2 +-
 mm/bootmem_info.c            | 25 ++-----------------------
 6 files changed, 4 insertions(+), 55 deletions(-)

---

base-commit: e9dd96806dbc2d50a66770b6a86962bd5d601153

change-id: 20260511-bootmem_info_prep-bfc0e7a5b87e

--

Cheers,

David

author maintainer
#1 lore raw

PATCH 1/8 sparc/mm: remove register_page_bootmem_info()

sparc does not select CONFIG_HAVE_BOOTMEM_INFO_NODE, therefore, register_page_bootmem_info_node() is a nop.

Let's just get rid of register_page_bootmem_info().

---
 arch/sparc/mm/init_64.c | 20 --------------------
 1 file changed, 20 deletions(-)
arch/sparc/mm/init_64.c +0 -20
index 367c269305e5..3b679b1d1d72 100644
@@ -27,7 +27,6 @@
 #include <linux/percpu.h>
 #include <linux/mmzone.h>
 #include <linux/gfp.h>
-#include <linux/bootmem_info.h>
 
 #include <asm/head.h>
 #include <asm/page.h>
@@ -2477,17 +2476,6 @@ int page_in_phys_avail(unsigned long paddr)
 	return 0;
 }
 
-static void __init register_page_bootmem_info(void)
-{
-#ifdef CONFIG_NUMA
-	int i;
-
-	for_each_online_node(i)
-		if (NODE_DATA(i)->node_spanned_pages)
-			register_page_bootmem_info_node(NODE_DATA(i));
-#endif
-}
-
 void __init arch_setup_zero_pages(void)
 {
 	phys_addr_t zero_page_pa = kern_base +
@@ -2498,14 +2486,6 @@ void __init arch_setup_zero_pages(void)
 
 void __init mem_init(void)
 {
-	/*
-	 * Must be done after boot memory is put on freelist, because here we
-	 * might set fields in deferred struct pages that have not yet been
-	 * initialized, and memblock_free_all() initializes all the reserved
-	 * deferred pages for us.
-	 */
-	register_page_bootmem_info();
-
 	if (tlb_type == cheetah || tlb_type == cheetah_plus)
 		cheetah_ecache_flush_init();
 }
Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH 2/8 mm/bootmem_info: drop initialization of page->lru

In reply to David Hildenbrand (Arm)

In the past, we used to store the type in page->lru.next, introduced by commit 5f24ce5fd34c ("thp: remove PG_buddy"). The location changed over the years; ever since commit 0386aaa6e9c8 ("bootmem: stop using page->index"), we store it alongside the info in page->private.

Consequently, there is no need to reset page->lru anymore.

---
 mm/bootmem_info.c | 1 -
 1 file changed, 1 deletion(-)
mm/bootmem_info.c +0 -1
index 3d7675a3ae04..a0a1ecdec8d0 100644
@@ -34,7 +34,6 @@ void put_page_bootmem(struct page *page)
 	if (page_ref_dec_return(page) == 1) {
 		ClearPagePrivate(page);
 		set_page_private(page, 0);
-		INIT_LIST_HEAD(&page->lru);
 		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
 	}
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 3/8 mm/bootmem_info: stop using PG_private

In reply to David Hildenbrand (Arm)

Nobody checks PG_private for these pages, and we can happily use set_page_private() without setting PG_private. So let's just stop setting/clearing PG_private.

---
 mm/bootmem_info.c | 2 --
 1 file changed, 2 deletions(-)
mm/bootmem_info.c +0 -2
index a0a1ecdec8d0..6e2aaab3dca9 100644
@@ -19,7 +19,6 @@ void get_page_bootmem(unsigned long info, struct page *page,
 {
 	BUG_ON(type > 0xf);
 	BUG_ON(info > (ULONG_MAX >> 4));
-	SetPagePrivate(page);
 	set_page_private(page, info << 4 | type);
 	page_ref_inc(page);
 }
@@ -32,7 +31,6 @@ void put_page_bootmem(struct page *page)
 	       type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
 
 	if (page_ref_dec_return(page) == 1) {
-		ClearPagePrivate(page);
 		set_page_private(page, 0);
 		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
Signature · 1 line
2.43.0
author maintainer
#13 lore raw

PATCH 4/8 mm/bootmem_info: remove call to kmemleak_free_part_phys()

In reply to David Hildenbrand (Arm)

The call to kmemleak_free_part_phys() was added in 2022 in commit dd0ff4d12dd2 ("bootmem: remove the vmemmap pages from kmemleak in put_page_bootmem").

In 2025, commit b2aad24b5333 ("mm/memmap: prevent double scanning of memmap by kmemleak") started to use MEMBLOCK_ALLOC_NOLEAKTRACE when allocating the memmap to skip the kmemleak_alloc_phys() in the buddy.

So remove the call to kmemleak_free_part_phys(). If this would still be required for other purposes, either free_reserved_page() should take care of it, or selected users.

---
 include/linux/bootmem_info.h | 1 -
 mm/bootmem_info.c            | 1 -
 2 files changed, 2 deletions(-)
include/linux/bootmem_info.h +0 -1
index 492ceeb1cdf8..f724340755e5 100644
@@ -82,7 +82,6 @@ static inline void get_page_bootmem(unsigned long info, struct page *page,
 
 static inline void free_bootmem_page(struct page *page)
 {
-	kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 	free_reserved_page(page);
 }
 #endif
mm/bootmem_info.c +0 -1
index 6e2aaab3dca9..74c1116626c8 100644
@@ -32,7 +32,6 @@ void put_page_bootmem(struct page *page)
 
 	if (page_ref_dec_return(page) == 1) {
 		set_page_private(page, 0);
-		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
 	}
 }
Signature · 1 line
2.43.0
author maintainer
#18 lore raw

PATCH 5/8 mm/bootmem_info: stop marking the pgdat as NODE_INFO

In reply to David Hildenbrand (Arm)

We removed the last user of NODE_INFO in commit 119c31caa59e ("mm/sparse:
remove !CONFIG_SPARSEMEM_VMEMMAP leftovers for CONFIG_MEMORY_HOTPLUG").

But it really was never used it besides for safety-checks ever since it was introduced in commit 04753278769f ("memory hotplug: register section/node id to free"), where we had the comment:

5) The node information like pgdat has similar issues. But, this will be able to be solved too by this.
(Not implemented yet, but, remembering node id in the pages.)

Of course, that never happened, and we are not planning on freeing the node data (pgdat/pglist_data), during memory hotunplug.

So let's just stop marking the pgdat as NODE_INFO.

---
 mm/bootmem_info.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
mm/bootmem_info.c +1 -8
index 74c1116626c8..cce1d560f094 100644
@@ -62,15 +62,8 @@ static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 
 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
 {
-	unsigned long i, pfn, end_pfn, nr_pages;
+	unsigned long pfn, end_pfn;
 	int node = pgdat->node_id;
-	struct page *page;
-
-	nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
-	page = virt_to_page(pgdat);
-
-	for (i = 0; i < nr_pages; i++, page++)
-		get_page_bootmem(node, page, NODE_INFO);
 
 	pfn = pgdat->node_start_pfn;
 	end_pfn = pgdat_end_pfn(pgdat);
Signature · 1 line
2.43.0
author maintainer
#24 lore raw

PATCH 6/8 mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO

In reply to David Hildenbrand (Arm)

We never free the ms->usage data for boot memory sections (see section_deactivate()). And to identify whether ms->usage was allocated from memblock, we simply identify it by looking at PG_reserved.

Consequently, there is no need to mark ms->usage as MIX_SECTION_INFO. Let's just stop doing that.

---
 mm/bootmem_info.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
mm/bootmem_info.c +1 -11
index cce1d560f094..0fa78db7fbc0 100644
@@ -38,10 +38,8 @@ void put_page_bootmem(struct page *page)
 
 static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 {
-	unsigned long mapsize, section_nr, i;
+	unsigned long section_nr;
 	struct mem_section *ms;
-	struct mem_section_usage *usage;
-	struct page *page;
 
 	start_pfn = SECTION_ALIGN_DOWN(start_pfn);
 	section_nr = pfn_to_section_nr(start_pfn);
@@ -50,14 +48,6 @@ static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 	if (!preinited_vmemmap_section(ms))
 		register_page_bootmem_memmap(section_nr, pfn_to_page(start_pfn),
 					     PAGES_PER_SECTION);
-
-	usage = ms->usage;
-	page = virt_to_page(usage);
-
-	mapsize = PAGE_ALIGN(mem_section_usage_size()) >> PAGE_SHIFT;
-
-	for (i = 0; i < mapsize; i++, page++)
-		get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
 }
 
 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
Signature · 1 line
2.43.0
author maintainer
#28 lore raw

PATCH 7/8 s390/mm: use free_reserved_page() in vmem_free_pages()

In reply to David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

---
 arch/s390/mm/vmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/mm/vmem.c +1 -2
index eeadff45e0e1..d8b2a60e0c33 100644
@@ -4,7 +4,6 @@
  */
 
 #include <linux/memory_hotplug.h>
-#include <linux/bootmem_info.h>
 #include <linux/cpufeature.h>
 #include <linux/memblock.h>
 #include <linux/pfn.h>
@@ -51,7 +50,7 @@ static void vmem_free_pages(unsigned long addr, int order, struct vmem_altmap *a
 	if (PageReserved(page)) {
 		/* allocated from memblock */
 		while (nr_pages--)
-			free_bootmem_page(page++);
+			free_reserved_page(page++);
 	} else {
 		free_pages(addr, order);
 	}
Signature · 1 line
2.43.0
author maintainer
#36 lore raw

PATCH 8/8 powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

In reply to David Hildenbrand (Arm)

register_page_bootmem_info_node() essentially only calls register_page_bootmem_memmap(). However, on powerpc that function is a nop. So there is not benefit in using CONFIG_HAVE_BOOTMEM_INFO_NODE anymore, let's just drop it.

We can stop including bootmem_info.h.

---
 arch/powerpc/mm/init_64.c | 8 --------
 mm/Kconfig                | 2 +-
 2 files changed, 1 insertion(+), 9 deletions(-)
arch/powerpc/mm/init_64.c +0 -8
index b6f3ae03ca9e..64f0df5bb5cd 100644
@@ -41,7 +41,6 @@
 #include <linux/libfdt.h>
 #include <linux/memremap.h>
 #include <linux/memory.h>
-#include <linux/bootmem_info.h>
 
 #include <asm/pgalloc.h>
 #include <asm/page.h>
@@ -388,13 +387,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
 
 #endif
 
-#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
-void register_page_bootmem_memmap(unsigned long section_nr,
-				  struct page *start_page, unsigned long size)
-{
-}
-#endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */
-
 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
 
 #ifdef CONFIG_PPC_BOOK3S_64
mm/Kconfig +1 -1
index e221fa1dc54d..97b079372325 100644
@@ -537,7 +537,7 @@ endchoice
 
 config MEMORY_HOTREMOVE
 	bool "Allow for memory hot remove"
-	select HAVE_BOOTMEM_INFO_NODE if (X86_64 || PPC64)
+	select HAVE_BOOTMEM_INFO_NODE if X86_64
 	depends on MEMORY_HOTPLUG
 	select MIGRATION
 
Signature · 1 line
2.43.0
maintainer
#29 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

In reply to David Hildenbrand (Arm)
Quoted 27 lines · David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

---
 arch/s390/mm/vmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/mm/vmem.c +0 -1
index eeadff45e0e1..d8b2a60e0c33 100644
@@ -4,7 +4,6 @@
  */
 
 #include <linux/memory_hotplug.h>
-#include <linux/bootmem_info.h>
 #include <linux/cpufeature.h>
 #include <linux/memblock.h>
 #include <linux/pfn.h>

arch/s390/mm/vmem.c static void vmem_free_pages(unsigned long addr, int order, struct vmem_altmap *a · line 53

Quoted 5 lines
arch/s390/mm/vmem.c +1 -1
@@ -51,7 +50,7 @@ static void vmem_free_pages(unsigned long addr, int order, struct vmem_altmap *a
 	if (PageReserved(page)) {
 		/* allocated from memblock */
 		while (nr_pages--)
-			free_bootmem_page(page++);
+			free_reserved_page(page++);

What about the implicit call of kmemleak_free_part_phys() which gets removed with this?

author maintainer
#30 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

Quoted 22 lines · Heiko Carstens
Quoted 21 lines · David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

---
 arch/s390/mm/vmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/mm/vmem.c +0 -0
index eeadff45e0e1..d8b2a60e0c33 100644
@@ -4,7 +4,6 @@
  */
 
Quoted 14 lines

arch/s390/mm/vmem.c static void vmem_free_pages(unsigned long addr, int order, struct vmem_altmap *a · line 53

Quoted 11 lines
arch/s390/mm/vmem.c +1 -2
 #include <linux/memory_hotplug.h>
-#include <linux/bootmem_info.h>
 #include <linux/cpufeature.h>
 #include <linux/memblock.h>
 #include <linux/pfn.h>
@@ -51,7 +50,7 @@ static void vmem_free_pages(unsigned long addr, int order, struct vmem_altmap *a
 	if (PageReserved(page)) {
 		/* allocated from memblock */
 		while (nr_pages--)
-			free_bootmem_page(page++);
+			free_reserved_page(page++);

What about the implicit call of kmemleak_free_part_phys() which gets removed with this?

Thanks for taking a look!

See patch #4:

https://lore.kernel.org/r/[email protected]

Signature · 3 lines
Cheers,

David
maintainer Acked-by
#31 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

Quoted 15 lines · David Hildenbrand (Arm)
Quoted 14 lines · Heiko Carstens
Quoted 13 lines · David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

---
 arch/s390/mm/vmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

...

Quoted 8 lines
Quoted 2 lines

What about the implicit call of kmemleak_free_part_phys() which gets removed with this?

Thanks for taking a look!

See patch #4:

https://lore.kernel.org/r/[email protected]

Heh, right, you can't expect from me that I would read more than one patch of a series :)

author maintainer
#32 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

Quoted 6 lines · Heiko Carstens
Quoted 1 line · David Hildenbrand (Arm)

On 5/11/26 16:21, Heiko Carstens wrote:

...

Quoted 3 lines
Quoted 2 lines

What about the implicit call of kmemleak_free_part_phys() which gets removed with this?

Quoted 8 lines
Quoted 5 lines

Thanks for taking a look!

See patch #4:

https://lore.kernel.org/r/[email protected]

Heh, right, you can't expect from me that I would read more than one patch of a series :)

:)

Let me add a hint that a recent patch changed that.

Thanks!

Signature · 3 lines
Cheers,

David
reviewer
#19 lore raw

Re: [PATCH 5/8] mm/bootmem_info: stop marking the pgdat as NODE_INFO

In reply to David Hildenbrand (Arm)
Quoted 7 lines · David Hildenbrand

We removed the last user of NODE_INFO in commit 119c31caa59e ("mm/sparse:
remove !CONFIG_SPARSEMEM_VMEMMAP leftovers for CONFIG_MEMORY_HOTPLUG").

But it really was never used it besides for safety-checks ever since it was introduced in commit 04753278769f ("memory hotplug: register section/node id to free"), where we had the comment:

Quoted 8 lines

5) The node information like pgdat has similar issues. But, this will be able to be solved too by this.
(Not implemented yet, but, remembering node id in the pages.)

Of course, that never happened, and we are not planning on freeing the node data (pgdat/pglist_data), during memory hotunplug.

So let's just stop marking the pgdat as NODE_INFO.

With the last user, shouldn't we simply drop NODE_INFO?

Quoted 30 lines
---
 mm/bootmem_info.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
mm/bootmem_info.c +1 -8
index 74c1116626c8..cce1d560f094 100644
@@ -62,15 +62,8 @@ static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 
 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
 {
-	unsigned long i, pfn, end_pfn, nr_pages;
+	unsigned long pfn, end_pfn;
 	int node = pgdat->node_id;
-	struct page *page;
-
-	nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
-	page = virt_to_page(pgdat);
-
-	for (i = 0; i < nr_pages; i++, page++)
-		get_page_bootmem(node, page, NODE_INFO);
 
 	pfn = pgdat->node_start_pfn;
 	end_pfn = pgdat_end_pfn(pgdat);
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Michal Hocko
SUSE Labs
reviewer Acked-by on the v1 series
#41 lore raw
In reply to David Hildenbrand (Arm)
Quoted 29 lines · David Hildenbrand

We want to remove CONFIG_HAVE_BOOTMEM_INFO_NODE. As a first step, let's limit the remaining harm to x86 and core code, removing sparc, ppc and s390 leftovers, starting the stepwise removal by removing and simplifying some code.

Once a related x86 vmemmap fix [1] is in, we can merge part 2 that will remove CONFIG_HAVE_BOOTMEM_INFO_NODE entirely.

Tested on x86-64 with hugetlb vmemmap optimization in combination with KMEMLEAK, making sure that the problem reported in dd0ff4d12dd2 ("bootmem:
remove the vmemmap pages from kmemleak in put_page_bootmem") does not reappear -- hoping I managed to trigger the original problem.

Heavily cross-compiled, but let's let build bots run on it for a bit.

[1] https://lore.kernel.org/r/[email protected]

---
David Hildenbrand (Arm) (8):
sparc/mm: remove register_page_bootmem_info() mm/bootmem_info: drop initialization of page->lru mm/bootmem_info: stop using PG_private
mm/bootmem_info: remove call to kmemleak_free_part_phys() mm/bootmem_info: stop marking the pgdat as NODE_INFO mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO s390/mm: use free_reserved_page() in vmem_free_pages() powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

Quoted 7 lines
 arch/powerpc/mm/init_64.c    |  8 --------
 arch/s390/mm/vmem.c          |  3 +--
 arch/sparc/mm/init_64.c      | 20 --------------------
 include/linux/bootmem_info.h |  1 -
 mm/Kconfig                   |  2 +-
 mm/bootmem_info.c            | 25 ++-----------------------
 6 files changed, 4 insertions(+), 55 deletions(-)

Good clean up. Feel free to add

to all patches but kmemleak one which I do not feel qualified to judge.

Thanks!

Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#20 lore raw

Re: [PATCH 5/8] mm/bootmem_info: stop marking the pgdat as NODE_INFO

In reply to Michal Hocko
Quoted 12 lines · Michal Hocko
Quoted 11 lines · David Hildenbrand

We removed the last user of NODE_INFO in commit 119c31caa59e ("mm/sparse:
remove !CONFIG_SPARSEMEM_VMEMMAP leftovers for CONFIG_MEMORY_HOTPLUG").

But it really was never used it besides for safety-checks ever since it was introduced in commit 04753278769f ("memory hotplug: register section/node id to free"), where we had the comment:

5) The node information like pgdat has similar issues. But, this will be able to be solved too by this.
(Not implemented yet, but, remembering node id in the pages.)

Quoted 6 lines
Quoted 4 lines

Of course, that never happened, and we are not planning on freeing the node data (pgdat/pglist_data), during memory hotunplug.

So let's just stop marking the pgdat as NODE_INFO.

With the last user, shouldn't we simply drop NODE_INFO?

I'll drop the whole thing in part 2.

I actually had both parts together until I stumbled into the vmmemmap x86 freeing issue that now causes conflicts until upstream and synced to the MM tree.

Signature · 3 lines
Cheers,

David
author maintainer
#42 lore raw
In reply to Michal Hocko
Quoted 38 lines · Michal Hocko
Quoted 29 lines · David Hildenbrand

We want to remove CONFIG_HAVE_BOOTMEM_INFO_NODE. As a first step, let's limit the remaining harm to x86 and core code, removing sparc, ppc and s390 leftovers, starting the stepwise removal by removing and simplifying some code.

Once a related x86 vmemmap fix [1] is in, we can merge part 2 that will remove CONFIG_HAVE_BOOTMEM_INFO_NODE entirely.

Tested on x86-64 with hugetlb vmemmap optimization in combination with KMEMLEAK, making sure that the problem reported in dd0ff4d12dd2 ("bootmem:
remove the vmemmap pages from kmemleak in put_page_bootmem") does not reappear -- hoping I managed to trigger the original problem.

Heavily cross-compiled, but let's let build bots run on it for a bit.

[1] https://lore.kernel.org/r/[email protected]

---
David Hildenbrand (Arm) (8):
sparc/mm: remove register_page_bootmem_info() mm/bootmem_info: drop initialization of page->lru mm/bootmem_info: stop using PG_private
mm/bootmem_info: remove call to kmemleak_free_part_phys() mm/bootmem_info: stop marking the pgdat as NODE_INFO mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO s390/mm: use free_reserved_page() in vmem_free_pages() powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

Quoted 7 lines
 arch/powerpc/mm/init_64.c    |  8 --------
 arch/s390/mm/vmem.c          |  3 +--
 arch/sparc/mm/init_64.c      | 20 --------------------
 include/linux/bootmem_info.h |  1 -
 mm/Kconfig                   |  2 +-
 mm/bootmem_info.c            | 25 ++-----------------------
 6 files changed, 4 insertions(+), 55 deletions(-)
Quoted 2 lines

Good clean up. Feel free to add

Thanks!

Quoted 1 line

to all patches but kmemleak one which I do not feel qualified to judge.

It's black magic to me as well. I tried to test that scenario in particular and was not able to trigger the problem.

Signature · 3 lines
Cheers,

David
Acked-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] sparc/mm: remove register_page_bootmem_info()

In reply to David Hildenbrand (Arm)
Quoted 6 lines · David Hildenbrand (Arm)

sparc does not select CONFIG_HAVE_BOOTMEM_INFO_NODE, therefore, register_page_bootmem_info_node() is a nop.

Let's just get rid of register_page_bootmem_info().

Signature · 2 lines
Oscar Salvador
SUSE Labs
Acked-by on v1 2/8
#6 lore raw

Re: [PATCH 2/8] mm/bootmem_info: drop initialization of page->lru

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

In the past, we used to store the type in page->lru.next, introduced by commit 5f24ce5fd34c ("thp: remove PG_buddy"). The location changed over the years; ever since commit 0386aaa6e9c8 ("bootmem: stop using page->index"), we store it alongside the info in page->private.

Consequently, there is no need to reset page->lru anymore.

Signature · 2 lines
Oscar Salvador
SUSE Labs
Acked-by on v1 3/8
#10 lore raw

Re: [PATCH 3/8] mm/bootmem_info: stop using PG_private

In reply to David Hildenbrand (Arm)
Quoted 5 lines · David Hildenbrand (Arm)

Nobody checks PG_private for these pages, and we can happily use set_page_private() without setting PG_private. So let's just stop setting/clearing PG_private.

Signature · 2 lines
Oscar Salvador
SUSE Labs
Reviewed-by on v1 4/8
#14 lore raw

Re: [PATCH 4/8] mm/bootmem_info: remove call to kmemleak_free_part_phys()

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

The call to kmemleak_free_part_phys() was added in 2022 in commit dd0ff4d12dd2 ("bootmem: remove the vmemmap pages from kmemleak in put_page_bootmem").

In 2025, commit b2aad24b5333 ("mm/memmap: prevent double scanning of memmap by kmemleak") started to use MEMBLOCK_ALLOC_NOLEAKTRACE when allocating the memmap to skip the kmemleak_alloc_phys() in the buddy.

Quoted 5 lines

So remove the call to kmemleak_free_part_phys(). If this would still be required for other purposes, either free_reserved_page() should take care of it, or selected users.

Quoted 22 lines
---
 include/linux/bootmem_info.h | 1 -
 mm/bootmem_info.c            | 1 -
 2 files changed, 2 deletions(-)
include/linux/bootmem_info.h +0 -1
index 492ceeb1cdf8..f724340755e5 100644
@@ -82,7 +82,6 @@ static inline void get_page_bootmem(unsigned long info, struct page *page,
 
 static inline void free_bootmem_page(struct page *page)
 {
-	kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 	free_reserved_page(page);
 }
 #endif
mm/bootmem_info.c +0 -0
index 6e2aaab3dca9..74c1116626c8 100644

mm/bootmem_info.c void put_page_bootmem(struct page *page) · line 35

Quoted 4 lines
mm/bootmem_info.c +0 -1
@@ -32,7 +32,6 @@ void put_page_bootmem(struct page *page)
 
 	if (page_ref_dec_return(page) == 1) {
 		set_page_private(page, 0);
-		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);

A bit odd that kmemleak_free_part_phys() did not complain if we never did kmemleak_alloc_phys() for these pages?

Signature · 2 lines
Oscar Salvador
SUSE Labs
Acked-by on v1 5/8
#21 lore raw

Re: [PATCH 5/8] mm/bootmem_info: stop marking the pgdat as NODE_INFO

In reply to David Hildenbrand (Arm)
Quoted 11 lines · David Hildenbrand (Arm)

We removed the last user of NODE_INFO in commit 119c31caa59e ("mm/sparse:
remove !CONFIG_SPARSEMEM_VMEMMAP leftovers for CONFIG_MEMORY_HOTPLUG").

But it really was never used it besides for safety-checks ever since it was introduced in commit 04753278769f ("memory hotplug: register section/node id to free"), where we had the comment:

5) The node information like pgdat has similar issues. But, this will be able to be solved too by this.
(Not implemented yet, but, remembering node id in the pages.)

Quoted 6 lines

Of course, that never happened, and we are not planning on freeing the node data (pgdat/pglist_data), during memory hotunplug.

So let's just stop marking the pgdat as NODE_INFO.

Signature · 2 lines
Oscar Salvador
SUSE Labs
Acked-by on v1 6/8
#25 lore raw

Re: [PATCH 6/8] mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

We never free the ms->usage data for boot memory sections (see section_deactivate()). And to identify whether ms->usage was allocated from memblock, we simply identify it by looking at PG_reserved.

Consequently, there is no need to mark ms->usage as MIX_SECTION_INFO. Let's just stop doing that.

Signature · 2 lines
Oscar Salvador
SUSE Labs
Reviewed-by on v1 7/8
#33 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

In reply to David Hildenbrand (Arm)
Quoted 10 lines · David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

Signature · 2 lines
Oscar Salvador
SUSE Labs
Acked-by on v1 8/8
#37 lore raw

Re: [PATCH 8/8] powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

register_page_bootmem_info_node() essentially only calls register_page_bootmem_memmap(). However, on powerpc that function is a nop. So there is not benefit in using CONFIG_HAVE_BOOTMEM_INFO_NODE anymore, let's just drop it.

We can stop including bootmem_info.h.

Quoted 49 lines
---
 arch/powerpc/mm/init_64.c | 8 --------
 mm/Kconfig                | 2 +-
 2 files changed, 1 insertion(+), 9 deletions(-)
arch/powerpc/mm/init_64.c +0 -8
index b6f3ae03ca9e..64f0df5bb5cd 100644
@@ -41,7 +41,6 @@
 #include <linux/libfdt.h>
 #include <linux/memremap.h>
 #include <linux/memory.h>
-#include <linux/bootmem_info.h>
 
 #include <asm/pgalloc.h>
 #include <asm/page.h>
@@ -388,13 +387,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
 
 #endif
 
-#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
-void register_page_bootmem_memmap(unsigned long section_nr,
-				  struct page *start_page, unsigned long size)
-{
-}
-#endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */
-
 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
 
 #ifdef CONFIG_PPC_BOOK3S_64
mm/Kconfig +1 -1
index e221fa1dc54d..97b079372325 100644
@@ -537,7 +537,7 @@ endchoice
 
 config MEMORY_HOTREMOVE
 	bool "Allow for memory hot remove"
-	select HAVE_BOOTMEM_INFO_NODE if (X86_64 || PPC64)
+	select HAVE_BOOTMEM_INFO_NODE if X86_64
 	depends on MEMORY_HOTPLUG
 	select MIGRATION
 
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Oscar Salvador
SUSE Labs
author maintainer
#15 lore raw

Re: [PATCH 4/8] mm/bootmem_info: remove call to kmemleak_free_part_phys()

In reply to Oscar Salvador
Quoted 40 lines · Oscar Salvador
Quoted 8 lines · David Hildenbrand (Arm)

The call to kmemleak_free_part_phys() was added in 2022 in commit dd0ff4d12dd2 ("bootmem: remove the vmemmap pages from kmemleak in put_page_bootmem").

In 2025, commit b2aad24b5333 ("mm/memmap: prevent double scanning of memmap by kmemleak") started to use MEMBLOCK_ALLOC_NOLEAKTRACE when allocating the memmap to skip the kmemleak_alloc_phys() in the buddy.

Quoted 5 lines

So remove the call to kmemleak_free_part_phys(). If this would still be required for other purposes, either free_reserved_page() should take care of it, or selected users.

Quoted 23 lines
---
 include/linux/bootmem_info.h | 1 -
 mm/bootmem_info.c            | 1 -
 2 files changed, 2 deletions(-)
include/linux/bootmem_info.h +0 -1
index 492ceeb1cdf8..f724340755e5 100644
@@ -82,7 +82,6 @@ static inline void get_page_bootmem(unsigned long info, struct page *page,
 
 static inline void free_bootmem_page(struct page *page)
 {
-	kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 	free_reserved_page(page);
 }
 #endif
mm/bootmem_info.c +0 -0
index 6e2aaab3dca9..74c1116626c8 100644
@@ -32,7 +32,6 @@ void put_page_bootmem(struct page *page)
 
Quoted 6 lines

mm/bootmem_info.c void put_page_bootmem(struct page *page) · line 35

Quoted 3 lines
mm/bootmem_info.c +0 -1
 	if (page_ref_dec_return(page) == 1) {
 		set_page_private(page, 0);
-		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);

A bit odd that kmemleak_free_part_phys() did not complain if we never did kmemleak_alloc_phys() for these pages?

delete_object_part() calls __find_and_remove_object() and essentially just skips if it didn't find anything.

Maybe the kmemleak_warn() would trigger, but it's guarded by "#ifdef DEBUG" ...

Signature · 3 lines
Cheers,

David
#43 lore raw
In reply to David Hildenbrand (Arm)
Quoted 13 lines · David Hildenbrand (Arm)

We want to remove CONFIG_HAVE_BOOTMEM_INFO_NODE. As a first step, let's limit the remaining harm to x86 and core code, removing sparc, ppc and s390 leftovers, starting the stepwise removal by removing and simplifying some code.

Once a related x86 vmemmap fix [1] is in, we can merge part 2 that will remove CONFIG_HAVE_BOOTMEM_INFO_NODE entirely.

Tested on x86-64 with hugetlb vmemmap optimization in combination with KMEMLEAK, making sure that the problem reported in dd0ff4d12dd2 ("bootmem:
remove the vmemmap pages from kmemleak in put_page_bootmem") does not reappear -- hoping I managed to trigger the original problem.

Quoted 5 lines

Heavily cross-compiled, but let's let build bots run on it for a bit.

[1] https://lore.kernel.org/r/[email protected]

Awesome cleanup David, thanks for doing this ;-)

Signature · 2 lines
Oscar Salvador
SUSE Labs
author maintainer
#44 lore raw
Quoted 14 lines · Oscar Salvador
Quoted 13 lines · David Hildenbrand (Arm)

We want to remove CONFIG_HAVE_BOOTMEM_INFO_NODE. As a first step, let's limit the remaining harm to x86 and core code, removing sparc, ppc and s390 leftovers, starting the stepwise removal by removing and simplifying some code.

Once a related x86 vmemmap fix [1] is in, we can merge part 2 that will remove CONFIG_HAVE_BOOTMEM_INFO_NODE entirely.

Tested on x86-64 with hugetlb vmemmap optimization in combination with KMEMLEAK, making sure that the problem reported in dd0ff4d12dd2 ("bootmem:
remove the vmemmap pages from kmemleak in put_page_bootmem") does not reappear -- hoping I managed to trigger the original problem.

Quoted 7 lines
Quoted 5 lines

Heavily cross-compiled, but let's let build bots run on it for a bit.

[1] https://lore.kernel.org/r/[email protected]

Awesome cleanup David, thanks for doing this ;-)

Thanks for the review, I'm sure you'll enjoy part 2 :)

Signature · 3 lines
Cheers,

David
reviewer Reviewed-by on v1 8/8
#38 lore raw

Re: [PATCH 8/8] powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

In reply to David Hildenbrand (Arm)
Quoted 6 lines · David Hildenbrand (Arm)

register_page_bootmem_info_node() essentially only calls register_page_bootmem_memmap(). However, on powerpc that function is a nop. So there is not benefit in using CONFIG_HAVE_BOOTMEM_INFO_NODE anymore, let's just drop it.

We can stop including bootmem_info.h.

Yup, the following patch [1] removed the usage of bootmem more than a decade ago. Thanks for cleaning up the remaining unused pieces.

[1]: https://lore.kernel.org/all/[email protected]/

LGTM. Please feel free to add:

reviewer Reviewed-by on v1 1/8
#3 lore raw

Re: [PATCH 1/8] sparc/mm: remove register_page_bootmem_info()

In reply to David Hildenbrand (Arm)
Quoted 6 lines · David Hildenbrand (Arm)

sparc does not select CONFIG_HAVE_BOOTMEM_INFO_NODE, therefore, register_page_bootmem_info_node() is a nop.

Let's just get rid of register_page_bootmem_info().

Quoted 3 lines
---
 arch/sparc/mm/init_64.c | 20 --------------------
 1 file changed, 20 deletions(-)
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 2/8
#7 lore raw

Re: [PATCH 2/8] mm/bootmem_info: drop initialization of page->lru

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

In the past, we used to store the type in page->lru.next, introduced by commit 5f24ce5fd34c ("thp: remove PG_buddy"). The location changed over the years; ever since commit 0386aaa6e9c8 ("bootmem: stop using page->index"), we store it alongside the info in page->private.

Consequently, there is no need to reset page->lru anymore.

Quoted 20 lines
---
 mm/bootmem_info.c | 1 -
 1 file changed, 1 deletion(-)
mm/bootmem_info.c +0 -1
index 3d7675a3ae04..a0a1ecdec8d0 100644
@@ -34,7 +34,6 @@ void put_page_bootmem(struct page *page)
 	if (page_ref_dec_return(page) == 1) {
 		ClearPagePrivate(page);
 		set_page_private(page, 0);
-		INIT_LIST_HEAD(&page->lru);
 		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
 	}
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 3/8
#11 lore raw

Re: [PATCH 3/8] mm/bootmem_info: stop using PG_private

In reply to David Hildenbrand (Arm)
Quoted 5 lines · David Hildenbrand (Arm)

Nobody checks PG_private for these pages, and we can happily use set_page_private() without setting PG_private. So let's just stop setting/clearing PG_private.

Quoted 28 lines
---
 mm/bootmem_info.c | 2 --
 1 file changed, 2 deletions(-)
mm/bootmem_info.c +0 -2
index a0a1ecdec8d0..6e2aaab3dca9 100644
@@ -19,7 +19,6 @@ void get_page_bootmem(unsigned long info, struct page *page,
 {
 	BUG_ON(type > 0xf);
 	BUG_ON(info > (ULONG_MAX >> 4));
-	SetPagePrivate(page);
 	set_page_private(page, info << 4 | type);
 	page_ref_inc(page);
 }
@@ -32,7 +31,6 @@ void put_page_bootmem(struct page *page)
 	       type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
 
 	if (page_ref_dec_return(page) == 1) {
-		ClearPagePrivate(page);
 		set_page_private(page, 0);
 		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 4/8
#17 lore raw

Re: [PATCH 4/8] mm/bootmem_info: remove call to kmemleak_free_part_phys()

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

The call to kmemleak_free_part_phys() was added in 2022 in commit dd0ff4d12dd2 ("bootmem: remove the vmemmap pages from kmemleak in put_page_bootmem").

In 2025, commit b2aad24b5333 ("mm/memmap: prevent double scanning of memmap by kmemleak") started to use MEMBLOCK_ALLOC_NOLEAKTRACE when allocating the memmap to skip the kmemleak_alloc_phys() in the buddy.

Quoted 5 lines

So remove the call to kmemleak_free_part_phys(). If this would still be required for other purposes, either free_reserved_page() should take care of it, or selected users.

Quoted 33 lines
---
 include/linux/bootmem_info.h | 1 -
 mm/bootmem_info.c            | 1 -
 2 files changed, 2 deletions(-)
include/linux/bootmem_info.h +0 -1
index 492ceeb1cdf8..f724340755e5 100644
@@ -82,7 +82,6 @@ static inline void get_page_bootmem(unsigned long info, struct page *page,
 
 static inline void free_bootmem_page(struct page *page)
 {
-	kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 	free_reserved_page(page);
 }
 #endif
mm/bootmem_info.c +0 -1
index 6e2aaab3dca9..74c1116626c8 100644
@@ -32,7 +32,6 @@ void put_page_bootmem(struct page *page)
 
 	if (page_ref_dec_return(page) == 1) {
 		set_page_private(page, 0);
-		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
 	}
 }
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 5/8
#22 lore raw

Re: [PATCH 5/8] mm/bootmem_info: stop marking the pgdat as NODE_INFO

In reply to David Hildenbrand (Arm)
Quoted 11 lines · David Hildenbrand (Arm)

We removed the last user of NODE_INFO in commit 119c31caa59e ("mm/sparse:
remove !CONFIG_SPARSEMEM_VMEMMAP leftovers for CONFIG_MEMORY_HOTPLUG").

But it really was never used it besides for safety-checks ever since it was introduced in commit 04753278769f ("memory hotplug: register section/node id to free"), where we had the comment:

5) The node information like pgdat has similar issues. But, this will be able to be solved too by this.
(Not implemented yet, but, remembering node id in the pages.)

Quoted 6 lines

Of course, that never happened, and we are not planning on freeing the node data (pgdat/pglist_data), during memory hotunplug.

So let's just stop marking the pgdat as NODE_INFO.

Quoted 29 lines
---
 mm/bootmem_info.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
mm/bootmem_info.c +1 -8
index 74c1116626c8..cce1d560f094 100644
@@ -62,15 +62,8 @@ static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 
 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
 {
-	unsigned long i, pfn, end_pfn, nr_pages;
+	unsigned long pfn, end_pfn;
 	int node = pgdat->node_id;
-	struct page *page;
-
-	nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
-	page = virt_to_page(pgdat);
-
-	for (i = 0; i < nr_pages; i++, page++)
-		get_page_bootmem(node, page, NODE_INFO);
 
 	pfn = pgdat->node_start_pfn;
 	end_pfn = pgdat_end_pfn(pgdat);
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 6/8
#26 lore raw

Re: [PATCH 6/8] mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

We never free the ms->usage data for boot memory sections (see section_deactivate()). And to identify whether ms->usage was allocated from memblock, we simply identify it by looking at PG_reserved.

Consequently, there is no need to mark ms->usage as MIX_SECTION_INFO. Let's just stop doing that.

Quoted 39 lines
---
 mm/bootmem_info.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
mm/bootmem_info.c +1 -11
index cce1d560f094..0fa78db7fbc0 100644
@@ -38,10 +38,8 @@ void put_page_bootmem(struct page *page)
 
 static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 {
-	unsigned long mapsize, section_nr, i;
+	unsigned long section_nr;
 	struct mem_section *ms;
-	struct mem_section_usage *usage;
-	struct page *page;
 
 	start_pfn = SECTION_ALIGN_DOWN(start_pfn);
 	section_nr = pfn_to_section_nr(start_pfn);
@@ -50,14 +48,6 @@ static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 	if (!preinited_vmemmap_section(ms))
 		register_page_bootmem_memmap(section_nr, pfn_to_page(start_pfn),
 					     PAGES_PER_SECTION);
-
-	usage = ms->usage;
-	page = virt_to_page(usage);
-
-	mapsize = PAGE_ALIGN(mem_section_usage_size()) >> PAGE_SHIFT;
-
-	for (i = 0; i < mapsize; i++, page++)
-		get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
 }
 
 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 7/8
#34 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

In reply to David Hildenbrand (Arm)
Quoted 10 lines · David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

Quoted 29 lines
---
 arch/s390/mm/vmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/mm/vmem.c +1 -2
index eeadff45e0e1..d8b2a60e0c33 100644
@@ -4,7 +4,6 @@
  */
 
 #include <linux/memory_hotplug.h>
-#include <linux/bootmem_info.h>
 #include <linux/cpufeature.h>
 #include <linux/memblock.h>
 #include <linux/pfn.h>
@@ -51,7 +50,7 @@ static void vmem_free_pages(unsigned long addr, int order, struct vmem_altmap *a
 	if (PageReserved(page)) {
 		/* allocated from memblock */
 		while (nr_pages--)
-			free_bootmem_page(page++);
+			free_reserved_page(page++);
 	} else {
 		free_pages(addr, order);
 	}
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
reviewer Reviewed-by on v1 8/8
#39 lore raw

Re: [PATCH 8/8] powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

In reply to David Hildenbrand (Arm)
Quoted 8 lines · David Hildenbrand (Arm)

register_page_bootmem_info_node() essentially only calls register_page_bootmem_memmap(). However, on powerpc that function is a nop. So there is not benefit in using CONFIG_HAVE_BOOTMEM_INFO_NODE anymore, let's just drop it.

We can stop including bootmem_info.h.

Quoted 48 lines
---
 arch/powerpc/mm/init_64.c | 8 --------
 mm/Kconfig                | 2 +-
 2 files changed, 1 insertion(+), 9 deletions(-)
arch/powerpc/mm/init_64.c +0 -8
index b6f3ae03ca9e..64f0df5bb5cd 100644
@@ -41,7 +41,6 @@
 #include <linux/libfdt.h>
 #include <linux/memremap.h>
 #include <linux/memory.h>
-#include <linux/bootmem_info.h>
 
 #include <asm/pgalloc.h>
 #include <asm/page.h>
@@ -388,13 +387,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
 
 #endif
 
-#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
-void register_page_bootmem_memmap(unsigned long section_nr,
-				  struct page *start_page, unsigned long size)
-{
-}
-#endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */
-
 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
 
 #ifdef CONFIG_PPC_BOOK3S_64
mm/Kconfig +1 -1
index e221fa1dc54d..97b079372325 100644
@@ -537,7 +537,7 @@ endchoice
 
 config MEMORY_HOTREMOVE
 	bool "Allow for memory hot remove"
-	select HAVE_BOOTMEM_INFO_NODE if (X86_64 || PPC64)
+	select HAVE_BOOTMEM_INFO_NODE if X86_64
 	depends on MEMORY_HOTPLUG
 	select MIGRATION
 
Signature · 2 lines
-- 
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
Reviewed-by on v1 1/8
#4 lore raw

Re: [PATCH 1/8] sparc/mm: remove register_page_bootmem_info()

In reply to David Hildenbrand (Arm)
Quoted 7 lines · David Hildenbrand (Arm)

sparc does not select CONFIG_HAVE_BOOTMEM_INFO_NODE, therefore, register_page_bootmem_info_node() is a nop.

Let's just get rid of register_page_bootmem_info().

---

Nice cleanup!

With CONFIG_NUMA=n, the removed helper did nothing.
With CONFIG_NUMA=y, it only looped over nodes and called the empty inline stub.

So, feel free to add:

Reviewed-by on v1 2/8
#8 lore raw

Re: [PATCH 2/8] mm/bootmem_info: drop initialization of page->lru

In reply to David Hildenbrand (Arm)
Quoted 17 lines · David Hildenbrand (Arm)

In the past, we used to store the type in page->lru.next, introduced by commit 5f24ce5fd34c ("thp: remove PG_buddy"). The location changed over the years; ever since commit 0386aaa6e9c8 ("bootmem: stop using page->index"), we store it alongside the info in page->private.

Consequently, there is no need to reset page->lru anymore.

---
mm/bootmem_info.c | 1 -

1 file changed, 1 deletion(-)
mm/bootmem_info.c +0 -0
index 3d7675a3ae04..a0a1ecdec8d0 100644

mm/bootmem_info.c void put_page_bootmem(struct page *page) · line 37

Quoted 4 lines
mm/bootmem_info.c +0 -1
@@ -34,7 +34,6 @@ void put_page_bootmem(struct page *page)
 	if (page_ref_dec_return(page) == 1) {
 		ClearPagePrivate(page);
 		set_page_private(page, 0);
-		INIT_LIST_HEAD(&page->lru);

Yep, that old INIT_LIST_HEAD() call was dead cleanup. page->lru and page->buddy_list are in the same union:

			union {
				struct list_head lru;

				/* Or, free page */
				struct list_head buddy_list;
			};

and free_reserved_page() passes the page to the buddy allocator. The later buddy list insertion will overwrite the values written by INIT_LIST_HEAD(&page->lru) anyway.

mm/bootmem_info.c void put_page_bootmem(struct page *page) · line 39

Quoted 3 lines
mm/bootmem_info.c +0 -0
 		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
 	}

LGTM, feel free to add:

Reviewed-by on v1 3/8
#12 lore raw

Re: [PATCH 3/8] mm/bootmem_info: stop using PG_private

In reply to David Hildenbrand (Arm)
Quoted 14 lines · David Hildenbrand (Arm)

Nobody checks PG_private for these pages, and we can happily use set_page_private() without setting PG_private. So let's just stop setting/clearing PG_private.

---
mm/bootmem_info.c | 2 --

1 file changed, 2 deletions(-)
mm/bootmem_info.c +0 -0
index a0a1ecdec8d0..6e2aaab3dca9 100644

mm/bootmem_info.c void get_page_bootmem(unsigned long info, struct page *page, · line 22

Quoted 4 lines
mm/bootmem_info.c +0 -1
@@ -19,7 +19,6 @@ void get_page_bootmem(unsigned long info, struct page *page,
 {
 	BUG_ON(type > 0xf);
 	BUG_ON(info > (ULONG_MAX >> 4));
-	SetPagePrivate(page);

Right, the users classify these pages via PageReserved()/bootmem_type(), not PagePrivate().

So makes sense to not set PG_private in the first place.

mm/bootmem_info.c void put_page_bootmem(struct page *page) · line 35

Quoted 8 lines
mm/bootmem_info.c +0 -1
 	set_page_private(page, info << 4 | type);
 	page_ref_inc(page);
 }
@@ -32,7 +31,6 @@ void put_page_bootmem(struct page *page)
 	       type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
 
 	if (page_ref_dec_return(page) == 1) {
-		ClearPagePrivate(page);

Nothing sets it anymore, so there is nothing to clear here.

LGTM, feel free to add:

Quoted 8 lines
mm/bootmem_info.c +0 -0
 		set_page_private(page, 0);
 		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
 		free_reserved_page(page);
Signature · 2 lines
-- 
2.43.0
Tested-by
#16 lore raw

Re: [PATCH 4/8] mm/bootmem_info: remove call to kmemleak_free_part_phys()

In reply to David Hildenbrand (Arm)
Quoted 1 line · David Hildenbrand (Arm)

On 5/12/26 10:34, Oscar Salvador wrote:

[...]

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
mm/bootmem_info.c +0 -0
index 6e2aaab3dca9..74c1116626c8 100644
@@ -32,7 +32,6 @@ void put_page_bootmem(struct page *page)
 
Quoted 6 lines

mm/bootmem_info.c void put_page_bootmem(struct page *page) · line 35

Quoted 3 lines
mm/bootmem_info.c +0 -1
 	if (page_ref_dec_return(page) == 1) {
 		set_page_private(page, 0);
-		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);

A bit odd that kmemleak_free_part_phys() did not complain if we never did kmemleak_alloc_phys() for these pages?

Quoted 4 lines

delete_object_part() calls __find_and_remove_object() and essentially just skips if it didn't find anything.

Maybe the kmemleak_warn() would trigger, but it's guarded by "#ifdef DEBUG" ...

Right! With kmemleak DEBUG enabled, kmemleak_free_part_phys() does warns whenever delete_object_part() cannot find the corresponding physical object ...

Before this patch, booting with:

"kmemleak=on hugetlb_free_vmemmap=on default_hugepagesz=2M hugepagesz=2M hugepages=512"

I got a lot of warnings, something like:

[   44.481883] kmemleak: Partially freeing unknown object at 0x2acc59000 (size 4096)
[   44.482754] CPU: 2 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.1.0-rc3 #206 PREEMPT(full)
[   44.482758] Hardware name: Red Hat KVM, BIOS 1.11.0-2.el7 04/01/2014
[   44.482760] Call Trace:
[   44.482762]  <TASK>
[   44.482764]  dump_stack_lvl+0x60/0x90
[   44.482769]  dump_stack+0x14/0x1a
[   44.482774]  delete_object_part.cold+0x28/0x2d
[   44.482779]  kmemleak_free_part_phys+0x67/0x80
[   44.482783]  put_page_bootmem+0xc0/0x100
[   44.482787]  free_vmemmap_page_list+0x13e/0x230
[   44.482791]  __hugetlb_vmemmap_optimize_folios+0x351/0x430

[...]

So, yeah, looks like these calls are trying to free physical kmemleak objects that are no longer tracked after memmap_alloc() started using MEMBLOCK_ALLOC_NOLEAKTRACE :)

With this patch applied, those stale calls are gone, and so are the warnings :P

Reviewed-by on v1 5/8
#23 lore raw

Re: [PATCH 5/8] mm/bootmem_info: stop marking the pgdat as NODE_INFO

In reply to David Hildenbrand (Arm)
Quoted 29 lines · David Hildenbrand (Arm)

We removed the last user of NODE_INFO in commit 119c31caa59e ("mm/sparse:
remove !CONFIG_SPARSEMEM_VMEMMAP leftovers for CONFIG_MEMORY_HOTPLUG").

But it really was never used it besides for safety-checks ever since it was introduced in commit 04753278769f ("memory hotplug: register section/node id to free"), where we had the comment:

5) The node information like pgdat has similar issues. But, this will be able to be solved too by this.
(Not implemented yet, but, remembering node id in the pages.)

Of course, that never happened, and we are not planning on freeing the node data (pgdat/pglist_data), during memory hotunplug.

So let's just stop marking the pgdat as NODE_INFO.

---
mm/bootmem_info.c | 9 +--------

1 file changed, 1 insertion(+), 8 deletions(-)
mm/bootmem_info.c +0 -0
index 74c1116626c8..cce1d560f094 100644
@@ -62,15 +62,8 @@ static void __init register_page_bootmem_info_section(unsigned long start_pfn)
 
 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
 {

mm/bootmem_info.c static void __init register_page_bootmem_info_section(unsigned long start_pfn) · line 73

Quoted 10 lines
mm/bootmem_info.c +1 -8
-	unsigned long i, pfn, end_pfn, nr_pages;
+	unsigned long pfn, end_pfn;
 	int node = pgdat->node_id;
-	struct page *page;
-
-	nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
-	page = virt_to_page(pgdat);
-
-	for (i = 0; i < nr_pages; i++, page++)
-		get_page_bootmem(node, page, NODE_INFO);

Cool. IIUC, pgdat isn't freed during memory hotremove. Offline nodes stick around and can get reinitialized on hotadd, so NODE_INFO doesn't buy us anything here :D

LGTM, feel free to add:

Reviewed-by on v1 6/8
#27 lore raw

Re: [PATCH 6/8] mm/bootmem_info: stop marking mem_section_usage as MIX_SECTION_INFO

In reply to David Hildenbrand (Arm)
Quoted 3 lines · David Hildenbrand (Arm)

We never free the ms->usage data for boot memory sections (see section_deactivate()). And to identify whether ms->usage was allocated from memblock, we simply identify it by looking at PG_reserved.

Yep, PageReserved() is already enough to tell that case apart :)

Quoted 2 lines

Consequently, there is no need to mark ms->usage as MIX_SECTION_INFO. Let's just stop doing that.

Right, MIX_SECTION_INFO doesn't add much here. For ms->usage, removal code doesn't use MIX_SECTION_INFO at all :)

Quoted 2 lines

---

LGTM, feel free to add:

Reviewed-by on v1 7/8
#35 lore raw

Re: [PATCH 7/8] s390/mm: use free_reserved_page() in vmem_free_pages()

In reply to David Hildenbrand (Arm)
Quoted 2 lines · David Hildenbrand (Arm)

We never select CONFIG_HAVE_BOOTMEM_INFO_NODE on s390. Therefore, free_bootmem_page() nowadays always translates to free_reserved_page().

Yeah. After patch #04 there is no kmemleak handling left in free_bootmem_page(), and on s390 it is just a wrapper around free_reserved_page() :)

Quoted 8 lines

Let's use free_reserved_page() to replace the free_bootmem_page() loop. We can stop including bootmem_info.h.

Likely, vmemmap freeing code could be factored out into the core in the future.

---

Nice cleanup, feel free to add:

Reviewed-by on v1 8/8
#40 lore raw

Re: [PATCH 8/8] powerpc/mm: remove CONFIG_HAVE_BOOTMEM_INFO_NODE

In reply to David Hildenbrand (Arm)
Quoted 9 lines · David Hildenbrand (Arm)

register_page_bootmem_info_node() essentially only calls register_page_bootmem_memmap(). However, on powerpc that function is a nop. So there is not benefit in using CONFIG_HAVE_BOOTMEM_INFO_NODE anymore, let's just drop it.

We can stop including bootmem_info.h.

---

Nice cleanup! Feel free to add: