Skip to content

Commit f9a7feb

Browse files
Greg Ungererralfbaechle
authored andcommitted
MIPS: Fix start of free memory when using initrd
Currently when using an initrd on a MIPS system the start of the bootmem region of memory is set to the larger of the end of the kernel bss region (_end) or the end of the initrd. In a typical memory layout where the initrd is at some address above the kernel image this means that the start of the bootmem region will be the end of the initrd. But when we are done processing/loading the initrd we have no way to reclaim the memory region it occupied, and we lose a large chunk of now otherwise empty RAM from our final running system. The bootmem code is designed to allow this initrd to be reserved (and the code in finalize_initrd() currently does this). When the initrd is finally processed/loaded its reserved memory is freed. Fix the setting of the start of the bootmem map to be the end of the kernel. [[email protected]: fold in the fix of Ashok Kumar <[email protected]>.] Signed-off-by: Greg Ungerer <[email protected]> Cc: [email protected] Patchwork: https://patchwork.linux-mips.org/patch/1574/ Cc: Ashok Kumar <[email protected]> Patchwork: https://patchwork.linux-mips.org/patch/5883/ Patchwork: https://patchwork.linux-mips.org/patch/6028/ Patchwork: https://patchwork.linux-mips.org/patch/6064/ Signed-off-by: Ralf Baechle <[email protected]>
1 parent 007fbbe commit f9a7feb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

arch/mips/kernel/setup.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,13 @@ static void __init bootmem_init(void)
300300
int i;
301301

302302
/*
303-
* Init any data related to initrd. It's a nop if INITRD is
304-
* not selected. Once that done we can determine the low bound
305-
* of usable memory.
303+
* Sanity check any INITRD first. We don't take it into account
304+
* for bootmem setup initially, rely on the end-of-kernel-code
305+
* as our memory range starting point. Once bootmem is inited we
306+
* will reserve the area used for the initrd.
306307
*/
307-
reserved_end = max(init_initrd(),
308-
(unsigned long) PFN_UP(__pa_symbol(&_end)));
308+
init_initrd();
309+
reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
309310

310311
/*
311312
* max_low_pfn is not a number of pages. The number of pages
@@ -362,6 +363,14 @@ static void __init bootmem_init(void)
362363
max_low_pfn = PFN_DOWN(HIGHMEM_START);
363364
}
364365

366+
#ifdef CONFIG_BLK_DEV_INITRD
367+
/*
368+
* mapstart should be after initrd_end
369+
*/
370+
if (initrd_end)
371+
mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
372+
#endif
373+
365374
/*
366375
* Initialize the boot-time allocator with low memory only.
367376
*/

0 commit comments

Comments
 (0)