Re: [PATCH] Autoregulate vm swappiness cleanup

From: Nick Piggin
Date: Sun Oct 26 2003 - 05:24:47 EST




Con Kolivas wrote:

On Fri, 24 Oct 2003 01:03, Con Kolivas wrote:

On Friday 24 October 2003 00:42, Martin J. Bligh wrote:

It seems that you don't need si_swapinfo here, do you? i.freeram,
i.bufferram, and i.totalram all come from meminfo, as far as I can
see? Maybe I'm missing a bit ...

Well I did do it a while ago and it seems I got carried away adding and
subtracting info indeed. :-) Here's a simpler patch that does the same
thing.


The off-list enthusiasm has been rather strong so here is a patch done the right way (tm). There is no need for the check of totalram being zero (the original version of this patch modified the swappiness every tick which was wasteful and had a divide by zero on init). Adjusting vm_swappiness only when there is pressure to swap means totalram shouldn't be ever be zero. The sysctl is made read only since writing to it would be ignored now.

Con



------------------------------------------------------------------------

--- linux-2.6.0-test8-base/kernel/sysctl.c 2003-10-19 20:24:49.000000000 +1000
+++ linux-2.6.0-test8-am/kernel/sysctl.c 2003-10-25 16:37:44.384824976 +1000
@@ -664,11 +664,8 @@ static ctl_table vm_table[] = {
.procname = "swappiness",
.data = &vm_swappiness,
.maxlen = sizeof(vm_swappiness),
- .mode = 0644,
- .proc_handler = &proc_dointvec_minmax,
- .strategy = &sysctl_intvec,
- .extra1 = &zero,
- .extra2 = &one_hundred,
+ .mode = 0444 /* read-only*/,
+ .proc_handler = &proc_dointvec,
},
#ifdef CONFIG_HUGETLB_PAGE
{
--- linux-2.6.0-test8-base/mm/vmscan.c 2003-10-19 20:24:36.000000000 +1000
+++ linux-2.6.0-test8-am/mm/vmscan.c 2003-10-25 16:40:33.099176496 +1000
@@ -47,7 +47,7 @@
/*
* From 0 .. 100. Higher means more swappy.
*/
-int vm_swappiness = 60;
+int vm_swappiness = 0;
static long total_memory;

#ifdef ARCH_HAS_PREFETCH
@@ -600,6 +600,7 @@ refill_inactive_zone(struct zone *zone, LIST_HEAD(l_active); /* Pages to go onto the active_list */
struct page *page;
struct pagevec pvec;
+ struct sysinfo i;
int reclaim_mapped = 0;
long mapped_ratio;
long distress;
@@ -642,6 +643,14 @@ refill_inactive_zone(struct zone *zone, mapped_ratio = (ps->nr_mapped * 100) / total_memory;

/*
+ * Autoregulate vm_swappiness to be equal to the percentage of
+ * pages in physical ram that are application pages. -ck
+ */
+ si_meminfo(&i);
+ vm_swappiness = 100 - (((i.freeram + get_page_cache_size() -
+ swapper_space.nrpages) * 100) / i.totalram);
+
+ /*
* Now decide how much we really want to unmap some pages. The mapped
* ratio is downgraded - just because there's a lot of mapped memory
* doesn't necessarily mean that page reclaim isn't succeeding.


Hi Con,
If this indeed makes VM behaviour better, why not just merge the calculation
with the swap_tendancy calculation and leave vm_swappiness there as a tunable?


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/