From f9a7febd82f413b9c8bafd40145bc398b7eb619f Mon Sep 17 00:00:00 2001 From: Greg Ungerer Date: Wed, 8 Sep 2010 15:50:43 +1000 Subject: [PATCH] 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. [ralf@linux-mips.org: fold in the fix of Ashok Kumar .] Signed-off-by: Greg Ungerer Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/1574/ Cc: Ashok Kumar 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 --- arch/mips/kernel/setup.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index c538d6e01b7b..a842154d57dc 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -300,12 +300,13 @@ static void __init bootmem_init(void) int i; /* - * Init any data related to initrd. It's a nop if INITRD is - * not selected. Once that done we can determine the low bound - * of usable memory. + * Sanity check any INITRD first. We don't take it into account + * for bootmem setup initially, rely on the end-of-kernel-code + * as our memory range starting point. Once bootmem is inited we + * will reserve the area used for the initrd. */ - reserved_end = max(init_initrd(), - (unsigned long) PFN_UP(__pa_symbol(&_end))); + init_initrd(); + reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end)); /* * max_low_pfn is not a number of pages. The number of pages @@ -362,6 +363,14 @@ static void __init bootmem_init(void) max_low_pfn = PFN_DOWN(HIGHMEM_START); } +#ifdef CONFIG_BLK_DEV_INITRD + /* + * mapstart should be after initrd_end + */ + if (initrd_end) + mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end))); +#endif + /* * Initialize the boot-time allocator with low memory only. */ -- 2.20.1