Skip to content

Commit bcec54b

Browse files
rpptpaulburton
authored andcommitted
mips: switch to NO_BOOTMEM
MIPS already has memblock support and all the memory is already registered with it. This patch replaces bootmem memory reservations with memblock ones and removes the bootmem initialization. Since memblock allocates memory in top-down mode, we ensure that memblock limit is max_low_pfn to prevent allocations from the high memory. To have the exceptions base in the lower 512M of the physical memory, its allocation in arch/mips/kernel/traps.c::traps_init() is using bottom-up mode. Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Paul Burton <paul.burton@mips.com> Patchwork: https://patchwork.linux-mips.org/patch/20560/ Cc: Serge Semin <fancer.lancer@gmail.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: James Hogan <jhogan@kernel.org> Cc: Huacai Chen <chenhc@lemote.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: linux-mips@linux-mips.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org
1 parent 0eb1cff commit bcec54b

File tree

5 files changed

+46
-102
lines changed

5 files changed

+46
-102
lines changed

arch/mips/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ config MIPS
7878
select RTC_LIB if !MACH_LOONGSON64
7979
select SYSCTL_EXCEPTION_TRACE
8080
select VIRT_TO_BUS
81+
select NO_BOOTMEM
8182

8283
menu "Machine selection"
8384

arch/mips/kernel/setup.c

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void __init finalize_initrd(void)
333333

334334
maybe_bswap_initrd();
335335

336-
reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
336+
memblock_reserve(__pa(initrd_start), size);
337337
initrd_below_start_ok = 1;
338338

339339
pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
@@ -370,20 +370,10 @@ static void __init bootmem_init(void)
370370

371371
#else /* !CONFIG_SGI_IP27 */
372372

373-
static unsigned long __init bootmap_bytes(unsigned long pages)
374-
{
375-
unsigned long bytes = DIV_ROUND_UP(pages, 8);
376-
377-
return ALIGN(bytes, sizeof(long));
378-
}
379-
380373
static void __init bootmem_init(void)
381374
{
382375
unsigned long reserved_end;
383-
unsigned long mapstart = ~0UL;
384-
unsigned long bootmap_size;
385376
phys_addr_t ramstart = PHYS_ADDR_MAX;
386-
bool bootmap_valid = false;
387377
int i;
388378

389379
/*
@@ -395,6 +385,8 @@ static void __init bootmem_init(void)
395385
init_initrd();
396386
reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
397387

388+
memblock_reserve(PHYS_OFFSET, reserved_end << PAGE_SHIFT);
389+
398390
/*
399391
* max_low_pfn is not a number of pages. The number of pages
400392
* of the system is given by 'max_low_pfn - min_low_pfn'.
@@ -442,9 +434,6 @@ static void __init bootmem_init(void)
442434
if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
443435
continue;
444436
#endif
445-
if (start >= mapstart)
446-
continue;
447-
mapstart = max(reserved_end, start);
448437
}
449438

450439
if (min_low_pfn >= max_low_pfn)
@@ -456,9 +445,11 @@ static void __init bootmem_init(void)
456445
/*
457446
* Reserve any memory between the start of RAM and PHYS_OFFSET
458447
*/
459-
if (ramstart > PHYS_OFFSET)
448+
if (ramstart > PHYS_OFFSET) {
460449
add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
461450
BOOT_MEM_RESERVED);
451+
memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
452+
}
462453

463454
if (min_low_pfn > ARCH_PFN_OFFSET) {
464455
pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
@@ -483,52 +474,6 @@ static void __init bootmem_init(void)
483474
max_low_pfn = PFN_DOWN(HIGHMEM_START);
484475
}
485476

486-
#ifdef CONFIG_BLK_DEV_INITRD
487-
/*
488-
* mapstart should be after initrd_end
489-
*/
490-
if (initrd_end)
491-
mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
492-
#endif
493-
494-
/*
495-
* check that mapstart doesn't overlap with any of
496-
* memory regions that have been reserved through eg. DTB
497-
*/
498-
bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
499-
500-
bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
501-
bootmap_size);
502-
for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
503-
unsigned long mapstart_addr;
504-
505-
switch (boot_mem_map.map[i].type) {
506-
case BOOT_MEM_RESERVED:
507-
mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
508-
boot_mem_map.map[i].size);
509-
if (PHYS_PFN(mapstart_addr) < mapstart)
510-
break;
511-
512-
bootmap_valid = memory_region_available(mapstart_addr,
513-
bootmap_size);
514-
if (bootmap_valid)
515-
mapstart = PHYS_PFN(mapstart_addr);
516-
break;
517-
default:
518-
break;
519-
}
520-
}
521-
522-
if (!bootmap_valid)
523-
panic("No memory area to place a bootmap bitmap");
524-
525-
/*
526-
* Initialize the boot-time allocator with low memory only.
527-
*/
528-
if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
529-
min_low_pfn, max_low_pfn))
530-
panic("Unexpected memory size required for bootmap");
531-
532477
for (i = 0; i < boot_mem_map.nr_map; i++) {
533478
unsigned long start, end;
534479

@@ -577,9 +522,9 @@ static void __init bootmem_init(void)
577522
default:
578523
/* Not usable memory */
579524
if (start > min_low_pfn && end < max_low_pfn)
580-
reserve_bootmem(boot_mem_map.map[i].addr,
581-
boot_mem_map.map[i].size,
582-
BOOTMEM_DEFAULT);
525+
memblock_reserve(boot_mem_map.map[i].addr,
526+
boot_mem_map.map[i].size);
527+
583528
continue;
584529
}
585530

@@ -602,15 +547,9 @@ static void __init bootmem_init(void)
602547
size = end - start;
603548

604549
/* Register lowmem ranges */
605-
free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
606550
memory_present(0, start, end);
607551
}
608552

609-
/*
610-
* Reserve the bootmap memory.
611-
*/
612-
reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
613-
614553
#ifdef CONFIG_RELOCATABLE
615554
/*
616555
* The kernel reserves all memory below its _end symbol as bootmem,
@@ -907,21 +846,29 @@ static void __init arch_mem_init(char **cmdline_p)
907846
early_init_fdt_scan_reserved_mem();
908847

909848
bootmem_init();
849+
850+
/*
851+
* Prevent memblock from allocating high memory.
852+
* This cannot be done before max_low_pfn is detected, so up
853+
* to this point is possible to only reserve physical memory
854+
* with memblock_reserve; memblock_virt_alloc* can be used
855+
* only after this point
856+
*/
857+
memblock_set_current_limit(PFN_PHYS(max_low_pfn));
858+
910859
#ifdef CONFIG_PROC_VMCORE
911860
if (setup_elfcorehdr && setup_elfcorehdr_size) {
912861
printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
913862
setup_elfcorehdr, setup_elfcorehdr_size);
914-
reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
915-
BOOTMEM_DEFAULT);
863+
memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
916864
}
917865
#endif
918866

919867
mips_parse_crashkernel();
920868
#ifdef CONFIG_KEXEC
921869
if (crashk_res.start != crashk_res.end)
922-
reserve_bootmem(crashk_res.start,
923-
crashk_res.end - crashk_res.start + 1,
924-
BOOTMEM_DEFAULT);
870+
memblock_reserve(crashk_res.start,
871+
crashk_res.end - crashk_res.start + 1);
925872
#endif
926873
device_tree_init();
927874
sparse_init();
@@ -931,7 +878,7 @@ static void __init arch_mem_init(char **cmdline_p)
931878
/* Tell bootmem about cma reserved memblock section */
932879
for_each_memblock(reserved, reg)
933880
if (reg->size != 0)
934-
reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
881+
memblock_reserve(reg->base, reg->size);
935882

936883
reserve_bootmem_region(__pa_symbol(&__nosave_begin),
937884
__pa_symbol(&__nosave_end)); /* Reserve for hibernation */

arch/mips/kernel/traps.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/spinlock.h>
3030
#include <linux/kallsyms.h>
3131
#include <linux/bootmem.h>
32+
#include <linux/memblock.h>
3233
#include <linux/interrupt.h>
3334
#include <linux/ptrace.h>
3435
#include <linux/kgdb.h>
@@ -2260,8 +2261,10 @@ void __init trap_init(void)
22602261
unsigned long size = 0x200 + VECTORSPACING*64;
22612262
phys_addr_t ebase_pa;
22622263

2264+
memblock_set_bottom_up(true);
22632265
ebase = (unsigned long)
22642266
__alloc_bootmem(size, 1 << fls(size), 0);
2267+
memblock_set_bottom_up(false);
22652268

22662269
/*
22672270
* Try to ensure ebase resides in KSeg0 if possible.

arch/mips/loongson64/loongson-3/numa.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,43 +180,39 @@ static void __init szmem(unsigned int node)
180180

181181
static void __init node_mem_init(unsigned int node)
182182
{
183-
unsigned long bootmap_size;
184183
unsigned long node_addrspace_offset;
185-
unsigned long start_pfn, end_pfn, freepfn;
184+
unsigned long start_pfn, end_pfn;
186185

187186
node_addrspace_offset = nid_to_addroffset(node);
188187
pr_info("Node%d's addrspace_offset is 0x%lx\n",
189188
node, node_addrspace_offset);
190189

191190
get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
192-
freepfn = start_pfn;
193-
if (node == 0)
194-
freepfn = PFN_UP(__pa_symbol(&_end)); /* kernel end address */
195-
pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx, freepfn=0x%lx\n",
196-
node, start_pfn, end_pfn, freepfn);
191+
pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx\n",
192+
node, start_pfn, end_pfn);
197193

198194
__node_data[node] = prealloc__node_data + node;
199195

200-
NODE_DATA(node)->bdata = &bootmem_node_data[node];
201196
NODE_DATA(node)->node_start_pfn = start_pfn;
202197
NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
203198

204-
bootmap_size = init_bootmem_node(NODE_DATA(node), freepfn,
205-
start_pfn, end_pfn);
206199
free_bootmem_with_active_regions(node, end_pfn);
207-
if (node == 0) /* used by finalize_initrd() */
200+
201+
if (node == 0) {
202+
/* kernel end address */
203+
unsigned long kernel_end_pfn = PFN_UP(__pa_symbol(&_end));
204+
205+
/* used by finalize_initrd() */
208206
max_low_pfn = end_pfn;
209207

210-
/* This is reserved for the kernel and bdata->node_bootmem_map */
211-
reserve_bootmem_node(NODE_DATA(node), start_pfn << PAGE_SHIFT,
212-
((freepfn - start_pfn) << PAGE_SHIFT) + bootmap_size,
213-
BOOTMEM_DEFAULT);
208+
/* Reserve the kernel text/data/bss */
209+
memblock_reserve(start_pfn << PAGE_SHIFT,
210+
((kernel_end_pfn - start_pfn) << PAGE_SHIFT));
214211

215-
if (node == 0 && node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT)) {
216212
/* Reserve 0xfe000000~0xffffffff for RS780E integrated GPU */
217-
reserve_bootmem_node(NODE_DATA(node),
218-
(node_addrspace_offset | 0xfe000000),
219-
32 << 20, BOOTMEM_DEFAULT);
213+
if (node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT))
214+
memblock_reserve((node_addrspace_offset | 0xfe000000),
215+
32 << 20);
220216
}
221217

222218
sparse_memory_present_with_active_regions(node);

arch/mips/sgi-ip27/ip27-memory.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ static void __init node_mem_init(cnodeid_t node)
389389
{
390390
unsigned long slot_firstpfn = slot_getbasepfn(node, 0);
391391
unsigned long slot_freepfn = node_getfirstfree(node);
392-
unsigned long bootmap_size;
393392
unsigned long start_pfn, end_pfn;
394393

395394
get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
@@ -400,7 +399,6 @@ static void __init node_mem_init(cnodeid_t node)
400399
__node_data[node] = __va(slot_freepfn << PAGE_SHIFT);
401400
memset(__node_data[node], 0, PAGE_SIZE);
402401

403-
NODE_DATA(node)->bdata = &bootmem_node_data[node];
404402
NODE_DATA(node)->node_start_pfn = start_pfn;
405403
NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
406404

@@ -409,12 +407,11 @@ static void __init node_mem_init(cnodeid_t node)
409407
slot_freepfn += PFN_UP(sizeof(struct pglist_data) +
410408
sizeof(struct hub_data));
411409

412-
bootmap_size = init_bootmem_node(NODE_DATA(node), slot_freepfn,
413-
start_pfn, end_pfn);
414410
free_bootmem_with_active_regions(node, end_pfn);
415-
reserve_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT,
416-
((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size,
417-
BOOTMEM_DEFAULT);
411+
412+
memblock_reserve(slot_firstpfn << PAGE_SHIFT,
413+
((slot_freepfn - slot_firstpfn) << PAGE_SHIFT));
414+
418415
sparse_memory_present_with_active_regions(node);
419416
}
420417

0 commit comments

Comments
 (0)