Skip to contentSkip to conversation

mm: split a couple of headers from internal.h

PATCH Superseded Mike Rapoport (Microsoft) 4 participants 9 messages Jul 9 – Jul 13

Subsystems (13)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Mike Rapoport (Microsoft)

author maintainer
#0 lore raw

cover mm: split a couple of headers from internal.h

mm/internal.h becomes more and more bloated.

Split declarations related to mm_init, memblock, vmalloc and sparse into new headers.

---
Mike Rapoport (Microsoft) (3):
mm: split out mm_init and memblock declarations from internal.h
mm: split out sparse declarations from internal.h
mm: split out vmalloc declarations from internal.h

 MAINTAINERS                        |   3 +
 kernel/liveupdate/kexec_handover.c |   3 +-
 mm/cma.c                           |   1 +
 mm/execmem.c                       |   1 +
 mm/hugetlb.c                       |   1 +
 mm/internal.h                      | 183 -------------------------------------
 mm/kmsan/hooks.c                   |   1 +
 mm/kmsan/shadow.c                  |   1 +
 mm/memblock.c                      |   1 +
 mm/memory_hotplug.c                |   1 +
 mm/mm_init.c                       |   3 +
 mm/mm_init.h                       | 120 ++++++++++++++++++++++++
 mm/page_alloc.c                    |   1 +
 mm/percpu-vm.c                     |   1 +
 mm/sparse-vmemmap.c                |   2 +
 mm/sparse.c                        |   2 +
 mm/sparse.h                        |  63 +++++++++++++
 mm/vmalloc.c                       |   1 +
 mm/vmalloc.h                       |  46 ++++++++++
 19 files changed, 251 insertions(+), 184 deletions(-)

---
base-commit: 820d5dfede0cd55dcbc89ce96fcfbb11b7c457ba
change-id: 20260707-internal-h-2efef660381d

--
Sincerely yours,
Mike.

author maintainer
#1 lore raw

PATCH 1/3 mm: split out mm_init and memblock declarations from internal.h

mm/internal.h becomes more and more bloated.

Move declarations for related to mm/mm_init.c and mm/memblock.c to a new mm/mm_init.h header.

No functional changes.

---
 MAINTAINERS                        |   1 +
 kernel/liveupdate/kexec_handover.c |   1 +
 mm/cma.c                           |   1 +
 mm/hugetlb.c                       |   1 +
 mm/internal.h                      |  91 ----------------------------
 mm/memblock.c                      |   1 +
 mm/memory_hotplug.c                |   1 +
 mm/mm_init.c                       |   1 +
 mm/mm_init.h                       | 120 +++++++++++++++++++++++++++++++++++++
 mm/page_alloc.c                    |   1 +
 mm/sparse-vmemmap.c                |   1 +
 11 files changed, 129 insertions(+), 91 deletions(-)
MAINTAINERS +1 -0
index 661ac43204d2..537dbfd01362 100644
@@ -16882,6 +16882,7 @@ F:	mm/bootmem_info.c
 F:	mm/memblock.c
 F:	mm/memtest.c
 F:	mm/mm_init.c
+F:	mm/mm_init.h
 F:	mm/rodata_test.c
 F:	tools/testing/memblock/
 
kernel/liveupdate/kexec_handover.c +1 -0
index 4834a809985a..fe11cbf1006e 100644
@@ -35,6 +35,7 @@
  * internal APIs.
  */
 #include "../../mm/internal.h"
+#include "../../mm/mm_init.h"
 #include "../kexec_internal.h"
 #include "kexec_handover_internal.h"
 
mm/cma.c +1 -0
index 31073738f2ac..a7929c758df1 100644
@@ -33,6 +33,7 @@
 
 #include "internal.h"
 #include "cma.h"
+#include "mm_init.h"
 
 struct cma cma_areas[MAX_CMA_AREAS];
 unsigned int cma_area_count;
mm/hugetlb.c +1 -0
index c211da6f0911..83d32d59aeab 100644
@@ -51,6 +51,7 @@
 #include "hugetlb_vmemmap.h"
 #include "hugetlb_cma.h"
 #include "hugetlb_internal.h"
+#include "mm_init.h"
 #include <linux/page-isolation.h>
 
 int hugetlb_max_hstate __read_mostly;
mm/internal.h +0 -91

148 lines not on this page · raw message

mm/memblock.c +1 -0
index 6349c48154f4..777c69f05400 100644
@@ -29,6 +29,7 @@
 #include <linux/io.h>
 
 #include "internal.h"
+#include "mm_init.h"
 
 #define INIT_MEMBLOCK_REGIONS			128
 #define INIT_PHYSMEM_REGIONS			4
mm/memory_hotplug.c +1 -0
index 11ab2f7bc7f3..99090f49d2df 100644
@@ -40,6 +40,7 @@
 #include <asm/tlbflush.h>
 
 #include "internal.h"
+#include "mm_init.h"
 #include "page_alloc.h"
 #include "shuffle.h"
 
mm/mm_init.c +1 -0
index 537664974ab1..39583c028e34 100644
@@ -33,6 +33,7 @@
 #include <linux/kexec_handover.h>
 #include <linux/hugetlb.h>
 #include "internal.h"
+#include "mm_init.h"
 #include "page_alloc.h"
 #include "slab.h"
 #include "shuffle.h"
mm/mm_init.h new file +120 -0

120 lines not on this page · raw message

mm/page_alloc.c +1 -0
index a63733dac659..ecb411fcaf81 100644
@@ -56,6 +56,7 @@
 #include <linux/pgalloc_tag.h>
 #include <asm/div64.h>
 #include "internal.h"
+#include "mm_init.h"
 #include "page_alloc.h"
 #include "shuffle.h"
 #include "page_reporting.h"
mm/sparse-vmemmap.c +1 -0
index 515a404b66c0..10dd4a9b591b 100644
@@ -41,6 +41,7 @@
 #define VMEMMAP_POPULATE_PAGEREF	0x0001
 
 #include "internal.h"
+#include "mm_init.h"
 
 /*
  * Allocate a block of memory to be used to back the virtual memory map
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/3] mm: split out mm_init and memblock declarations from internal.h

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Missing semicolon at the end of the `memmap_init_range()` function declaration in the new…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Missing semicolon at the end of the memmap_init_range() function declaration in the new mm/mm_init.h header file.
- [Low] mm/sparse.c fails to compile because it lacks #include "mm_init.h", resulting in undeclared identifiers and potential implicit declarations. --

--- Patch [1]: [PATCH 1/3] mm: split out mm_init and memblock declarations from internal.h --- commit 13783d4d0cf38a0ede9798e1d71f8e2fb2de5d3d
Author: Mike Rapoport (Microsoft) <[email protected]>

mm: split out mm_init and memblock declarations from internal.h

This commit moves declarations related to mm/mm_init.c and mm/memblock.c from mm/internal.h to a new mm/mm_init.h header file to reduce bloat.

Quoted 4 lines
mm/internal.h +0 -0
index 5c94d1bd7b930..c514b17c61b87 100644

[ ... ]

mm/internal.h static inline void init_compound_tail(struct page *tail, · line 830

Quoted 12 lines
mm/internal.h +0 -8
@@ -820,14 +807,6 @@ static inline void init_compound_tail(struct page *tail,
 	prep_compound_tail(tail, head, order);
 }
 
-extern void *memmap_alloc(phys_addr_t size, phys_addr_t align,
-			  phys_addr_t min_addr,
-			  int nid, bool exact_nid);
-
-void memmap_init_range(unsigned long, int, unsigned long, unsigned long,
-		unsigned long, enum meminit_context, struct vmem_altmap *, int,
-		bool);
-

[Severity: Low]
Since these declarations are moved to mm/mm_init.h, will mm/sparse.c fail to compile? It appears __populate_section_memmap() relies on memmap_alloc(), and mminit_validate_memmodel_limits() relies on mminit_dprintk(), but the patch doesn't add an include for mm_init.h in mm/sparse.c.

Quoted 3 lines
mm/internal.h +0 -0
 /*
  * mm/sparse.c
  */

[ ... ]

Quoted 5 lines
mm/mm_init.h new file +0 -0
new file mode 100644
index 0000000000000..118f88c523c95

[ ... ]

mm/mm_init.h line 41

Quoted 8 lines
mm/mm_init.h new file +8 -0
+void *memmap_alloc(phys_addr_t size, phys_addr_t align, phys_addr_t min_addr,
+		int nid, bool exact_nid);
+
+void memmap_init_range(unsigned long size, int nid, unsigned long zone,
+		unsigned long start_pfn, unsigned long zone_end_pfn,
+		enum meminit_context context,
+		struct vmem_altmap *altmap, int migratetype,
+		bool isolate_pageblock)

[Severity: Low]
Does this declaration cause a syntax error because it is missing a semicolon at the end?

Quoted 5 lines
mm/mm_init.h new file +5 -0
+
+#if defined CONFIG_COMPACTION || defined CONFIG_CMA
+/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
+void init_cma_reserved_pageblock(struct page *page);
+#endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

Re: [PATCH 1/3] mm: split out mm_init and memblock declarations from internal.h

Quoted 9 lines · On Thu, Jul 09, 2026 at 06:57:12AM +0000, [email protected] wrote:

mm/mm_init.h line 41

Quoted 5 lines
mm/mm_init.h new file +5 -0
+void memmap_init_range(unsigned long size, int nid, unsigned long zone,
+		unsigned long start_pfn, unsigned long zone_end_pfn,
+		enum meminit_context context,
+		struct vmem_altmap *altmap, int migratetype,
+		bool isolate_pageblock)

[Severity: Low]
Does this declaration cause a syntax error because it is missing a semicolon at the end?

Fixing checkpatch warning didn't go well :)

Will send v2 later.

Quoted 7 lines
Quoted 4 lines
mm/mm_init.h new file +4 -0
+#if defined CONFIG_COMPACTION || defined CONFIG_CMA
+/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
+void init_cma_reserved_pageblock(struct page *page);
+#endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Signature · 2 lines
Sincerely yours,
Mike.
author maintainer
#4 lore raw

PATCH 2/3 mm: split out sparse declarations from internal.h

In reply to Mike Rapoport (Microsoft)

mm/internal.h becomes more and more bloated.

Move declarations related to SPARSE and SPARSE_VMEMMAP memory models to a new mm/sparse.h header.

No functional changes.

---
 MAINTAINERS         |  1 +
 mm/internal.h       | 52 -------------------------------------------
 mm/mm_init.c        |  1 +
 mm/sparse-vmemmap.c |  1 +
 mm/sparse.c         |  2 ++
 mm/sparse.h         | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 68 insertions(+), 52 deletions(-)
MAINTAINERS +1 -0
index 537dbfd01362..406ccfe63974 100644
@@ -16999,6 +16999,7 @@ F:	mm/pgtable-generic.c
 F:	mm/ptdump.c
 F:	mm/sparse-vmemmap.c
 F:	mm/sparse.c
+F:	mm/sparse.h
 F:	mm/util.c
 F:	mm/vmpressure.c
 F:	mm/vmstat.c
mm/internal.h +0 -52

58 lines not on this page · raw message

mm/mm_init.c +1 -0
index 39583c028e34..b557e5fe35f3 100644
@@ -35,6 +35,7 @@
 #include "internal.h"
 #include "mm_init.h"
 #include "page_alloc.h"
+#include "sparse.h"
 #include "slab.h"
 #include "shuffle.h"
 
mm/sparse-vmemmap.c +1 -0
index 10dd4a9b591b..458b0b9570ff 100644
@@ -42,6 +42,7 @@
 
 #include "internal.h"
 #include "mm_init.h"
+#include "sparse.h"
 
 /*
  * Allocate a block of memory to be used to back the virtual memory map
mm/sparse.c +2 -0
index 058ef9300367..4b21dd8c7dfb 100644
@@ -16,6 +16,8 @@
 #include <linux/bootmem_info.h>
 #include <linux/vmstat.h>
 #include "internal.h"
+#include "mm_init.h"
+#include "sparse.h"
 #include <asm/dma.h>
 
 /*
mm/sparse.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.53.0
author maintainer
#5 lore raw

PATCH 3/3 mm: split out vmalloc declarations from internal.h

In reply to Mike Rapoport (Microsoft)

mm/internal.h becomes more and more bloated.

Move declarations related to vmalloc to a new mm/vmalloc.h header.

No functional changes.

---
 MAINTAINERS                        |  1 +
 kernel/liveupdate/kexec_handover.c |  2 +-
 mm/execmem.c                       |  1 +
 mm/internal.h                      | 40 ---------------------------------
 mm/kmsan/hooks.c                   |  1 +
 mm/kmsan/shadow.c                  |  1 +
 mm/mm_init.c                       |  1 +
 mm/percpu-vm.c                     |  1 +
 mm/vmalloc.c                       |  1 +
 mm/vmalloc.h                       | 46 ++++++++++++++++++++++++++++++++++++++
 10 files changed, 54 insertions(+), 41 deletions(-)
MAINTAINERS +1 -0
index 406ccfe63974..804e3b0f3d97 100644
@@ -28813,6 +28813,7 @@ W:	http://www.linux-mm.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
 F:	include/linux/vmalloc.h
 F:	mm/vmalloc.c
+F:	mm/vmalloc.h
 F:	lib/test_vmalloc.c
 
 VME SUBSYSTEM
kernel/liveupdate/kexec_handover.c +1 -1
index fe11cbf1006e..78ff267bf51e 100644
@@ -34,8 +34,8 @@
  * KHO is tightly coupled with mm init and needs access to some of mm
  * internal APIs.
  */
-#include "../../mm/internal.h"
 #include "../../mm/mm_init.h"
+#include "../../mm/vmalloc.h"
 #include "../kexec_internal.h"
 #include "kexec_handover_internal.h"
 
mm/execmem.c +1 -0
index 084a207e4278..74a178a87e75 100644
@@ -20,6 +20,7 @@
 #include <asm/tlbflush.h>
 
 #include "internal.h"
+#include "vmalloc.h"
 
 static struct execmem_info *execmem_info __ro_after_init;
 static struct execmem_info default_execmem_info __ro_after_init;
mm/internal.h +0 -40
index 860cd31c3da5..8a2bf9bc93ab 100644
@@ -1092,9 +1092,6 @@ static inline void mlock_new_folio(struct folio *folio) { }
 static inline bool need_mlock_drain(int cpu) { return false; }
 static inline void mlock_drain_local(void) { }
 static inline void mlock_drain_remote(int cpu) { }
-static inline void vunmap_range_noflush(unsigned long start, unsigned long end)
-{
-}
 #endif /* !CONFIG_MMU */
 
 #define NODE_RECLAIM_NOSCAN	-2
@@ -1209,37 +1206,6 @@ struct migration_target_control {
 size_t splice_folio_into_pipe(struct pipe_inode_info *pipe,
 			      struct folio *folio, loff_t fpos, size_t size);
 
-/*
- * mm/vmalloc.c
- */
-#ifdef CONFIG_MMU
-void __init vmalloc_init(void);
-int __must_check vmap_pages_range_noflush(unsigned long addr, unsigned long end,
-	pgprot_t prot, struct page **pages, unsigned int page_shift, gfp_t gfp_mask);
-unsigned int get_vm_area_page_order(struct vm_struct *vm);
-#else
-static inline void vmalloc_init(void)
-{
-}
-
-static inline
-int __must_check vmap_pages_range_noflush(unsigned long addr, unsigned long end,
-	pgprot_t prot, struct page **pages, unsigned int page_shift, gfp_t gfp_mask)
-{
-	return -EINVAL;
-}
-#endif
-
-void clear_vm_uninitialized_flag(struct vm_struct *vm);
-
-int __must_check __vmap_pages_range_noflush(unsigned long addr,
-			       unsigned long end, pgprot_t prot,
-			       struct page **pages, unsigned int page_shift);
-
-void vunmap_range_noflush(unsigned long start, unsigned long end);
-
-void __vunmap_range_noflush(unsigned long start, unsigned long end);
-
 static inline bool vma_is_single_threaded_private(struct vm_area_struct *vma)
 {
 	if (vma->vm_flags & VM_SHARED)
@@ -1267,12 +1233,6 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,
 void free_zone_device_folio(struct folio *folio);
 int migrate_device_coherent_folio(struct folio *folio);
 
-struct vm_struct *__get_vm_area_node(unsigned long size,
-				     unsigned long align, unsigned long shift,
-				     unsigned long vm_flags, unsigned long start,
-				     unsigned long end, int node, gfp_t gfp_mask,
-				     const void *caller);
-
 /*
  * mm/gup.c
  */
mm/kmsan/hooks.c +1 -0
index 8f22d1f22981..5f1b8053f9fa 100644
@@ -21,6 +21,7 @@
 #include <linux/usb.h>
 
 #include "../internal.h"
+#include "../vmalloc.h"
 #include "../slab.h"
 #include "kmsan.h"
 
mm/kmsan/shadow.c +1 -0
index 8fde939784a7..0c88d89bf0d6 100644
@@ -17,6 +17,7 @@
 #include <linux/stddef.h>
 
 #include "../internal.h"
+#include "../vmalloc.h"
 #include "kmsan.h"
 
 #define shadow_page_for(page) ((page)->kmsan_shadow)
mm/mm_init.c +1 -0
index b557e5fe35f3..711f821f7b3c 100644
@@ -38,6 +38,7 @@
 #include "sparse.h"
 #include "slab.h"
 #include "shuffle.h"
+#include "vmalloc.h"
 
 #include <asm/setup.h>
 
mm/percpu-vm.c +1 -0
index 7ed216192fc0..509d8901835c 100644
@@ -9,6 +9,7 @@
  * This is the default chunk allocator.
  */
 #include "internal.h"
+#include "vmalloc.h"
 
 static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk,
 				    unsigned int cpu, int page_idx)
mm/vmalloc.c +1 -0
index 1191cda3b4e8..4b0362cbdf5a 100644
@@ -49,6 +49,7 @@
 
 #include "internal.h"
 #include "pgalloc-track.h"
+#include "vmalloc.h"
 
 #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
 static unsigned int __ro_after_init ioremap_max_page_shift = BITS_PER_LONG - 1;
mm/vmalloc.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.53.0
author maintainer
#6 lore raw
In reply to Mike Rapoport (Microsoft)
Quoted 4 lines · Mike Rapoport (Microsoft)

mm/internal.h becomes more and more bloated.

Split declarations related to mm_init, memblock, vmalloc and sparse into new headers.

Sashiko rightfully pointed to some issues, will send v2 later.

Quoted 34 lines

---
Mike Rapoport (Microsoft) (3):
mm: split out mm_init and memblock declarations from internal.h
mm: split out sparse declarations from internal.h
mm: split out vmalloc declarations from internal.h

 MAINTAINERS                        |   3 +
 kernel/liveupdate/kexec_handover.c |   3 +-
 mm/cma.c                           |   1 +
 mm/execmem.c                       |   1 +
 mm/hugetlb.c                       |   1 +
 mm/internal.h                      | 183 -------------------------------------
 mm/kmsan/hooks.c                   |   1 +
 mm/kmsan/shadow.c                  |   1 +
 mm/memblock.c                      |   1 +
 mm/memory_hotplug.c                |   1 +
 mm/mm_init.c                       |   3 +
 mm/mm_init.h                       | 120 ++++++++++++++++++++++++
 mm/page_alloc.c                    |   1 +
 mm/percpu-vm.c                     |   1 +
 mm/sparse-vmemmap.c                |   2 +
 mm/sparse.c                        |   2 +
 mm/sparse.h                        |  63 +++++++++++++
 mm/vmalloc.c                       |   1 +
 mm/vmalloc.h                       |  46 ++++++++++
 19 files changed, 251 insertions(+), 184 deletions(-)

---
base-commit: 820d5dfede0cd55dcbc89ce96fcfbb11b7c457ba
change-id: 20260707-internal-h-2efef660381d

--
Sincerely yours,
Mike.

Signature · 2 lines
Sincerely yours,
Mike.
maintainer Acked-by
#7 lore raw
Quoted 11 lines · Mike Rapoport
Quoted 4 lines · Mike Rapoport (Microsoft)

mm/internal.h becomes more and more bloated.

Split declarations related to mm_init, memblock, vmalloc and sparse into new headers.

Sashiko rightfully pointed to some issues, will send v2 later.

Hi Mike,

I recall that this work was mentioned during the last review in my series. However, I didn't have time to address it then because I was still working on the HVO refactoring. I really appreciate you taking this on. Thanks for your work.

I've reviewed Sashiko's comments as well, and it doesn't look like there are any major issues. Therefore, feel free to add my ack for this whole series in your v2 version with the proper fix.

Muchun,
Thanks

Quoted 39 lines
Quoted 35 lines

---
Mike Rapoport (Microsoft) (3):
mm: split out mm_init and memblock declarations from internal.h
mm: split out sparse declarations from internal.h
mm: split out vmalloc declarations from internal.h

MAINTAINERS                        |   3 +
kernel/liveupdate/kexec_handover.c |   3 +-
mm/cma.c                           |   1 +
mm/execmem.c                       |   1 +
mm/hugetlb.c                       |   1 +
mm/internal.h                      | 183 -------------------------------------
mm/kmsan/hooks.c                   |   1 +
mm/kmsan/shadow.c                  |   1 +
mm/memblock.c                      |   1 +
mm/memory_hotplug.c                |   1 +
mm/mm_init.c                       |   3 +
mm/mm_init.h                       | 120 ++++++++++++++++++++++++
mm/page_alloc.c                    |   1 +
mm/percpu-vm.c                     |   1 +
mm/sparse-vmemmap.c                |   2 +
mm/sparse.c                        |   2 +
mm/sparse.h                        |  63 +++++++++++++
mm/vmalloc.c                       |   1 +
mm/vmalloc.h                       |  46 ++++++++++
19 files changed, 251 insertions(+), 184 deletions(-)

---
base-commit: 820d5dfede0cd55dcbc89ce96fcfbb11b7c457ba
change-id: 20260707-internal-h-2efef660381d

--
Sincerely yours,
Mike.

Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#8 lore raw
In reply to Mike Rapoport (Microsoft)
Quoted 22 lines · Mike Rapoport (Microsoft)

mm/internal.h becomes more and more bloated.

Split declarations related to mm_init, memblock, vmalloc and sparse into new headers.

---
Mike Rapoport (Microsoft) (3):
mm: split out mm_init and memblock declarations from internal.h
mm: split out sparse declarations from internal.h
mm: split out vmalloc declarations from internal.h

 MAINTAINERS                        |   3 +
 kernel/liveupdate/kexec_handover.c |   3 +-
 mm/cma.c                           |   1 +
 mm/execmem.c                       |   1 +
 mm/hugetlb.c                       |   1 +
 mm/internal.h                      | 183 -------------------------------------
 mm/kmsan/hooks.c                   |   1 +
 mm/kmsan/shadow.c                  |   1 +
 mm/memblock.c                      |   1 +
 mm/memory_hotplug.c                |   1 +
 mm/mm_init.c                       |   3 +
Quoted 9 lines
 mm/mm_init.h                       | 120 ++++++++++++++++++++++++
 mm/page_alloc.c                    |   1 +
 mm/percpu-vm.c                     |   1 +
 mm/sparse-vmemmap.c                |   2 +
 mm/sparse.c                        |   2 +
 mm/sparse.h                        |  63 +++++++++++++
 mm/vmalloc.c                       |   1 +
 mm/vmalloc.h                       |  46 ++++++++++

Thank you for splitting vmalloc. Later on we/i can move other things from main vmalloc.h into this local variant.

--
Uladzislau Rezki