Skip to content

Commit 73a6e47

Browse files
Baoquan Hetorvalds
authored andcommitted
mm: memmap_init: iterate over memblock regions rather that check each PFN
When called during boot the memmap_init_zone() function checks if each PFN is valid and actually belongs to the node being initialized using early_pfn_valid() and early_pfn_in_nid(). Each such check may cost up to O(log(n)) where n is the number of memory banks, so for large amount of memory overall time spent in early_pfn*() becomes substantial. Since the information is anyway present in memblock, we can iterate over memblock memory regions in memmap_init() and only call memmap_init_zone() for PFN ranges that are know to be valid and in the appropriate node. [[email protected]: fix a compilation warning from Clang] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: fix the incorrect hole in fast_isolate_freepages()] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Baoquan He <[email protected]> Signed-off-by: Mike Rapoport <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Tested-by: Hoan Tran <[email protected]> [arm64] 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: Qian Cai <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent da50c57 commit 73a6e47

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

mm/compaction.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,9 @@ fast_isolate_freepages(struct compact_control *cc)
14091409
cc->free_pfn = highest;
14101410
} else {
14111411
if (cc->direct_compaction && pfn_valid(min_pfn)) {
1412-
page = pfn_to_page(min_pfn);
1412+
page = pageblock_pfn_to_page(min_pfn,
1413+
pageblock_end_pfn(min_pfn),
1414+
cc->zone);
14131415
cc->free_pfn = min_pfn;
14141416
}
14151417
}

mm/page_alloc.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5951,23 +5951,6 @@ overlap_memmap_init(unsigned long zone, unsigned long *pfn)
59515951
return false;
59525952
}
59535953

5954-
#ifdef CONFIG_SPARSEMEM
5955-
/* Skip PFNs that belong to non-present sections */
5956-
static inline __meminit unsigned long next_pfn(unsigned long pfn)
5957-
{
5958-
const unsigned long section_nr = pfn_to_section_nr(++pfn);
5959-
5960-
if (present_section_nr(section_nr))
5961-
return pfn;
5962-
return section_nr_to_pfn(next_present_section_nr(section_nr));
5963-
}
5964-
#else
5965-
static inline __meminit unsigned long next_pfn(unsigned long pfn)
5966-
{
5967-
return pfn++;
5968-
}
5969-
#endif
5970-
59715954
/*
59725955
* Initially all pages are reserved - free ones are freed
59735956
* up by memblock_free_all() once the early boot process is
@@ -6007,14 +5990,6 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
60075990
* function. They do not exist on hotplugged memory.
60085991
*/
60095992
if (context == MEMMAP_EARLY) {
6010-
if (!early_pfn_valid(pfn)) {
6011-
pfn = next_pfn(pfn);
6012-
continue;
6013-
}
6014-
if (!early_pfn_in_nid(pfn, nid)) {
6015-
pfn++;
6016-
continue;
6017-
}
60185993
if (overlap_memmap_init(zone, &pfn))
60195994
continue;
60205995
if (defer_init(nid, pfn, end_pfn))
@@ -6130,9 +6105,23 @@ static void __meminit zone_init_free_lists(struct zone *zone)
61306105
}
61316106

61326107
void __meminit __weak memmap_init(unsigned long size, int nid,
6133-
unsigned long zone, unsigned long start_pfn)
6108+
unsigned long zone,
6109+
unsigned long range_start_pfn)
61346110
{
6135-
memmap_init_zone(size, nid, zone, start_pfn, MEMMAP_EARLY, NULL);
6111+
unsigned long start_pfn, end_pfn;
6112+
unsigned long range_end_pfn = range_start_pfn + size;
6113+
int i;
6114+
6115+
for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) {
6116+
start_pfn = clamp(start_pfn, range_start_pfn, range_end_pfn);
6117+
end_pfn = clamp(end_pfn, range_start_pfn, range_end_pfn);
6118+
6119+
if (end_pfn > start_pfn) {
6120+
size = end_pfn - start_pfn;
6121+
memmap_init_zone(size, nid, zone, start_pfn,
6122+
MEMMAP_EARLY, NULL);
6123+
}
6124+
}
61366125
}
61376126

61386127
static int zone_batchsize(struct zone *zone)

0 commit comments

Comments
 (0)