From: Andy Whitcroft The FLATMEM memory model assumes that memory is in one contigious area based at pfn 0. If we initialise node 0 to start at any other offset we will incorrectly map pfn's to the wrong struct page *. The key to the memory model is the contigious nature of the memory not the location of it. Relax the requirement for the area to start at 0. Signed-off-by: Andy Whitcroft Acked-by: Mel Gorman Cc: Dave Hansen Signed-off-by: Andrew Morton --- mm/page_alloc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff -puN mm/page_alloc.c~flatmem-relax-requirement-for-memory-to-start-at-pfn-0 mm/page_alloc.c --- a/mm/page_alloc.c~flatmem-relax-requirement-for-memory-to-start-at-pfn-0 +++ a/mm/page_alloc.c @@ -2192,15 +2192,16 @@ static void __meminit free_area_init_cor static void __init alloc_node_mem_map(struct pglist_data *pgdat) { +#ifdef CONFIG_FLAT_NODE_MEM_MAP + struct page *map = pgdat->node_mem_map; + /* Skip empty nodes */ if (!pgdat->node_spanned_pages) return; -#ifdef CONFIG_FLAT_NODE_MEM_MAP /* ia64 gets its own node_mem_map, before this, without bootmem */ - if (!pgdat->node_mem_map) { + if (!map) { unsigned long size, start, end; - struct page *map; /* * The zone's endpoints aren't required to be MAX_ORDER @@ -2215,13 +2216,21 @@ static void __init alloc_node_mem_map(st if (!map) map = alloc_bootmem_node(pgdat, size); pgdat->node_mem_map = map + (pgdat->node_start_pfn - start); + + /* + * With FLATMEM the global mem_map is used. This is assumed + * to be based at pfn 0 such that 'pfn = page* - mem_map' + * is true. Adjust map relative to node_mem_map to + * maintain this relationship. + */ + map -= pgdat->node_start_pfn; } #ifdef CONFIG_FLATMEM /* * With no DISCONTIG, the global mem_map is just set as node 0's */ if (pgdat == NODE_DATA(0)) - mem_map = NODE_DATA(0)->node_mem_map; + mem_map = map; #endif #endif /* CONFIG_FLAT_NODE_MEM_MAP */ } _