[PATCH] Fix NUMA node sizing in nr_free_zone_pages

We are iterating over all nodes in nr_free_zone_pages(). Because the
fallback zonelists contain all nodes in the system, and we walk all the
zonelists, we're counting memory multiple times (once for each node). This
caused us to make a size estimate of 32GB for an 8GB AMD64 box, which makes
all the dirty ratio calculations, etc incorrect.

There's still a further bug to fix from e820 holes causing overestimation
as well, but this fix is separate, and good as is, and fixes one class of
problems. Problem found by Badari, and tested by Ram Pai - thanks!

Signed-off-by: Martin J. Bligh <mbligh@mbligh.org>
Signed-off-by: Matt Dobson <colpatch@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Martin J. Bligh and committed by Linus Torvalds e310fd43 5fa918b4

+10 -11
+10 -11
mm/page_alloc.c
··· 1061 1061 1062 1062 static unsigned int nr_free_zone_pages(int offset) 1063 1063 { 1064 - pg_data_t *pgdat; 1064 + /* Just pick one node, since fallback list is circular */ 1065 + pg_data_t *pgdat = NODE_DATA(numa_node_id()); 1065 1066 unsigned int sum = 0; 1066 1067 1067 - for_each_pgdat(pgdat) { 1068 - struct zonelist *zonelist = pgdat->node_zonelists + offset; 1069 - struct zone **zonep = zonelist->zones; 1070 - struct zone *zone; 1068 + struct zonelist *zonelist = pgdat->node_zonelists + offset; 1069 + struct zone **zonep = zonelist->zones; 1070 + struct zone *zone; 1071 1071 1072 - for (zone = *zonep++; zone; zone = *zonep++) { 1073 - unsigned long size = zone->present_pages; 1074 - unsigned long high = zone->pages_high; 1075 - if (size > high) 1076 - sum += size - high; 1077 - } 1072 + for (zone = *zonep++; zone; zone = *zonep++) { 1073 + unsigned long size = zone->present_pages; 1074 + unsigned long high = zone->pages_high; 1075 + if (size > high) 1076 + sum += size - high; 1078 1077 } 1079 1078 1080 1079 return sum;