From: Andrew Morton Initialise total_memory earlier in boot. Because if for some reason we run page reclaim early in boot, we don't want total_memory to be zero when we use it as a divisor. And rename total_memory to vm_total_pages to avoid naming clashes with architectures. Cc: Yasunori Goto Cc: KAMEZAWA Hiroyuki Cc: Martin Bligh Signed-off-by: Andrew Morton --- include/linux/swap.h | 1 + mm/page_alloc.c | 6 +++--- mm/vmscan.c | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff -puN include/linux/swap.h~initialise-total_memory-earlier include/linux/swap.h --- devel/include/linux/swap.h~initialise-total_memory-earlier 2006-06-09 15:17:43.000000000 -0700 +++ devel-akpm/include/linux/swap.h 2006-06-09 15:17:43.000000000 -0700 @@ -185,6 +185,7 @@ extern unsigned long try_to_free_pages(s extern unsigned long shrink_all_memory(unsigned long nr_pages); extern int vm_swappiness; extern int remove_mapping(struct address_space *mapping, struct page *page); +extern long vm_total_pages; #ifdef CONFIG_NUMA extern int zone_reclaim_mode; diff -puN mm/page_alloc.c~initialise-total_memory-earlier mm/page_alloc.c --- devel/mm/page_alloc.c~initialise-total_memory-earlier 2006-06-09 15:17:43.000000000 -0700 +++ devel-akpm/mm/page_alloc.c 2006-06-09 15:17:43.000000000 -0700 @@ -1725,9 +1725,9 @@ void __meminit build_all_zonelists(void) stop_machine_run(__build_all_zonelists, NULL, NR_CPUS); /* cpuset refresh routine should be here */ } - - printk("Built %i zonelists\n", num_online_nodes()); - + vm_total_pages = nr_free_pagecache_pages(); + printk("Built %i zonelists. Total pages: %ld\n", + num_online_nodes(), vm_total_pages); } /* diff -puN mm/vmscan.c~initialise-total_memory-earlier mm/vmscan.c --- devel/mm/vmscan.c~initialise-total_memory-earlier 2006-06-09 15:17:43.000000000 -0700 +++ devel-akpm/mm/vmscan.c 2006-06-09 15:17:43.000000000 -0700 @@ -111,7 +111,7 @@ struct shrinker { * From 0 .. 100. Higher means more swappy. */ int vm_swappiness = 60; -static long total_memory; +long vm_total_pages; /* The total number of pages which the VM controls */ static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); @@ -744,7 +744,7 @@ static void shrink_active_list(unsigned * how much memory * is mapped. */ - mapped_ratio = (sc->nr_mapped * 100) / total_memory; + mapped_ratio = (sc->nr_mapped * 100) / vm_total_pages; /* * Now decide how much we really want to unmap some pages. The @@ -1499,7 +1499,6 @@ static int __init kswapd_init(void) for_each_online_node(nid) kswapd_run(nid); - total_memory = nr_free_pagecache_pages(); hotcpu_notifier(cpu_callback, 0); return 0; } _