linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Avoid excessive time spend on concurrent slab shrinking
@ 2006-03-31 22:44 Christoph Lameter
       [not found] ` <20060331150120.21fad488.akpm@osdl.org>
  2006-03-31 23:45 ` Andrew Morton
  0 siblings, 2 replies; 14+ messages in thread
From: Christoph Lameter @ 2006-03-31 22:44 UTC (permalink / raw)
  To: akpm, nickpiggin; +Cc: linux-mm

We experienced that concurrent slab shrinking on 2.6.16 can slow down a
system excessively due to lock contention. Slab shrinking is a global
operation so it does not make sense for multiple slab shrink operations
to be ongoing at the same time. The single shrinking task can perform the
shrinking for all nodes and processors in the system. Introduce an atomic
counter that works in the same was as in shrink_zone to limit concurrent
shrinking.

Also calculate the time it took to do the shrinking and wait at least twice
that time before doing it again. If we are spending excessive time 
on slab shrinking then we need to pause for some time to insure that the 
system is capable of archiving other tasks.

Signed-off-by: Christoph Lameter <clameter@sgi.com>

Index: linux-2.6.16/mm/vmscan.c
===================================================================
--- linux-2.6.16.orig/mm/vmscan.c	2006-03-19 21:53:29.000000000 -0800
+++ linux-2.6.16/mm/vmscan.c	2006-03-31 14:38:18.000000000 -0800
@@ -130,6 +130,8 @@ static long total_memory;
 
 static LIST_HEAD(shrinker_list);
 static DECLARE_RWSEM(shrinker_rwsem);
+static atomic_t active_shrinkers;
+static unsigned long next_slab_shrink;
 
 /*
  * Add a shrinker callback to be called from the vm
@@ -187,12 +189,18 @@ int shrink_slab(unsigned long scanned, g
 {
 	struct shrinker *shrinker;
 	int ret = 0;
+	unsigned long shrinkstart;
 
 	if (scanned == 0)
 		scanned = SWAP_CLUSTER_MAX;
 
-	if (!down_read_trylock(&shrinker_rwsem))
-		return 1;	/* Assume we'll be able to shrink next time */
+	if (atomic_read(&active_shrinkers) ||
+		time_before(jiffies, next_slab_shrink) ||
+		!down_read_trylock(&shrinker_rwsem))
+			/* Assume we'll be able to shrink next time */
+			return 1;
+	atomic_inc(&active_shrinkers);
+	shrinkstart = jiffies;
 
 	list_for_each_entry(shrinker, &shrinker_list, list) {
 		unsigned long long delta;
@@ -239,6 +247,12 @@ int shrink_slab(unsigned long scanned, g
 
 		shrinker->nr += total_scan;
 	}
+	/*
+	 * If slab shrinking took a long time then lets at least wait
+	 * twice as long as it took before we do it again.
+	 */
+	next_slab_shrink = jiffies + 2 * (jiffies - shrinkstart);
+	atomic_dec(&active_shrinkers);
 	up_read(&shrinker_rwsem);
 	return ret;
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2006-04-01 18:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-31 22:44 Avoid excessive time spend on concurrent slab shrinking Christoph Lameter
     [not found] ` <20060331150120.21fad488.akpm@osdl.org>
2006-03-31 23:17   ` Christoph Lameter
2006-03-31 23:46     ` Andrew Morton
     [not found]     ` <20060331153235.754deb0c.akpm@osdl.org>
2006-03-31 23:48       ` Christoph Lameter
2006-04-01  0:00         ` Andrew Morton
2006-04-01  0:14           ` Andrew Morton
2006-04-01  0:22           ` Christoph Lameter
2006-04-01  1:25             ` Andrew Morton
2006-04-01  2:34               ` Nick Piggin
2006-04-01  5:59               ` Nathan Scott
2006-04-01 18:30                 ` David Chinner
2006-04-01 18:49                   ` Christoph Lameter
2006-04-01 18:24             ` David Chinner
2006-03-31 23:45 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox