Skip to content

Commit fa3354e

Browse files
rppttorvalds
authored andcommitted
mm: free_area_init: use maximal zone PFNs rather than zone sizes
Currently, architectures that use free_area_init() to initialize memory map and node and zone structures need to calculate zone and hole sizes. We can use free_area_init_nodes() instead and let it detect the zone boundaries while the architectures will only have to supply the possible limits for the zones. Signed-off-by: Mike Rapoport <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Tested-by: Hoan Tran <[email protected]> [arm64] Reviewed-by: Baoquan He <[email protected]> Cc: Brian Cain <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Greentime Hu <[email protected]> Cc: Greg Ungerer <[email protected]> Cc: Guan Xuetao <[email protected]> Cc: Guo Ren <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Helge Deller <[email protected]> Cc: "James E.J. Bottomley" <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Ley Foon Tan <[email protected]> Cc: Mark Salter <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Michal Simek <[email protected]> Cc: Nick Hu <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Rich Felker <[email protected]> Cc: Russell King <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Tony Luck <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Yoshinori Sato <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3f08a30 commit fa3354e

File tree

12 files changed

+38
-60
lines changed

12 files changed

+38
-60
lines changed

arch/alpha/mm/init.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,17 @@ callback_init(void * kernel_end)
243243
*/
244244
void __init paging_init(void)
245245
{
246-
unsigned long zones_size[MAX_NR_ZONES] = {0, };
247-
unsigned long dma_pfn, high_pfn;
246+
unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
247+
unsigned long dma_pfn;
248248

249249
dma_pfn = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
250-
high_pfn = max_pfn = max_low_pfn;
250+
max_pfn = max_low_pfn;
251251

252-
if (dma_pfn >= high_pfn)
253-
zones_size[ZONE_DMA] = high_pfn;
254-
else {
255-
zones_size[ZONE_DMA] = dma_pfn;
256-
zones_size[ZONE_NORMAL] = high_pfn - dma_pfn;
257-
}
252+
max_zone_pfn[ZONE_DMA] = dma_pfn;
253+
max_zone_pfn[ZONE_NORMAL] = max_pfn;
258254

259255
/* Initialize mem_map[]. */
260-
free_area_init(zones_size);
256+
free_area_init(max_zone_pfn);
261257

262258
/* Initialize the kernel's ZERO_PGE. */
263259
memset((void *)ZERO_PGE, 0, PAGE_SIZE);

arch/c6x/mm/init.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ EXPORT_SYMBOL(empty_zero_page);
3333
void __init paging_init(void)
3434
{
3535
struct pglist_data *pgdat = NODE_DATA(0);
36-
unsigned long zones_size[MAX_NR_ZONES] = {0, };
36+
unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
3737

3838
empty_zero_page = (unsigned long) memblock_alloc(PAGE_SIZE,
3939
PAGE_SIZE);
@@ -49,11 +49,9 @@ void __init paging_init(void)
4949
/*
5050
* Define zones
5151
*/
52-
zones_size[ZONE_NORMAL] = (memory_end - PAGE_OFFSET) >> PAGE_SHIFT;
53-
pgdat->node_zones[ZONE_NORMAL].zone_start_pfn =
54-
__pa(PAGE_OFFSET) >> PAGE_SHIFT;
52+
max_zone_pfn[ZONE_NORMAL] = memory_end >> PAGE_SHIFT;
5553

56-
free_area_init(zones_size);
54+
free_area_init(max_zone_pfn);
5755
}
5856

5957
void __init mem_init(void)

arch/h8300/mm/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ void __init paging_init(void)
8383
start_mem, end_mem);
8484

8585
{
86-
unsigned long zones_size[MAX_NR_ZONES] = {0, };
86+
unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
8787

88-
zones_size[ZONE_NORMAL] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
89-
free_area_init(zones_size);
88+
max_zone_pfn[ZONE_NORMAL] = end_mem >> PAGE_SHIFT;
89+
free_area_init(max_zone_pfn);
9090
}
9191
}
9292

arch/hexagon/mm/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void sync_icache_dcache(pte_t pte)
9191
*/
9292
void __init paging_init(void)
9393
{
94-
unsigned long zones_sizes[MAX_NR_ZONES] = {0, };
94+
unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
9595

9696
/*
9797
* This is not particularly well documented anywhere, but
@@ -101,9 +101,9 @@ void __init paging_init(void)
101101
* adjust accordingly.
102102
*/
103103

104-
zones_sizes[ZONE_NORMAL] = max_low_pfn;
104+
max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
105105

106-
free_area_init(zones_sizes); /* sets up the zonelists and mem_map */
106+
free_area_init(max_zone_pfn); /* sets up the zonelists and mem_map */
107107

108108
/*
109109
* Start of high memory area. Will probably need something more

arch/m68k/mm/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void __init paging_init(void)
8484
* page_alloc get different views of the world.
8585
*/
8686
unsigned long end_mem = memory_end & PAGE_MASK;
87-
unsigned long zones_size[MAX_NR_ZONES] = { 0, };
87+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, };
8888

8989
high_memory = (void *) end_mem;
9090

@@ -98,8 +98,8 @@ void __init paging_init(void)
9898
*/
9999
set_fs (USER_DS);
100100

101-
zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
102-
free_area_init(zones_size);
101+
max_zone_pfn[ZONE_DMA] = end_mem >> PAGE_SHIFT;
102+
free_area_init(max_zone_pfn);
103103
}
104104

105105
#endif /* CONFIG_MMU */

arch/m68k/mm/mcfmmu.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void __init paging_init(void)
3939
pte_t *pg_table;
4040
unsigned long address, size;
4141
unsigned long next_pgtable, bootmem_end;
42-
unsigned long zones_size[MAX_NR_ZONES];
42+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
4343
enum zone_type zone;
4444
int i;
4545

@@ -80,11 +80,8 @@ void __init paging_init(void)
8080
}
8181

8282
current->mm = NULL;
83-
84-
for (zone = 0; zone < MAX_NR_ZONES; zone++)
85-
zones_size[zone] = 0x0;
86-
zones_size[ZONE_DMA] = num_pages;
87-
free_area_init(zones_size);
83+
max_zone_pfn[ZONE_DMA] = PFN_DOWN(_ramend);
84+
free_area_init(max_zone_pfn);
8885
}
8986

9087
int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word)

arch/nds32/mm/init.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@ EXPORT_SYMBOL(empty_zero_page);
3131

3232
static void __init zone_sizes_init(void)
3333
{
34-
unsigned long zones_size[MAX_NR_ZONES];
34+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
3535

36-
/* Clear the zone sizes */
37-
memset(zones_size, 0, sizeof(zones_size));
38-
39-
zones_size[ZONE_NORMAL] = max_low_pfn;
36+
max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
4037
#ifdef CONFIG_HIGHMEM
41-
zones_size[ZONE_HIGHMEM] = max_pfn;
38+
max_zone_pfn[ZONE_HIGHMEM] = max_pfn;
4239
#endif
43-
free_area_init(zones_size);
40+
free_area_init(max_zone_pfn);
4441

4542
}
4643

arch/nios2/mm/init.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ pgd_t *pgd_current;
4646
*/
4747
void __init paging_init(void)
4848
{
49-
unsigned long zones_size[MAX_NR_ZONES];
50-
51-
memset(zones_size, 0, sizeof(zones_size));
49+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
5250

5351
pagetable_init();
5452
pgd_current = swapper_pg_dir;
5553

56-
zones_size[ZONE_NORMAL] = max_mapnr;
54+
max_zone_pfn[ZONE_NORMAL] = max_mapnr;
5755

5856
/* pass the memory from the bootmem allocator to the main allocator */
59-
free_area_init(zones_size);
57+
free_area_init(max_zone_pfn);
6058

6159
flush_dcache_range((unsigned long)empty_zero_page,
6260
(unsigned long)empty_zero_page + PAGE_SIZE);

arch/openrisc/mm/init.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,14 @@ DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
4545

4646
static void __init zone_sizes_init(void)
4747
{
48-
unsigned long zones_size[MAX_NR_ZONES];
49-
50-
/* Clear the zone sizes */
51-
memset(zones_size, 0, sizeof(zones_size));
48+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
5249

5350
/*
5451
* We use only ZONE_NORMAL
5552
*/
56-
zones_size[ZONE_NORMAL] = max_low_pfn;
53+
max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
5754

58-
free_area_init(zones_size);
55+
free_area_init(max_zone_pfn);
5956
}
6057

6158
extern const char _s_kernel_ro[], _e_kernel_ro[];

arch/um/kernel/mem.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,17 @@ static void __init fixaddr_user_init( void)
158158

159159
void __init paging_init(void)
160160
{
161-
unsigned long zones_size[MAX_NR_ZONES], vaddr;
162-
int i;
161+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
162+
unsigned long vaddr;
163163

164164
empty_zero_page = (unsigned long *) memblock_alloc_low(PAGE_SIZE,
165165
PAGE_SIZE);
166166
if (!empty_zero_page)
167167
panic("%s: Failed to allocate %lu bytes align=%lx\n",
168168
__func__, PAGE_SIZE, PAGE_SIZE);
169169

170-
for (i = 0; i < ARRAY_SIZE(zones_size); i++)
171-
zones_size[i] = 0;
172-
173-
zones_size[ZONE_NORMAL] = (end_iomem >> PAGE_SHIFT) -
174-
(uml_physmem >> PAGE_SHIFT);
175-
free_area_init(zones_size);
170+
max_zone_pfn[ZONE_NORMAL] = end_iomem >> PAGE_SHIFT;
171+
free_area_init(max_zone_pfn);
176172

177173
/*
178174
* Fixed mappings, only the page table structure has to be

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@ static inline spinlock_t *pud_lock(struct mm_struct *mm, pud_t *pud)
23292329
}
23302330

23312331
extern void __init pagecache_init(void);
2332-
extern void free_area_init(unsigned long * zones_size);
2332+
extern void free_area_init(unsigned long * max_zone_pfn);
23332333
extern void __init free_area_init_node(int nid, unsigned long * zones_size,
23342334
unsigned long zone_start_pfn, unsigned long *zholes_size);
23352335
extern void free_initmem(void);

mm/page_alloc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7712,11 +7712,10 @@ void __init set_dma_reserve(unsigned long new_dma_reserve)
77127712
dma_reserve = new_dma_reserve;
77137713
}
77147714

7715-
void __init free_area_init(unsigned long *zones_size)
7715+
void __init free_area_init(unsigned long *max_zone_pfn)
77167716
{
77177717
init_unavailable_mem();
7718-
free_area_init_node(0, zones_size,
7719-
__pa(PAGE_OFFSET) >> PAGE_SHIFT, NULL);
7718+
free_area_init_nodes(max_zone_pfn);
77207719
}
77217720

77227721
static int page_alloc_cpu_dead(unsigned int cpu)

0 commit comments

Comments
 (0)