All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [ck] 2.6.7 backport request, spinoff idea
       [not found]     ` <200412190321.16567.mr@ramendik.ru>
@ 2004-12-19  0:42       ` Con Kolivas
  2004-12-19  1:29         ` Con Kolivas
  0 siblings, 1 reply; 3+ messages in thread
From: Con Kolivas @ 2004-12-19  0:42 UTC (permalink / raw)
  To: Mikhail Ramendik; +Cc: ck, Rik van Riel, Andrew Morton, linux

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

Mikhail Ramendik wrote:
> Con Kolivas wrote:
> 
> 
>>Actually I wonder if the swap token is responsible in 2.6.10-rc3
>>
>>Try this
>>echo 0 > /proc/sys/vm/swap_token_timeout
> 
> 
> Well, this makes things really better, although not as good as 2.6.8.1. There 
> are kswapd cpu jumps and screen freezes, but they only last several seconds 
> (the longest is in the very beginning, about 15-20 sec).
> 
> Thanks! This makes the system much more useable.

This is worth posting to lkml so I've cc'ed a few relevant people (there 
is already a thread about this there). Rik care to comment? I recall 
pointing out this test case a while back. Got any way to make it harder 
to trigger the swap token? It seems to affect normal workloads adversely 
considering how rare swap thrashing actually occurs.

Con

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ck] 2.6.7 backport request, spinoff idea
  2004-12-19  0:42       ` [ck] 2.6.7 backport request, spinoff idea Con Kolivas
@ 2004-12-19  1:29         ` Con Kolivas
  2004-12-19  4:26           ` Rik van Riel
  0 siblings, 1 reply; 3+ messages in thread
From: Con Kolivas @ 2004-12-19  1:29 UTC (permalink / raw)
  To: Con Kolivas; +Cc: Mikhail Ramendik, ck, riel, Andrew Morton, linux

[-- Attachment #1: Type: text/plain, Size: 1055 bytes --]

Con Kolivas wrote:
> Mikhail Ramendik wrote:
> 
>> Con Kolivas wrote:
>>
>>
>>> Actually I wonder if the swap token is responsible in 2.6.10-rc3
>>>
>>> Try this
>>> echo 0 > /proc/sys/vm/swap_token_timeout
>>
>>
>>
>> Well, this makes things really better, although not as good as 
>> 2.6.8.1. There are kswapd cpu jumps and screen freezes, but they only 
>> last several seconds (the longest is in the very beginning, about 
>> 15-20 sec).
>>
>> Thanks! This makes the system much more useable.
> 
> 
> This is worth posting to lkml so I've cc'ed a few relevant people (there 
> is already a thread about this there). Rik care to comment? I recall 
> pointing out this test case a while back. Got any way to make it harder 
> to trigger the swap token? It seems to affect normal workloads adversely 
> considering how rare swap thrashing actually occurs.

Rik tells me he has already posted a patch for this problem :D

Sorry for cc'ing the wrong email Rik. Do you have a simple link to the 
patch or can you send it on this thread please?

Cheers,
Con

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ck] 2.6.7 backport request, spinoff idea
  2004-12-19  1:29         ` Con Kolivas
@ 2004-12-19  4:26           ` Rik van Riel
  0 siblings, 0 replies; 3+ messages in thread
From: Rik van Riel @ 2004-12-19  4:26 UTC (permalink / raw)
  To: Con Kolivas; +Cc: Mikhail Ramendik, ck, Andrew Morton, linux

On Sun, 19 Dec 2004, Con Kolivas wrote:

> Sorry for cc'ing the wrong email Rik. Do you have a simple link to the 
> patch or can you send it on this thread please?

Here it is.  The patch should have the effect of reducing the
swap token timeout to the minimum value at times when there is
little to no memory pressure, while allowing it to grow in times
where it is needed.


Date: Sat, 11 Dec 2004 14:24:15 -0500 (EST)
From: Rik van Riel <riel@redhat.com>
To: Marcelo Tosatti <marcelo.tosatti@cyclades.com>
Cc: linux-mm@kvack.org
Subject: PATCH: automatic tuning of swap token timeout

At Marcelo's request.  I made this patch a while ago so I'm
not sure if it will still apply to the recent kernel, but it
should give you an idea of what I tried to achieve.

The idea is to keep the swap token timeout short on a system
with mostly small tasks, even if there is one big hog running
in the background.  The big thrashing program should not hold
the swap token for unfair amounts of time.

The swap token timeout should be the minimum required to keep
most of the processes in the system from thrashing, while
keeping some amount of fairness.

This patch is untested.  Have fun.

===== mm/thrash.c 1.2 vs edited =====
--- 1.2/mm/thrash.c	Wed Oct 20 04:37:11 2004
+++ edited/mm/thrash.c	Mon Nov  1 22:35:01 2004
@@ -19,10 +19,44 @@
   struct mm_struct * swap_token_mm = &init_mm;

   #define SWAP_TOKEN_CHECK_INTERVAL (HZ * 2)
-#define SWAP_TOKEN_TIMEOUT (HZ * 300)
+#define MIN_SWAP_TOKEN_TIMEOUT (2 * SWAP_TOKEN_CHECK_INTERVAL)
+#define SWAP_TOKEN_TIMEOUT (HZ * 30)
+#define MAX_SWAP_TOKEN_TIMEOUT (HZ * 300)
   unsigned long swap_token_default_timeout = SWAP_TOKEN_TIMEOUT;

   /*
+ * We count how often the swap token times out, and how often the
+ * swap token hold time is long enough for processes to regain their
+ * working set and make progress.
+ *
+ * The goal is to have processes in the system make progress, with the
+ * lowest possible latency.  If the token times out too often, processes
+ * are not making progress and the timeout needs to be increased.  If
+ * processes are making progress, we can decrease the timeout and improve
+ * system latency.
+ */
+#define SWAP_TOKEN_RECALC 32
+#define SWAP_TOKEN_TOO_LONG 1
+static int swap_token_timed_out;
+static int swap_token_enough_rss;
+
+static void recalculate_swap_token_timeout(void)
+{
+	unsigned long delta = (swap_token_default_timeout / 4) + 1;
+	if (swap_token_timed_out > SWAP_TOKEN_TOO_LONG) {
+		swap_token_default_timeout += delta;
+		if (swap_token_default_timeout > MAX_SWAP_TOKEN_TIMEOUT)
+			swap_token_default_timeout = MAX_SWAP_TOKEN_TIMEOUT;
+	} else {
+		swap_token_default_timeout -= delta;
+		if (swap_token_default_timeout < MIN_SWAP_TOKEN_TIMEOUT)
+			swap_token_default_timeout = MIN_SWAP_TOKEN_TIMEOUT;
+	}
+	swap_token_enough_rss /= 2;
+	swap_token_timed_out /= 2;
+}
+
+/*
    * Take the token away if the process had no page faults
    * in the last interval, or if it has held the token for
    * too long.
@@ -32,11 +66,18 @@
   static int should_release_swap_token(struct mm_struct *mm)
   {
   	int ret = 0;
-	if (!mm->recent_pagein)
+	if (!mm->recent_pagein) {
+		swap_token_enough_rss++;
   		ret = SWAP_TOKEN_ENOUGH_RSS;
-	else if (time_after(jiffies, swap_token_timeout))
+	} else if (time_after(jiffies, swap_token_timeout)) {
+		swap_token_timed_out++;
   		ret = SWAP_TOKEN_TIMED_OUT;
+	}
   	mm->recent_pagein = 0;
+
+	if (swap_token_timed_out + swap_token_enough_rss > SWAP_TOKEN_RECALC)
+		recalculate_swap_token_timeout();
+
   	return ret;
   }


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-12-19  4:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200412171504.41234.mr@ramendik.ru>
     [not found] ` <41C4A670.9090009@kolivas.org>
     [not found]   ` <41C4A899.10102@kolivas.org>
     [not found]     ` <200412190321.16567.mr@ramendik.ru>
2004-12-19  0:42       ` [ck] 2.6.7 backport request, spinoff idea Con Kolivas
2004-12-19  1:29         ` Con Kolivas
2004-12-19  4:26           ` Rik van Riel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.