Skip to content

Commit f59f1ca

Browse files
Daniel Vacektorvalds
authored andcommitted
Revert "mm: page_alloc: skip over regions of invalid pfns where possible"
This reverts commit b92df1d ("mm: page_alloc: skip over regions of invalid pfns where possible"). The commit is meant to be a boot init speed up skipping the loop in memmap_init_zone() for invalid pfns. But given some specific memory mapping on x86_64 (or more generally theoretically anywhere but on arm with CONFIG_HAVE_ARCH_PFN_VALID) the implementation also skips valid pfns which is plain wrong and causes 'kernel BUG at mm/page_alloc.c:1389!' crash> log | grep -e BUG -e RIP -e Call.Trace -e move_freepages_block -e rmqueue -e freelist -A1 kernel BUG at mm/page_alloc.c:1389! invalid opcode: 0000 [#1] SMP -- RIP: 0010: move_freepages+0x15e/0x160 -- Call Trace: move_freepages_block+0x73/0x80 __rmqueue+0x263/0x460 get_page_from_freelist+0x7e1/0x9e0 __alloc_pages_nodemask+0x176/0x420 -- crash> page_init_bug -v | grep RAM <struct resource 0xffff88067fffd2f8> 1000 - 9bfff System RAM (620.00 KiB) <struct resource 0xffff88067fffd3a0> 100000 - 430bffff System RAM ( 1.05 GiB = 1071.75 MiB = 1097472.00 KiB) <struct resource 0xffff88067fffd410> 4b0c8000 - 4bf9cfff System RAM ( 14.83 MiB = 15188.00 KiB) <struct resource 0xffff88067fffd480> 4bfac000 - 646b1fff System RAM (391.02 MiB = 400408.00 KiB) <struct resource 0xffff88067fffd560> 7b788000 - 7b7fffff System RAM (480.00 KiB) <struct resource 0xffff88067fffd640> 100000000 - 67fffffff System RAM ( 22.00 GiB) crash> page_init_bug | head -6 <struct resource 0xffff88067fffd560> 7b788000 - 7b7fffff System RAM (480.00 KiB) <struct page 0xffffea0001ede200> 1fffff00000000 0 <struct pglist_data 0xffff88047ffd9000> 1 <struct zone 0xffff88047ffd9800> DMA32 4096 1048575 <struct page 0xffffea0001ede200> 505736 505344 <struct page 0xffffea0001ed8000> 505855 <struct page 0xffffea0001edffc0> <struct page 0xffffea0001ed8000> 0 0 <struct pglist_data 0xffff88047ffd9000> 0 <struct zone 0xffff88047ffd9000> DMA 1 4095 <struct page 0xffffea0001edffc0> 1fffff00000400 0 <struct pglist_data 0xffff88047ffd9000> 1 <struct zone 0xffff88047ffd9800> DMA32 4096 1048575 BUG, zones differ! crash> kmem -p 77fff000 78000000 7b5ff000 7b600000 7b787000 7b788000 PAGE PHYSICAL MAPPING INDEX CNT FLAGS ffffea0001e00000 78000000 0 0 0 0 ffffea0001ed7fc0 7b5ff000 0 0 0 0 ffffea0001ed8000 7b600000 0 0 0 0 <<<< ffffea0001ede1c0 7b787000 0 0 0 0 ffffea0001ede200 7b788000 0 0 1 1fffff00000000 Link: http://lkml.kernel.org/r/[email protected] Fixes: b92df1d ("mm: page_alloc: skip over regions of invalid pfns where possible") Signed-off-by: Daniel Vacek <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Acked-by: Michal Hocko <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Paul Burton <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b3cd54b commit f59f1ca

File tree

3 files changed

+1
-39
lines changed

3 files changed

+1
-39
lines changed

include/linux/memblock.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
187187
unsigned long *end_pfn);
188188
void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
189189
unsigned long *out_end_pfn, int *out_nid);
190-
unsigned long memblock_next_valid_pfn(unsigned long pfn, unsigned long max_pfn);
191190

192191
/**
193192
* for_each_mem_pfn_range - early memory pfn range iterator

mm/memblock.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,34 +1101,6 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid,
11011101
*out_nid = r->nid;
11021102
}
11031103

1104-
unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn,
1105-
unsigned long max_pfn)
1106-
{
1107-
struct memblock_type *type = &memblock.memory;
1108-
unsigned int right = type->cnt;
1109-
unsigned int mid, left = 0;
1110-
phys_addr_t addr = PFN_PHYS(++pfn);
1111-
1112-
do {
1113-
mid = (right + left) / 2;
1114-
1115-
if (addr < type->regions[mid].base)
1116-
right = mid;
1117-
else if (addr >= (type->regions[mid].base +
1118-
type->regions[mid].size))
1119-
left = mid + 1;
1120-
else {
1121-
/* addr is within the region, so pfn is valid */
1122-
return pfn;
1123-
}
1124-
} while (left < right);
1125-
1126-
if (right == type->cnt)
1127-
return -1UL;
1128-
else
1129-
return PHYS_PFN(type->regions[right].base);
1130-
}
1131-
11321104
/**
11331105
* memblock_set_node - set node ID on memblock regions
11341106
* @base: base of area to set node ID for

mm/page_alloc.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5356,17 +5356,8 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
53565356
if (context != MEMMAP_EARLY)
53575357
goto not_early;
53585358

5359-
if (!early_pfn_valid(pfn)) {
5360-
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
5361-
/*
5362-
* Skip to the pfn preceding the next valid one (or
5363-
* end_pfn), such that we hit a valid pfn (or end_pfn)
5364-
* on our next iteration of the loop.
5365-
*/
5366-
pfn = memblock_next_valid_pfn(pfn, end_pfn) - 1;
5367-
#endif
5359+
if (!early_pfn_valid(pfn))
53685360
continue;
5369-
}
53705361
if (!early_pfn_in_nid(pfn, nid))
53715362
continue;
53725363
if (!update_defer_init(pgdat, pfn, end_pfn, &nr_initialised))

0 commit comments

Comments
 (0)