Skip to content

Commit 693fe4c

Browse files
maoxiaochuanAirFortressIlikara
authored andcommitted
LoongArch: Consolidate max_pfn & max_low_pfn calculation
Now there 5 places which calculate max_pfn & max_low_pfn: 1. in fdt_setup() for FDT systems; 2. in memblock_init() for ACPI systems; 3. in init_numa_memory() for NUMA systems; 4. in arch_mem_init() to recalculate for "mem=" cmdline; 5. in paging_init() to recalculate for NUMA systems. Since memblock_init() is called both for ACPI and FDT systems, move the calculation out of the for_each_efi_memory_desc() loop can eliminate the first case. The last case is very questionable (may be derived from the MIPS/Loongson code) and breaks the "mem=" cmdline, so should be removed. And then the NUMA version of paging_init() can be also eliminated. After consolidation there are 3 places of calculation: 1. in memblock_init() for both ACPI and FDT systems; 2. in init_numa_memory() to recalculate for NUMA systems; 3. in arch_mem_init() to recalculate for the "mem=" cmdline. For all cases the calculation is: max_pfn = PFN_DOWN(memblock_end_of_DRAM()); max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn); Cc: stable@vger.kernel.org Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn> fix merge conflict Signed-off-by: ilikara <3435193369@qq.com>
1 parent 9ef5b77 commit 693fe4c

File tree

4 files changed

+7
-30
lines changed

4 files changed

+7
-30
lines changed

arch/loongarch/kernel/mem.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
void __init memblock_init(void)
1616
{
1717
u32 mem_type;
18-
u64 mem_start, mem_end, mem_size;
18+
u64 mem_start, mem_size;
1919
efi_memory_desc_t *md;
2020

2121
/* Parse memory information */
@@ -24,7 +24,6 @@ void __init memblock_init(void)
2424
md->phys_addr = TO_PHYS(md->phys_addr);
2525
mem_start = md->phys_addr;
2626
mem_size = md->num_pages << EFI_PAGE_SHIFT;
27-
mem_end = mem_start + mem_size;
2827

2928
switch (mem_type) {
3029
case EFI_LOADER_CODE:
@@ -34,8 +33,6 @@ void __init memblock_init(void)
3433
case EFI_PERSISTENT_MEMORY:
3534
case EFI_CONVENTIONAL_MEMORY:
3635
memblock_add(mem_start, mem_size);
37-
if (max_low_pfn < (mem_end >> PAGE_SHIFT))
38-
max_low_pfn = mem_end >> PAGE_SHIFT;
3936
break;
4037
case EFI_PAL_CODE:
4138
case EFI_UNUSABLE_MEMORY:
@@ -54,6 +51,8 @@ void __init memblock_init(void)
5451

5552
bpi_memblock_init(&max_low_pfn);
5653

54+
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
55+
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
5756
memblock_set_current_limit(PFN_PHYS(max_low_pfn));
5857

5958
/* Reserve the first 2MB */

arch/loongarch/kernel/numa.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ int __init init_numa_memory(void)
275275
node_mem_init(node);
276276
node_set_online(node);
277277
}
278-
max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
278+
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
279+
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
279280

280281
setup_nr_node_ids();
281282
loongson_sysconf.nr_nodes = nr_node_ids;
@@ -286,26 +287,6 @@ int __init init_numa_memory(void)
286287

287288
#endif
288289

289-
void __init paging_init(void)
290-
{
291-
unsigned int node;
292-
unsigned long zones_size[MAX_NR_ZONES] = {0, };
293-
294-
for_each_online_node(node) {
295-
unsigned long start_pfn, end_pfn;
296-
297-
get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
298-
299-
if (end_pfn > max_low_pfn)
300-
max_low_pfn = end_pfn;
301-
}
302-
#ifdef CONFIG_ZONE_DMA32
303-
zones_size[ZONE_DMA32] = MAX_DMA32_PFN;
304-
#endif
305-
zones_size[ZONE_NORMAL] = max_low_pfn;
306-
free_area_init(zones_size);
307-
}
308-
309290
void __init mem_init(void)
310291
{
311292
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);

arch/loongarch/kernel/setup.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ static void __init fdt_setup(void)
410410

411411
early_init_dt_scan(fdt_pointer, __pa(fdt_pointer));
412412
early_init_fdt_reserve_self();
413-
414-
max_low_pfn = PFN_PHYS(memblock_end_of_DRAM());
415413
#endif
416414
}
417415

@@ -506,7 +504,8 @@ static void __init check_kernel_sections_mem(void)
506504
static void __init arch_mem_init(char **cmdline_p)
507505
{
508506
/* Recalculate max_low_pfn for "mem=xxx" */
509-
max_pfn = max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
507+
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
508+
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
510509

511510
if (usermem)
512511
pr_info("User-defined physical RAM map overwrite\n");

arch/loongarch/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ int __ref page_is_ram(unsigned long pfn)
6060
return memblock_is_memory(addr) && !memblock_is_reserved(addr);
6161
}
6262

63-
#ifndef CONFIG_NUMA
6463
void __init paging_init(void)
6564
{
6665
unsigned long max_zone_pfns[MAX_NR_ZONES];
@@ -80,7 +79,6 @@ void __init mem_init(void)
8079

8180
memblock_free_all();
8281
}
83-
#endif /* !CONFIG_NUMA */
8482

8583
void __ref free_initmem(void)
8684
{

0 commit comments

Comments
 (0)