Skip to content

Commit 51930df

Browse files
rppttorvalds
authored andcommitted
mm: free_area_init: allow defining max_zone_pfn in descending order
Some architectures (e.g. ARC) have the ZONE_HIGHMEM zone below the ZONE_NORMAL. Allowing free_area_init() parse max_zone_pfn array even it is sorted in descending order allows using free_area_init() on such architectures. Add top -> down traversal of max_zone_pfn array in free_area_init() and use the latter in ARC node/zone initialization. [[email protected]: ARC fix] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: arc: free_area_init(): take into account PAE40 mode] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: declare arch_has_descending_max_zone_pfns()] 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]> Cc: Guenter Roeck <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent acd3f5c commit 51930df

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

arch/arc/mm/init.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,25 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)
6363

6464
low_mem_sz = size;
6565
in_use = 1;
66+
memblock_add_node(base, size, 0);
6667
} else {
6768
#ifdef CONFIG_HIGHMEM
6869
high_mem_start = base;
6970
high_mem_sz = size;
7071
in_use = 1;
72+
memblock_add_node(base, size, 1);
7173
#endif
7274
}
7375

7476
pr_info("Memory @ %llx [%lldM] %s\n",
7577
base, TO_MB(size), !in_use ? "Not used":"");
7678
}
7779

80+
bool arch_has_descending_max_zone_pfns(void)
81+
{
82+
return !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
83+
}
84+
7885
/*
7986
* First memory setup routine called from setup_arch()
8087
* 1. setup swapper's mm @init_mm
@@ -83,8 +90,7 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)
8390
*/
8491
void __init setup_arch_memory(void)
8592
{
86-
unsigned long zones_size[MAX_NR_ZONES];
87-
unsigned long zones_holes[MAX_NR_ZONES];
93+
unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
8894

8995
init_mm.start_code = (unsigned long)_text;
9096
init_mm.end_code = (unsigned long)_etext;
@@ -115,7 +121,6 @@ void __init setup_arch_memory(void)
115121
* the crash
116122
*/
117123

118-
memblock_add_node(low_mem_start, low_mem_sz, 0);
119124
memblock_reserve(CONFIG_LINUX_LINK_BASE,
120125
__pa(_end) - CONFIG_LINUX_LINK_BASE);
121126

@@ -133,22 +138,7 @@ void __init setup_arch_memory(void)
133138
memblock_dump_all();
134139

135140
/*----------------- node/zones setup --------------------------*/
136-
memset(zones_size, 0, sizeof(zones_size));
137-
memset(zones_holes, 0, sizeof(zones_holes));
138-
139-
zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
140-
zones_holes[ZONE_NORMAL] = 0;
141-
142-
/*
143-
* We can't use the helper free_area_init(zones[]) because it uses
144-
* PAGE_OFFSET to compute the @min_low_pfn which would be wrong
145-
* when our kernel doesn't start at PAGE_OFFSET, i.e.
146-
* PAGE_OFFSET != CONFIG_LINUX_RAM_BASE
147-
*/
148-
free_area_init_node(0, /* node-id */
149-
zones_size, /* num pages per zone */
150-
min_low_pfn, /* first pfn of node */
151-
zones_holes); /* holes */
141+
max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
152142

153143
#ifdef CONFIG_HIGHMEM
154144
/*
@@ -168,20 +158,13 @@ void __init setup_arch_memory(void)
168158
min_high_pfn = PFN_DOWN(high_mem_start);
169159
max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz);
170160

171-
zones_size[ZONE_NORMAL] = 0;
172-
zones_holes[ZONE_NORMAL] = 0;
173-
174-
zones_size[ZONE_HIGHMEM] = max_high_pfn - min_high_pfn;
175-
zones_holes[ZONE_HIGHMEM] = 0;
176-
177-
free_area_init_node(1, /* node-id */
178-
zones_size, /* num pages per zone */
179-
min_high_pfn, /* first pfn of node */
180-
zones_holes); /* holes */
161+
max_zone_pfn[ZONE_HIGHMEM] = max_high_pfn;
181162

182163
high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
183164
kmap_init();
184165
#endif
166+
167+
free_area_init(max_zone_pfn);
185168
}
186169

187170
/*

include/linux/mm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,7 @@ extern void setup_per_cpu_pageset(void);
24732473
extern int min_free_kbytes;
24742474
extern int watermark_boost_factor;
24752475
extern int watermark_scale_factor;
2476+
extern bool arch_has_descending_max_zone_pfns(void);
24762477

24772478
/* nommu.c */
24782479
extern atomic_long_t mmap_pages_allocated;

mm/page_alloc.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7408,6 +7408,15 @@ static void check_for_memory(pg_data_t *pgdat, int nid)
74087408
}
74097409
}
74107410

7411+
/*
7412+
* Some architecturs, e.g. ARC may have ZONE_HIGHMEM below ZONE_NORMAL. For
7413+
* such cases we allow max_zone_pfn sorted in the descending order
7414+
*/
7415+
bool __weak arch_has_descending_max_zone_pfns(void)
7416+
{
7417+
return false;
7418+
}
7419+
74117420
/**
74127421
* free_area_init - Initialise all pg_data_t and zone data
74137422
* @max_zone_pfn: an array of max PFNs for each zone
@@ -7424,7 +7433,8 @@ static void check_for_memory(pg_data_t *pgdat, int nid)
74247433
void __init free_area_init(unsigned long *max_zone_pfn)
74257434
{
74267435
unsigned long start_pfn, end_pfn;
7427-
int i, nid;
7436+
int i, nid, zone;
7437+
bool descending;
74287438

74297439
/* Record where the zone boundaries are */
74307440
memset(arch_zone_lowest_possible_pfn, 0,
@@ -7433,14 +7443,20 @@ void __init free_area_init(unsigned long *max_zone_pfn)
74337443
sizeof(arch_zone_highest_possible_pfn));
74347444

74357445
start_pfn = find_min_pfn_with_active_regions();
7446+
descending = arch_has_descending_max_zone_pfns();
74367447

74377448
for (i = 0; i < MAX_NR_ZONES; i++) {
7438-
if (i == ZONE_MOVABLE)
7449+
if (descending)
7450+
zone = MAX_NR_ZONES - i - 1;
7451+
else
7452+
zone = i;
7453+
7454+
if (zone == ZONE_MOVABLE)
74397455
continue;
74407456

7441-
end_pfn = max(max_zone_pfn[i], start_pfn);
7442-
arch_zone_lowest_possible_pfn[i] = start_pfn;
7443-
arch_zone_highest_possible_pfn[i] = end_pfn;
7457+
end_pfn = max(max_zone_pfn[zone], start_pfn);
7458+
arch_zone_lowest_possible_pfn[zone] = start_pfn;
7459+
arch_zone_highest_possible_pfn[zone] = end_pfn;
74447460

74457461
start_pfn = end_pfn;
74467462
}

0 commit comments

Comments
 (0)