Skip to content

Commit d49004c

Browse files
rpptakpm00
authored andcommitted
arch, mm: consolidate initialization of nodes, zones and memory map
To initialize node, zone and memory map data structures every architecture calls free_area_init() during setup_arch() and passes it an array of zone limits. Beside code duplication it creates "interesting" ordering cases between allocation and initialization of hugetlb and the memory map. Some architectures allocate hugetlb pages very early in setup_arch() in certain cases, some only create hugetlb CMA areas in setup_arch() and sometimes hugetlb allocations happen mm_core_init(). With arch_zone_limits_init() helper available now on all architectures it is no longer necessary to call free_area_init() from architecture setup code. Rather core MM initialization can call arch_zone_limits_init() in a single place. This allows to unify ordering of hugetlb vs memory map allocation and initialization. Remove the call to free_area_init() from architecture specific code and place it in a new mm_core_init_early() function that is called immediately after setup_arch(). After this refactoring it is possible to consolidate hugetlb allocations and eliminate differences in ordering of hugetlb and memory map initialization among different architectures. As the first step of this consolidation move hugetlb_bootmem_alloc() to mm_core_early_init(). Link: https://lkml.kernel.org/r/20260111082105.290734-24-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alex Shi <alexs@kernel.org> Cc: Andreas Larsson <andreas@gaisler.com> Cc: "Borislav Petkov (AMD)" <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David Hildenbrand <david@kernel.org> Cc: David S. Miller <davem@davemloft.net> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Guo Ren <guoren@kernel.org> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Helge Deller <deller@gmx.de> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Klara Modin <klarasmodin@gmail.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Magnus Lindholm <linmag7@gmail.com> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Hocko <mhocko@suse.com> Cc: Michal Simek <monstr@monstr.eu> Cc: Muchun Song <muchun.song@linux.dev> Cc: Oscar Salvador <osalvador@suse.de> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Richard Weinberger <richard@nod.at> Cc: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Stafford Horne <shorne@gmail.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 2d3c8c5 commit d49004c

35 files changed

Lines changed: 15 additions & 200 deletions

File tree

arch/alpha/mm/init.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,10 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfn)
220220
}
221221

222222
/*
223-
* paging_init() sets up the memory map.
223+
* paging_init() initializes the kernel's ZERO_PGE.
224224
*/
225225
void __init paging_init(void)
226226
{
227-
unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
228-
229-
/* Initialize mem_map[]. */
230-
arch_zone_limits_init(max_zone_pfn);
231-
free_area_init(max_zone_pfn);
232-
233-
/* Initialize the kernel's ZERO_PGE. */
234227
memset(absolute_pointer(ZERO_PGE), 0, PAGE_SIZE);
235228
}
236229

arch/arc/mm/init.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfn)
102102
*/
103103
void __init setup_arch_memory(void)
104104
{
105-
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
106-
107105
setup_initial_init_mm(_text, _etext, _edata, _end);
108106

109107
/* first page of system - kernel .vector starts here */
@@ -158,9 +156,6 @@ void __init setup_arch_memory(void)
158156
arch_pfn_offset = min(min_low_pfn, min_high_pfn);
159157
kmap_init();
160158
#endif /* CONFIG_HIGHMEM */
161-
162-
arch_zone_limits_init(max_zone_pfn);
163-
free_area_init(max_zone_pfn);
164159
}
165160

166161
void __init arch_mm_preinit(void)

arch/arm/mm/init.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfn)
118118
#endif
119119
}
120120

121-
static void __init zone_sizes_init(unsigned long min, unsigned long max_low,
122-
unsigned long max_high)
123-
{
124-
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
125-
126-
arch_zone_limits_init(max_zone_pfn);
127-
free_area_init(max_zone_pfn);
128-
}
129-
130121
#ifdef CONFIG_HAVE_ARCH_PFN_VALID
131122
int pfn_valid(unsigned long pfn)
132123
{
@@ -222,13 +213,6 @@ void __init bootmem_init(void)
222213
* done after the fixed reservations
223214
*/
224215
sparse_init();
225-
226-
/*
227-
* Now free the memory - free_area_init needs
228-
* the sparse mem_map arrays initialized by sparse_init()
229-
* for memmap_init_zone(), otherwise all PFNs are invalid.
230-
*/
231-
zone_sizes_init(min_low_pfn, max_low_pfn, max_pfn);
232216
}
233217

234218
/*

arch/arm64/mm/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)
134134

135135
static void __init dma_limits_init(void)
136136
{
137-
unsigned long max_zone_pfns[MAX_NR_ZONES] = {0};
138137
phys_addr_t __maybe_unused acpi_zone_dma_limit;
139138
phys_addr_t __maybe_unused dt_zone_dma_limit;
140139
phys_addr_t __maybe_unused dma32_phys_limit =
@@ -160,9 +159,6 @@ static void __init dma_limits_init(void)
160159
#endif
161160
if (!arm64_dma_phys_limit)
162161
arm64_dma_phys_limit = PHYS_MASK + 1;
163-
164-
arch_zone_limits_init(max_zone_pfns);
165-
free_area_init(max_zone_pfns);
166162
}
167163

168164
int pfn_is_map_memory(unsigned long pfn)

arch/csky/kernel/setup.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ static void __init csky_memblock_init(void)
6363
{
6464
unsigned long lowmem_size = PFN_DOWN(LOWMEM_LIMIT - PHYS_OFFSET_OFFSET);
6565
unsigned long sseg_size = PFN_DOWN(SSEG_SIZE - PHYS_OFFSET_OFFSET);
66-
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
6766
signed long size;
6867

6968
memblock_reserve(__pa(_start), _end - _start);
@@ -101,9 +100,6 @@ static void __init csky_memblock_init(void)
101100
memblock_set_current_limit(PFN_PHYS(max_low_pfn));
102101

103102
dma_contiguous_reserve(0);
104-
105-
arch_zone_limits_init(max_zone_pfn);
106-
free_area_init(max_zone_pfn);
107103
}
108104

109105
void __init setup_arch(char **cmdline_p)

arch/hexagon/mm/init.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,8 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)
6666
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
6767
}
6868

69-
/*
70-
* In order to set up page allocator "nodes",
71-
* somebody has to call free_area_init() for UMA.
72-
*
73-
* In this mode, we only have one pg_data_t
74-
* structure: contig_mem_data.
75-
*/
7669
static void __init paging_init(void)
7770
{
78-
unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
79-
80-
arch_zone_limits_init(max_zone_pfn);
81-
free_area_init(max_zone_pfn); /* sets up the zonelists and mem_map */
82-
8371
/*
8472
* Set the init_mm descriptors "context" value to point to the
8573
* initial kernel segment table's physical address.

arch/loongarch/include/asm/pgtable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
353353
return pte;
354354
}
355355

356-
extern void paging_init(void);
357-
358356
#define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
359357
#define pte_present(pte) (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
360358
#define pte_no_exec(pte) (pte_val(pte) & _PAGE_NO_EXEC)

arch/loongarch/kernel/setup.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,6 @@ void __init setup_arch(char **cmdline_p)
621621
prefill_possible_map();
622622
#endif
623623

624-
paging_init();
625-
626624
#ifdef CONFIG_KASAN
627625
kasan_init();
628626
#endif

arch/loongarch/mm/init.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)
6868
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
6969
}
7070

71-
void __init paging_init(void)
72-
{
73-
unsigned long max_zone_pfns[MAX_NR_ZONES];
74-
75-
arch_zone_limits_init(max_zone_pfns);
76-
free_area_init(max_zone_pfns);
77-
}
78-
7971
void __ref free_initmem(void)
8072
{
8173
free_initmem_default(POISON_FREE_INITMEM);

arch/m68k/mm/init.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ void __init paging_init(void)
6969
* page_alloc get different views of the world.
7070
*/
7171
unsigned long end_mem = memory_end & PAGE_MASK;
72-
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, };
7372

7473
high_memory = (void *) end_mem;
7574

7675
empty_zero_page = memblock_alloc_or_panic(PAGE_SIZE, PAGE_SIZE);
77-
arch_zone_limits_init(max_zone_pfn);
78-
free_area_init(max_zone_pfn);
7976
}
8077

8178
#endif /* CONFIG_MMU */

0 commit comments

Comments
 (0)