Skip to content

Commit 8268af3

Browse files
rpptakpm00
authored andcommitted
arch, mm: set max_mapnr when allocating memory map for FLATMEM
max_mapnr is essentially the size of the memory map for systems that use FLATMEM. There is no reason to calculate it in each and every architecture when it's anyway calculated in alloc_node_mem_map(). Drop setting of max_mapnr from architecture code and set it once in alloc_node_mem_map(). While on it, move definition of mem_map and max_mapnr to mm/mm_init.c so there won't be two copies for MMU and !MMU variants. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Acked-by: Dave Hansen <[email protected]> [x86] Tested-by: Mark Brown <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Betkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: David S. Miller <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Gerald Schaefer <[email protected]> Cc: Guo Ren (csky) <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Helge Deller <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiaxun Yang <[email protected]> Cc: Johannes Berg <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russel King <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Thomas Gleinxer <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d319c8b commit 8268af3

File tree

26 files changed

+21
-86
lines changed

26 files changed

+21
-86
lines changed

arch/alpha/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ srm_paging_stop (void)
276276
void __init
277277
mem_init(void)
278278
{
279-
set_max_mapnr(max_low_pfn);
280279
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
281280
memblock_free_all();
282281
}

arch/arc/mm/init.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ void __init setup_arch_memory(void)
154154

155155
arch_pfn_offset = min(min_low_pfn, min_high_pfn);
156156
kmap_init();
157-
158-
#else /* CONFIG_HIGHMEM */
159-
/* pfn_valid() uses this when FLATMEM=y and HIGHMEM=n */
160-
max_mapnr = max_low_pfn - min_low_pfn;
161-
162157
#endif /* CONFIG_HIGHMEM */
163158

164159
free_area_init(max_zone_pfn);

arch/arm/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ void __init mem_init(void)
275275
swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
276276
#endif
277277

278-
set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
279-
280278
#ifdef CONFIG_SA1111
281279
/* now that our DMA memory is actually so designated, we can free it */
282280
memblock_phys_free(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);

arch/csky/mm/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ void __init mem_init(void)
4646
{
4747
#ifdef CONFIG_HIGHMEM
4848
unsigned long tmp;
49-
50-
set_max_mapnr(highend_pfn - ARCH_PFN_OFFSET);
51-
#else
52-
set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET);
5349
#endif
5450
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
5551

arch/loongarch/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ void __init paging_init(void)
7878

7979
void __init mem_init(void)
8080
{
81-
max_mapnr = max_low_pfn;
8281
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
8382

8483
memblock_free_all();

arch/microblaze/mm/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,13 @@ void __init setup_memory(void)
104104
*
105105
* min_low_pfn - the first page (mm/bootmem.c - node_boot_start)
106106
* max_low_pfn
107-
* max_mapnr - the first unused page (mm/bootmem.c - node_low_pfn)
108107
*/
109108

110109
/* memory start is from the kernel end (aligned) to higher addr */
111110
min_low_pfn = memory_start >> PAGE_SHIFT; /* minimum for allocation */
112-
/* RAM is assumed contiguous */
113-
max_mapnr = memory_size >> PAGE_SHIFT;
114111
max_low_pfn = ((u64)memory_start + (u64)lowmem_size) >> PAGE_SHIFT;
115112
max_pfn = ((u64)memory_start + (u64)memory_size) >> PAGE_SHIFT;
116113

117-
pr_info("%s: max_mapnr: %#lx\n", __func__, max_mapnr);
118114
pr_info("%s: min_low_pfn: %#lx\n", __func__, min_low_pfn);
119115
pr_info("%s: max_low_pfn: %#lx\n", __func__, max_low_pfn);
120116
pr_info("%s: max_pfn: %#lx\n", __func__, max_pfn);

arch/mips/mm/init.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,7 @@ void __init paging_init(void)
415415
" %ldk highmem ignored\n",
416416
(highend_pfn - max_low_pfn) << (PAGE_SHIFT - 10));
417417
max_zone_pfns[ZONE_HIGHMEM] = max_low_pfn;
418-
419-
max_mapnr = max_low_pfn;
420-
} else if (highend_pfn) {
421-
max_mapnr = highend_pfn;
422-
} else {
423-
max_mapnr = max_low_pfn;
424418
}
425-
#else
426-
max_mapnr = max_low_pfn;
427419
#endif
428420
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
429421

arch/nios2/kernel/setup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ void __init setup_arch(char **cmdline_p)
158158
*cmdline_p = boot_command_line;
159159

160160
find_limits(&min_low_pfn, &max_low_pfn, &max_pfn);
161-
max_mapnr = max_low_pfn;
162161

163162
memblock_reserve(__pa_symbol(_stext), _end - _stext);
164163
#ifdef CONFIG_BLK_DEV_INITRD

arch/nios2/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void __init paging_init(void)
5151
pagetable_init();
5252
pgd_current = swapper_pg_dir;
5353

54-
max_zone_pfn[ZONE_NORMAL] = max_mapnr;
54+
max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
5555

5656
/* pass the memory from the bootmem allocator to the main allocator */
5757
free_area_init(max_zone_pfn);

arch/openrisc/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ void __init mem_init(void)
193193
{
194194
BUG_ON(!mem_map);
195195

196-
max_mapnr = max_low_pfn;
197196
high_memory = (void *)__va(max_low_pfn * PAGE_SIZE);
198197

199198
/* clear the zero-page */

arch/parisc/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ void __init mem_init(void)
563563
#endif
564564

565565
high_memory = __va((max_pfn << PAGE_SHIFT));
566-
set_max_mapnr(max_low_pfn);
567566
memblock_free_all();
568567

569568
#ifdef CONFIG_PA11

arch/powerpc/kernel/setup-common.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,6 @@ void __init setup_arch(char **cmdline_p)
957957

958958
/* Parse memory topology */
959959
mem_topology_setup();
960-
/* Set max_mapnr before paging_init() */
961-
set_max_mapnr(max_pfn);
962960
high_memory = (void *)__va(max_low_pfn * PAGE_SIZE);
963961

964962
/*

arch/riscv/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ static void __init setup_bootmem(void)
298298
high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
299299

300300
dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn));
301-
set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET);
302301

303302
reserve_initrd_mem();
304303

arch/s390/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ void __init mem_init(void)
159159
cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
160160
cpumask_set_cpu(0, mm_cpumask(&init_mm));
161161

162-
set_max_mapnr(max_low_pfn);
163162
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
164163

165164
pv_init();

arch/sh/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ void __init paging_init(void)
290290
*/
291291
max_low_pfn = max_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT;
292292
min_low_pfn = __MEMORY_START >> PAGE_SHIFT;
293-
set_max_mapnr(max_low_pfn - min_low_pfn);
294293

295294
nodes_clear(node_online_map);
296295

arch/sparc/mm/init_32.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ void __init mem_init(void)
275275

276276
taint_real_pages();
277277

278-
max_mapnr = last_valid_pfn - pfn_base;
279278
high_memory = __va(max_low_pfn << PAGE_SHIFT);
280279
memblock_free_all();
281280

arch/um/include/shared/mem_user.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ extern int iomem_size;
4747
#define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 << 22) - 1))
4848

4949
extern unsigned long find_iomem(char *driver, unsigned long *len_out);
50-
extern void mem_total_pages(unsigned long physmem, unsigned long iomem);
5150
extern void setup_physmem(unsigned long start, unsigned long usable,
5251
unsigned long len);
5352
extern void map_memory(unsigned long virt, unsigned long phys,

arch/um/kernel/physmem.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ static int physmem_fd = -1;
2222
unsigned long high_physmem;
2323
EXPORT_SYMBOL(high_physmem);
2424

25-
void __init mem_total_pages(unsigned long physmem, unsigned long iomem)
26-
{
27-
unsigned long phys_pages, iomem_pages, total_pages;
28-
29-
phys_pages = physmem >> PAGE_SHIFT;
30-
iomem_pages = iomem >> PAGE_SHIFT;
31-
32-
total_pages = phys_pages + iomem_pages;
33-
34-
max_mapnr = total_pages;
35-
}
36-
3725
void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
3826
int r, int w, int x)
3927
{

arch/um/kernel/um_arch.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ void __init setup_arch(char **cmdline_p)
419419

420420
stack_protections((unsigned long) init_task.stack);
421421
setup_physmem(uml_physmem, uml_reserved, physmem_size);
422-
mem_total_pages(physmem_size, iomem_size);
423422
uml_dtb_init();
424423
read_initrd();
425424

arch/x86/mm/init_32.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,6 @@ void __init initmem_init(void)
650650

651651
memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
652652

653-
#ifdef CONFIG_FLATMEM
654-
max_mapnr = IS_ENABLED(CONFIG_HIGHMEM) ? highend_pfn : max_low_pfn;
655-
#endif
656653
__vmalloc_start_set = true;
657654

658655
printk(KERN_NOTICE "%ldMB LOWMEM available.\n",

arch/xtensa/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ void __init mem_init(void)
164164
{
165165
free_highpages();
166166

167-
max_mapnr = max_pfn - ARCH_PFN_OFFSET;
168167
high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
169168

170169
memblock_free_all();

include/asm-generic/memory_model.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#define __page_to_pfn(page) ((unsigned long)((page) - mem_map) + \
2020
ARCH_PFN_OFFSET)
2121

22+
/* avoid <linux/mm.h> include hell */
23+
extern unsigned long max_mapnr;
24+
2225
#ifndef pfn_valid
2326
static inline int pfn_valid(unsigned long pfn)
2427
{
25-
/* avoid <linux/mm.h> include hell */
26-
extern unsigned long max_mapnr;
2728
unsigned long pfn_offset = ARCH_PFN_OFFSET;
2829

2930
return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr;

include/linux/mm.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@ extern int sysctl_page_lock_unfairness;
4646
void mm_core_init(void);
4747
void init_mm_internals(void);
4848

49-
#ifndef CONFIG_NUMA /* Don't use mapnrs, do it properly */
50-
extern unsigned long max_mapnr;
51-
52-
static inline void set_max_mapnr(unsigned long limit)
53-
{
54-
max_mapnr = limit;
55-
}
56-
#else
57-
static inline void set_max_mapnr(unsigned long limit) { }
58-
#endif
59-
6049
extern atomic_long_t _totalram_pages;
6150
static inline unsigned long totalram_pages(void)
6251
{

mm/memory.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@
9595
#warning Unfortunate NUMA and NUMA Balancing config, growing page-frame for last_cpupid.
9696
#endif
9797

98-
#ifndef CONFIG_NUMA
99-
unsigned long max_mapnr;
100-
EXPORT_SYMBOL(max_mapnr);
101-
102-
struct page *mem_map;
103-
EXPORT_SYMBOL(mem_map);
104-
#endif
105-
10698
static vm_fault_t do_fault(struct vm_fault *vmf);
10799
static vm_fault_t do_anonymous_page(struct vm_fault *vmf);
108100
static bool vmf_pte_changed(struct vm_fault *vmf);

mm/mm_init.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737

3838
#include <asm/setup.h>
3939

40+
#ifndef CONFIG_NUMA
41+
unsigned long max_mapnr;
42+
EXPORT_SYMBOL(max_mapnr);
43+
44+
struct page *mem_map;
45+
EXPORT_SYMBOL(mem_map);
46+
#endif
47+
4048
#ifdef CONFIG_DEBUG_MEMORY_INIT
4149
int __meminitdata mminit_loglevel;
4250

@@ -1639,7 +1647,7 @@ static void __init alloc_node_mem_map(struct pglist_data *pgdat)
16391647
start = pgdat->node_start_pfn & ~(MAX_ORDER_NR_PAGES - 1);
16401648
offset = pgdat->node_start_pfn - start;
16411649
/*
1642-
* The zone's endpoints aren't required to be MAX_PAGE_ORDER
1650+
* The zone's endpoints aren't required to be MAX_PAGE_ORDER
16431651
* aligned but the node_mem_map endpoints must be in order
16441652
* for the buddy allocator to function correctly.
16451653
*/
@@ -1655,14 +1663,15 @@ static void __init alloc_node_mem_map(struct pglist_data *pgdat)
16551663
pr_debug("%s: node %d, pgdat %08lx, node_mem_map %08lx\n",
16561664
__func__, pgdat->node_id, (unsigned long)pgdat,
16571665
(unsigned long)pgdat->node_mem_map);
1658-
#ifndef CONFIG_NUMA
1666+
16591667
/* the global mem_map is just set as node 0's */
1660-
if (pgdat == NODE_DATA(0)) {
1661-
mem_map = NODE_DATA(0)->node_mem_map;
1662-
if (page_to_pfn(mem_map) != pgdat->node_start_pfn)
1663-
mem_map -= offset;
1664-
}
1665-
#endif
1668+
WARN_ON(pgdat != NODE_DATA(0));
1669+
1670+
mem_map = pgdat->node_mem_map;
1671+
if (page_to_pfn(mem_map) != pgdat->node_start_pfn)
1672+
mem_map -= offset;
1673+
1674+
max_mapnr = end - start;
16661675
}
16671676
#else
16681677
static inline void alloc_node_mem_map(struct pglist_data *pgdat) { }

mm/nommu.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,12 @@
4444

4545
void *high_memory;
4646
EXPORT_SYMBOL(high_memory);
47-
struct page *mem_map;
48-
unsigned long max_mapnr;
49-
EXPORT_SYMBOL(max_mapnr);
5047
unsigned long highest_memmap_pfn;
5148
int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
5249
int heap_stack_gap = 0;
5350

5451
atomic_long_t mmap_pages_allocated;
5552

56-
EXPORT_SYMBOL(mem_map);
5753

5854
/* list of mapped, potentially shareable regions */
5955
static struct kmem_cache *vm_region_jar;

0 commit comments

Comments
 (0)