MIPS: OCTEON: use the free memory below the kernel
PATCH RESEND 1/1 MIPS: OCTEON: use the free memory below the kernel
plat_mem_setup() asks bootmem only for memory above _end. The kernel is loaded at 0x1100000, so whatever bootmem has free below _text is never added to memblock. On a CN6335 board with the Cavium bootloader that is 14MB, 0x200000-0xffffff:
before: node 0: [mem 0x0000000001100000-0x0000000001cc6fff]
after: node 0: [mem 0x0000000000200000-0x0000000000ffffff]
node 0: [mem 0x0000000001100000-0x0000000001cc6fff]
Claim it before the main loop, in 1MB pieces since the holes there are small and unaligned. It counts towards max_memory like the rest, and a piece inside the crash kernel range, which is added on its own, is skipped as the main loop does. bootmem never hands out what the bootloader reserved (the exception vectors, its named blocks, the kernel image itself), so only free memory is claimed.
---
RESEND: no reply since the posting of 2026-10-27,
https://lore.kernel.org/all/[email protected]/
Unchanged and still applies to mips-next (dfe3ece66313); only the Assisted-by tag is dropped (an LLM helped write this patch).
Tested on mips-next with cavium_octeon_defconfig (KEXEC=y, CRASH_DUMP=n) on a CN6335 board, 4GB, Cavium U-Boot 1.1.1: "Memory:" goes from 4023588K/4169492K to 4037924K/4183828K available. Built with KEXEC=n and CRASH_DUMP=y as well.
arch/mips/cavium-octeon/setup.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/mips/cavium-octeon/setup.c +21 -0
@@ -1022,6 +1022,27 @@ void __init plat_mem_setup(void)* which is handled by memblock */ cvmx_bootmem_lock (); +/* +* The loop below only takes memory above the kernel. Claim what +* bootmem has free below it as well, 1MB at a time: the holes the +* bootloader leaves there are small and not aligned to +* mem_alloc_size. +*/ +while (total < max_memory) { + memory =cvmx_bootmem_phy_alloc (0x100000 ,0 , +__pa_symbol (&_text), +0x100000 , +CVMX_BOOTMEM_FLAG_NO_LOCKING ); +if (memory <0 ) +break ; +#ifdef CONFIG_KEXEC +/* The crash kernel range is already added */ +if (memory < crashk_end && memory +0x100000 > crashk_base) +continue ; +#endif +memblock_add (memory,0x100000 ); + total +=0x100000 ; + }while (total < max_memory) { memory = cvmx_bootmem_phy_alloc(mem_alloc_size, __pa_symbol(&_end), -1,
Signature · 1 line
2.53.0
Please do not apply this patch. sashiko's review found two cases it breaks, which I did not test:
- After kexec, the old kernel frees all bootmem above 1MB, so the new kernel would claim the blocks that hold the boot descriptor and the FDT.
- With CONFIG_RELOCATABLE the relocated image is not reserved in bootmem, so the claim below _text can land inside it.
Consider it withdrawn. I will send a v2 if I get to cover both.
Orgad