mm/memory hotplug: init the zone's size when calculating node totalpages

Init the zone's size when calculating node totalpages to avoid duplicated
operations in free_area_init_core().

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Gu Zheng 2015-06-24 16:57:02 -07:00 committed by Linus Torvalds
parent 641844f561
commit febd5949e1

View File

@ -4756,22 +4756,28 @@ static void __meminit calculate_node_totalpages(struct pglist_data *pgdat,
unsigned long *zones_size, unsigned long *zones_size,
unsigned long *zholes_size) unsigned long *zholes_size)
{ {
unsigned long realtotalpages, totalpages = 0; unsigned long realtotalpages = 0, totalpages = 0;
enum zone_type i; enum zone_type i;
for (i = 0; i < MAX_NR_ZONES; i++) for (i = 0; i < MAX_NR_ZONES; i++) {
totalpages += zone_spanned_pages_in_node(pgdat->node_id, i, struct zone *zone = pgdat->node_zones + i;
node_start_pfn, unsigned long size, real_size;
node_end_pfn,
zones_size);
pgdat->node_spanned_pages = totalpages;
realtotalpages = totalpages; size = zone_spanned_pages_in_node(pgdat->node_id, i,
for (i = 0; i < MAX_NR_ZONES; i++) node_start_pfn,
realtotalpages -= node_end_pfn,
zone_absent_pages_in_node(pgdat->node_id, i, zones_size);
real_size = size - zone_absent_pages_in_node(pgdat->node_id, i,
node_start_pfn, node_end_pfn, node_start_pfn, node_end_pfn,
zholes_size); zholes_size);
zone->spanned_pages = size;
zone->present_pages = real_size;
totalpages += size;
realtotalpages += real_size;
}
pgdat->node_spanned_pages = totalpages;
pgdat->node_present_pages = realtotalpages; pgdat->node_present_pages = realtotalpages;
printk(KERN_DEBUG "On node %d totalpages: %lu\n", pgdat->node_id, printk(KERN_DEBUG "On node %d totalpages: %lu\n", pgdat->node_id,
realtotalpages); realtotalpages);
@ -4881,8 +4887,7 @@ static unsigned long __paginginit calc_memmap_size(unsigned long spanned_pages,
* NOTE: pgdat should get zeroed by caller. * NOTE: pgdat should get zeroed by caller.
*/ */
static void __paginginit free_area_init_core(struct pglist_data *pgdat, static void __paginginit free_area_init_core(struct pglist_data *pgdat,
unsigned long node_start_pfn, unsigned long node_end_pfn, unsigned long node_start_pfn, unsigned long node_end_pfn)
unsigned long *zones_size, unsigned long *zholes_size)
{ {
enum zone_type j; enum zone_type j;
int nid = pgdat->node_id; int nid = pgdat->node_id;
@ -4903,12 +4908,8 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat,
struct zone *zone = pgdat->node_zones + j; struct zone *zone = pgdat->node_zones + j;
unsigned long size, realsize, freesize, memmap_pages; unsigned long size, realsize, freesize, memmap_pages;
size = zone_spanned_pages_in_node(nid, j, node_start_pfn, size = zone->spanned_pages;
node_end_pfn, zones_size); realsize = freesize = zone->present_pages;
realsize = freesize = size - zone_absent_pages_in_node(nid, j,
node_start_pfn,
node_end_pfn,
zholes_size);
/* /*
* Adjust freesize so that it accounts for how much memory * Adjust freesize so that it accounts for how much memory
@ -4943,8 +4944,6 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat,
nr_kernel_pages -= memmap_pages; nr_kernel_pages -= memmap_pages;
nr_all_pages += freesize; nr_all_pages += freesize;
zone->spanned_pages = size;
zone->present_pages = realsize;
/* /*
* Set an approximate value for lowmem here, it will be adjusted * Set an approximate value for lowmem here, it will be adjusted
* when the bootmem allocator frees pages into the buddy system. * when the bootmem allocator frees pages into the buddy system.
@ -5050,8 +5049,7 @@ void __paginginit free_area_init_node(int nid, unsigned long *zones_size,
(unsigned long)pgdat->node_mem_map); (unsigned long)pgdat->node_mem_map);
#endif #endif
free_area_init_core(pgdat, start_pfn, end_pfn, free_area_init_core(pgdat, start_pfn, end_pfn);
zones_size, zholes_size);
} }
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP