Index: linux-2.6.7-ck2pre/include/linux/swap.h =================================================================== --- linux-2.6.7-ck2pre.orig/include/linux/swap.h 2004-06-25 14:14:29.791787740 +1000 +++ linux-2.6.7-ck2pre/include/linux/swap.h 2004-06-25 14:15:06.940967032 +1000 @@ -175,7 +175,7 @@ extern int try_to_free_pages(struct zone **, unsigned int, unsigned int); extern int shrink_all_memory(int); extern int vm_swappiness; -extern int auto_swappiness; +extern int vm_autoregulate; #ifdef CONFIG_MMU /* linux/mm/shmem.c */ Index: linux-2.6.7-ck2pre/include/linux/sysctl.h =================================================================== --- linux-2.6.7-ck2pre.orig/include/linux/sysctl.h 2004-06-25 14:14:29.790787897 +1000 +++ linux-2.6.7-ck2pre/include/linux/sysctl.h 2004-06-25 14:15:06.941966875 +1000 @@ -166,7 +166,7 @@ VM_LAPTOP_MODE=23, /* vm laptop mode */ VM_BLOCK_DUMP=24, /* block dump mode */ VM_HUGETLB_GROUP=25, /* permitted hugetlb group */ - VM_AUTO_SWAPPINESS=26, /* Make vm_swappiness autoregulated */ + VM_AUTOREGULATE=26, /* swappiness and inactivation autoregulated */ }; Index: linux-2.6.7-ck2pre/kernel/sysctl.c =================================================================== --- linux-2.6.7-ck2pre.orig/kernel/sysctl.c 2004-06-25 14:14:29.789788053 +1000 +++ linux-2.6.7-ck2pre/kernel/sysctl.c 2004-06-25 14:15:06.943966562 +1000 @@ -744,9 +744,9 @@ .extra2 = &one_hundred, }, { - .ctl_name = VM_AUTO_SWAPPINESS, - .procname = "autoswappiness", - .data = &auto_swappiness, + .ctl_name = VM_AUTOREGULATE, + .procname = "autoregulate", + .data = &vm_autoregulate, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec, Index: linux-2.6.7-ck2pre/mm/vmscan.c =================================================================== --- linux-2.6.7-ck2pre.orig/mm/vmscan.c 2004-06-25 14:14:29.787788366 +1000 +++ linux-2.6.7-ck2pre/mm/vmscan.c 2004-06-25 18:42:18.672581046 +1000 @@ -43,7 +43,8 @@ * From 0 .. 100. Higher means more swappy. */ int vm_swappiness = 60; -int auto_swappiness = 1; +int vm_autoregulate = 1; +static int app_percent = 1; static long total_memory; #define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru)) @@ -649,7 +650,9 @@ long mapped_ratio; long distress; long swap_tendency; + struct sysinfo i; + si_meminfo(&i); lru_add_drain(); pgmoved = 0; spin_lock_irq(&zone->lru_lock); @@ -691,23 +694,21 @@ */ mapped_ratio = (sc->nr_mapped * 100) / total_memory; + /* + * app_percent is the percentage of physical ram used + * by application pages. + */ + si_meminfo(&i); + app_percent = 100 - ((i.freeram + get_page_cache_size() - + swapper_space.nrpages) / (i.totalram / 100)); + #ifdef CONFIG_SWAP - if (auto_swappiness) { - int app_percent; - struct sysinfo i; - + if (vm_autoregulate) { si_swapinfo(&i); if (likely(i.totalswap >= 100)) { int swap_centile; - /* - * app_percent is the percentage of physical ram used - * by application pages. - */ - si_meminfo(&i); - app_percent = 100 - ((i.freeram + get_page_cache_size() - - swapper_space.nrpages) / (i.totalram / 100)); /* * swap_centile is the percentage of the last (sizeof physical @@ -834,11 +835,16 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) { - unsigned long scan_active, scan_inactive; - int count; + unsigned long scan_active, scan_inactive, biased_active; + int count, biased_ap; scan_inactive = (zone->nr_active + zone->nr_inactive) >> sc->priority; + if (vm_autoregulate) { + biased_ap = app_percent * app_percent / 100; + biased_active = zone->nr_active / (101 - biased_ap) * 100; + } else + biased_active = zone->nr_active; /* * Try to keep the active list 2/3 of the size of the cache. And * make sure that refill_inactive is given a decent number of pages. @@ -849,7 +855,7 @@ * `scan_active' just to make sure that the kernel will slowly sift * through the active list. */ - if (zone->nr_active >= 4*(zone->nr_inactive*2 + 1)) { + if (biased_active >= 4*(zone->nr_inactive*2 + 1)) { /* Don't scan more than 4 times the inactive list scan size */ scan_active = 4*scan_inactive; } else { @@ -857,7 +863,7 @@ /* Cast to long long so the multiply doesn't overflow */ - tmp = (unsigned long long)scan_inactive * zone->nr_active; + tmp = (unsigned long long)scan_inactive * biased_active; do_div(tmp, zone->nr_inactive*2 + 1); scan_active = (unsigned long)tmp; }