# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1485  -> 1.1486 
#	     mm/page_alloc.c	1.174   -> 1.175  
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/11/24	jbarnes@tomahawk.engr.sgi.com	1.1486
# fix nr_free_pages to not be such a bottleneck
# --------------------------------------------
#
diff -Nru a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c	Mon Nov 24 14:27:43 2003
+++ b/mm/page_alloc.c	Mon Nov 24 14:27:43 2003
@@ -752,11 +752,23 @@
  */
 unsigned int nr_free_pages(void)
 {
-	unsigned int sum = 0;
+	static unsigned long jiffies_last_compute = 0;
+	static unsigned int  free_pages_last_compute = 0;
+	pg_data_t *pgdat;
+	unsigned int sum, n;
 	struct zone *zone;
 
-	for_each_zone(zone)
-		sum += zone->free_pages;
+#define RECALC_TICKS	10
+
+	if (jiffies < jiffies_last_compute)
+		return free_pages_last_compute;
+
+	jiffies_last_compute = jiffies + RECALC_TICKS;
+	sum = 0;
+	for_each_pgdat(pgdat)
+		for (zone=pgdat->node_zones,n=0; n<pgdat->nr_zones; n++, zone++)
+			sum += zone->free_pages;
+	free_pages_last_compute = sum;
 
 	return sum;
 }
