]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
arch, mm: make releasing of memory to page allocator more explicit
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Thu, 13 Mar 2025 13:50:03 +0000 (15:50 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 18 Mar 2025 05:06:53 +0000 (22:06 -0700)
The point where the memory is released from memblock to the buddy
allocator is hidden inside arch-specific mem_init()s and the call to
memblock_free_all() is needlessly duplicated in every artiste cure and
after introduction of arch_mm_preinit() hook, mem_init() implementation on
many architecture only contains the call to memblock_free_all().

Pull memblock_free_all() call into mm_core_init() and drop mem_init() on
relevant architectures to make it more explicit where the free memory is
released from memblock to the buddy allocator and to reduce code
duplication in architecture specific code.

Link: https://lkml.kernel.org/r/20250313135003.836600-14-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com> [x86]
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> [m68k]
Tested-by: Mark Brown <broonie@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Guo Ren (csky) <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: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russel King <linux@armlinux.org.uk>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@kernel.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
27 files changed:
arch/alpha/mm/init.c
arch/arc/mm/init.c
arch/arm/mm/init.c
arch/arm64/mm/init.c
arch/csky/mm/init.c
arch/hexagon/mm/init.c
arch/loongarch/kernel/numa.c
arch/loongarch/mm/init.c
arch/m68k/mm/init.c
arch/microblaze/mm/init.c
arch/mips/mm/init.c
arch/nios2/mm/init.c
arch/openrisc/mm/init.c
arch/parisc/mm/init.c
arch/powerpc/mm/mem.c
arch/riscv/mm/init.c
arch/s390/mm/init.c
arch/sh/mm/init.c
arch/sparc/mm/init_32.c
arch/sparc/mm/init_64.c
arch/um/kernel/mem.c
arch/x86/mm/init_32.c
arch/x86/mm/init_64.c
arch/xtensa/mm/init.c
include/linux/memblock.h
mm/internal.h
mm/mm_init.c

index 3ab2d2f3c91790d9f4dd24efc2022c0432dc046f..2d491b8cdab95828b766949f6745296e368edbee 100644 (file)
@@ -273,12 +273,6 @@ srm_paging_stop (void)
 }
 #endif
 
-void __init
-mem_init(void)
-{
-       memblock_free_all();
-}
-
 static const pgprot_t protection_map[16] = {
        [VM_NONE]                                       = _PAGE_P(_PAGE_FOE | _PAGE_FOW |
                                                                  _PAGE_FOR),
index 90715b4a0bfaee7b5ddc4dae4e1c468b5defc620..a73cc94f806e70b689d185ca6c9b073a0bff9549 100644 (file)
@@ -169,17 +169,6 @@ void __init arch_mm_preinit(void)
        BUILD_BUG_ON((PTRS_PER_PTE * sizeof(pte_t)) > PAGE_SIZE);
 }
 
-/*
- * mem_init - initializes memory
- *
- * Frees up bootmem
- * Calculates and displays memory available/used
- */
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 #ifdef CONFIG_HIGHMEM
 int pfn_valid(unsigned long pfn)
 {
index 7222100b063148e54e488cf36d5664a9b5e611cd..54bdca025c9fd7af3f98cc3aee60fcf29d1256ab 100644 (file)
@@ -263,17 +263,6 @@ void __init arch_mm_preinit(void)
 #endif
 }
 
-/*
- * mem_init() marks the free areas in the mem_map and tells us how much
- * memory is free.  This is done after various parts of the system have
- * claimed their memory after the kernel image.
- */
-void __init mem_init(void)
-{
-       /* this will put all unused low memory onto the freelists */
-       memblock_free_all();
-}
-
 #ifdef CONFIG_STRICT_KERNEL_RWX
 struct section_perm {
        const char *name;
index 2312e3812043ea891868f8776be999b1df84d082..4b966d5709d2deca2c48b32d78078dbbbbf516af 100644 (file)
@@ -406,17 +406,6 @@ void __init arch_mm_preinit(void)
        }
 }
 
-/*
- * mem_init() marks the free areas in the mem_map and tells us how much memory
- * is free.  This is done after various parts of the system have claimed their
- * memory after the kernel image.
- */
-void __init mem_init(void)
-{
-       /* this will put all unused low memory onto the freelists */
-       memblock_free_all();
-}
-
 void free_initmem(void)
 {
        void *lm_init_begin = lm_alias(__init_begin);
index 3914c2b873daa2a669e6c08cf375506711965d05..573da66b25438a33a8f031ddc3bdfbe9aec062c5 100644 (file)
@@ -42,11 +42,6 @@ unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
                                                __page_aligned_bss;
 EXPORT_SYMBOL(empty_zero_page);
 
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 void free_initmem(void)
 {
        free_initmem_default(-1);
index d412c2314509b049af9412712498f6b0679ae1f7..34eb9d424b96bd0baf6b90a23b36f371c8383477 100644 (file)
@@ -43,24 +43,6 @@ DEFINE_SPINLOCK(kmap_gen_lock);
 /*  checkpatch says don't init this to 0.  */
 unsigned long long kmap_generation;
 
-/*
- * mem_init - initializes memory
- *
- * Frees up bootmem
- * Fixes up more stuff for HIGHMEM
- * Calculates and displays memory available/used
- */
-void __init mem_init(void)
-{
-       /*  No idea where this is actually declared.  Seems to evade LXR.  */
-       memblock_free_all();
-
-       /*
-        *  To-Do:  someone somewhere should wipe out the bootmem map
-        *  after we're done?
-        */
-}
-
 void sync_icache_dcache(pte_t pte)
 {
        unsigned long addr;
index 8eb489725b1a891b3d5dde5806fcf56d3ad58976..30a72fd528c0e7f99a1ddf8bd050f8815eb15f4d 100644 (file)
@@ -387,11 +387,6 @@ void __init paging_init(void)
        free_area_init(zones_size);
 }
 
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 int pcibus_to_node(struct pci_bus *bus)
 {
        return dev_to_node(&bus->dev);
index 6affa3609188a1269942338e1a00ac64a1fb53ac..fdb7f73ad1601661fd9c43a9d55569b2722e2724 100644 (file)
@@ -75,11 +75,6 @@ void __init paging_init(void)
 
        free_area_init(max_zone_pfns);
 }
-
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
 #endif /* !CONFIG_NUMA */
 
 void __ref free_initmem(void)
index 8b11d0d545aaf0ba72c25b88034ba968af0af988..488411af1b3fbb19c7b1f52b0b4530e179c89caf 100644 (file)
@@ -121,7 +121,5 @@ static inline void init_pointer_tables(void)
 
 void __init mem_init(void)
 {
-       /* this will put all memory onto the freelists */
-       memblock_free_all();
        init_pointer_tables();
 }
index 3e664e0efc33c4f4296db444fe91cecc5aafcfaa..65f0d1fb8a2ab597fda79f43a12339d69cc6025c 100644 (file)
@@ -107,9 +107,6 @@ void __init setup_memory(void)
 
 void __init mem_init(void)
 {
-       /* this will put all memory onto the freelists */
-       memblock_free_all();
-
        mem_init_done = 1;
 }
 
index eec38e7735ddc2e4c4f2e6555debc6142a8dc939..a673d3d68254bde4c15386939cab21c898c835e8 100644 (file)
@@ -451,11 +451,6 @@ void __init arch_mm_preinit(void)
 }
 #endif /* !CONFIG_NUMA */
 
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 void free_init_pages(const char *what, unsigned long begin, unsigned long end)
 {
        unsigned long pfn;
index 4ba8dfa0d238ad4eff74b15c4c2b5dbaf58881d8..94efa3de3933f900bb7767e4be58062d5bc126a7 100644 (file)
@@ -60,12 +60,6 @@ void __init paging_init(void)
                        (unsigned long)empty_zero_page + PAGE_SIZE);
 }
 
-void __init mem_init(void)
-{
-       /* this will put all memory onto the freelists */
-       memblock_free_all();
-}
-
 void __init mmu_init(void)
 {
        flush_tlb_all();
index 72c5952607ac9364eee8820ee156773cb5c98020..be1c2eb8bb9455fee37b45fc4ecadc6bcbace928 100644 (file)
@@ -196,9 +196,6 @@ void __init mem_init(void)
        /* clear the zero-page */
        memset((void *)empty_zero_page, 0, PAGE_SIZE);
 
-       /* this will put all low memory onto the freelists */
-       memblock_free_all();
-
        printk("mem_init_done ...........................................\n");
        mem_init_done = 1;
        return;
index 4fbe354dc9b432453877d765d9756ff20b535446..14270715d75435b96248e208f17c8fc28a68d680 100644 (file)
@@ -562,8 +562,6 @@ void __init mem_init(void)
        BUILD_BUG_ON(TMPALIAS_MAP_START >= 0x80000000);
 #endif
 
-       memblock_free_all();
-
 #ifdef CONFIG_PA11
        if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) {
                pcxl_dma_start = (unsigned long)SET_MAP_OFFSET(MAP_START);
index 68efdaf14e58141daa674958698a8e0bfcfe0f3f..d8fe11b6425973a159fa5b8e94ba27aff326bec9 100644 (file)
@@ -327,11 +327,6 @@ void __init arch_mm_preinit(void)
 #endif /* CONFIG_PPC32 */
 }
 
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 void free_initmem(void)
 {
        ppc_md.progress = ppc_printk_progress;
index 9efadabf6be199fd7e59e4b9ba92d3422fcca28c..79b649f6de720a71181f2ea1a95b2031e41c1e7c 100644 (file)
@@ -196,11 +196,6 @@ void __init arch_mm_preinit(void)
        print_vm_layout();
 }
 
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 /* Limit the memory size via mem. */
 static phys_addr_t memory_limit;
 #ifdef CONFIG_XIP_KERNEL
index e771b7458d8b2248b502d0d34ab9c2855c065b3a..5b7b7b281334c1a15049f188fb2fb2d86f065f9c 100644 (file)
@@ -165,12 +165,6 @@ void __init arch_mm_preinit(void)
        setup_zero_pages();     /* Setup zeroed pages. */
 }
 
-void __init mem_init(void)
-{
-       /* this will put all low memory onto the freelists */
-       memblock_free_all();
-}
-
 unsigned long memory_block_size_bytes(void)
 {
        /*
index 6d459ffba4bc29c2e1b722003e5938c852daea1e..99e302eeeec18ad6320c15419067fc16a88c7c60 100644 (file)
@@ -330,8 +330,6 @@ unsigned int mem_init_done = 0;
 
 void __init mem_init(void)
 {
-       memblock_free_all();
-
        /* Set this up early, so we can take care of the zero page */
        cpu_cache_init();
 
index e16c32c5728f815559a1dad1d5077c63774eb484..fdc93dd12c3e3e85ca117eb70a25a575c8dad699 100644 (file)
@@ -264,11 +264,6 @@ void __init arch_mm_preinit(void)
        taint_real_pages();
 }
 
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 void sparc_flush_page_to_ram(struct page *page)
 {
        unsigned long vaddr = (unsigned long)page_address(page);
index 34d46adb9571cf12005ad220448b9bc140817c3e..760818950464c719caa8ab9215c16cf4f4eb1b00 100644 (file)
@@ -2505,8 +2505,6 @@ static void __init register_page_bootmem_info(void)
 }
 void __init mem_init(void)
 {
-       memblock_free_all();
-
        /*
         * 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
index cce387438e60fdd58934625441ac87bde5b35276..379f33a1babfdbaa1968b3959f51edd897ae76af 100644 (file)
@@ -71,8 +71,6 @@ void __init arch_mm_preinit(void)
 
 void __init mem_init(void)
 {
-       /* this will put all low memory onto the freelists */
-       memblock_free_all();
        kmalloc_ok = 1;
 }
 
index 16664c5464b5d998fc1f3e90d8a78ccd210523ae..95b2758b4e4dd4200aaccae0bccfffca6de87111 100644 (file)
@@ -702,9 +702,6 @@ void __init arch_mm_preinit(void)
 
 void __init mem_init(void)
 {
-       /* this will put all low memory onto the freelists */
-       memblock_free_all();
-
        after_bootmem = 1;
        x86_init.hyper.init_after_bootmem();
 
index a88f7db8089ebb717089534be78e0f2cdc3fb836..d67f15386ea2fb5fdb9cbd7d4a8a49849724bce9 100644 (file)
@@ -1357,8 +1357,6 @@ void __init mem_init(void)
 {
        /* clear_bss() already clear the empty_zero_page */
 
-       /* this will put all memory onto the freelists */
-       memblock_free_all();
        after_bootmem = 1;
        x86_init.hyper.init_after_bootmem();
 
index 47ecbe28263e22456c19b393f04610ef1e90333c..cc52733a06493c224aba845f272d12d6ce8f2493 100644 (file)
@@ -129,15 +129,6 @@ void __init zones_init(void)
        print_vm_layout();
 }
 
-/*
- * Initialize memory pages.
- */
-
-void __init mem_init(void)
-{
-       memblock_free_all();
-}
-
 static void __init parse_memmap_one(char *p)
 {
        char *oldp;
index e79eb6ac516fa70347a7a1bc6bc62c8cb6e311af..ef5a1ecc6e595436baab453d6efea062b8118cc8 100644 (file)
@@ -133,7 +133,6 @@ int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
 int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
 int memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t size);
 
-void memblock_free_all(void);
 void memblock_free(void *ptr, size_t size);
 void reset_all_zones_managed_pages(void);
 
index 558c8e2a3d9498ef7c248f49b4db1eec9910a9d6..2f52a65272c1969e2ad619caa17d28d5390eafb9 100644 (file)
@@ -1475,7 +1475,8 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,
 }
 
 extern bool mirrored_kernelcore;
-extern bool memblock_has_mirror(void);
+bool memblock_has_mirror(void);
+void memblock_free_all(void);
 
 static __always_inline void vma_set_range(struct vm_area_struct *vma,
                                          unsigned long start, unsigned long end,
index 6844de516a50d2e0c521ce49a8bbfa18e3d6b19b..c82b0162f1cb8f6c39f1d4e7ce45414b3d686414 100644 (file)
@@ -2738,6 +2738,10 @@ void __init __weak arch_mm_preinit(void)
 {
 }
 
+void __init __weak mem_init(void)
+{
+}
+
 /*
  * Set up kernel memory allocators
  */
@@ -2761,6 +2765,7 @@ void __init mm_core_init(void)
        report_meminit();
        kmsan_init_shadow();
        stack_depot_early_init();
+       memblock_free_all();
        mem_init();
        kmem_cache_init();
        /*