Skip to contentSkip to conversation

Locking optimization for cache_reap

PATCH In review Dimitri Sivanich 4 participants 7 messages Jul 23, 2004 – Jul 27, 2004 1 message not in the archive Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Locking optimization for cache_reap

Here is another cache_reap optimization that reduces latency when applied after the 'Move cache_reap out of timer context' patch I submitted on 7/14 (for inclusion in -mm next week).

This applies to 2.6.8-rc2 + the above mentioned patch.

mm/slab.c +6 -31
Index: linux/mm/slab.c
===================================================================
@@ -2619,27 +2619,6 @@ static void enable_cpucache (kmem_cache_
 					cachep->name, -err);
 }
 
-static void drain_array(kmem_cache_t *cachep, struct array_cache *ac)
-{
-	int tofree;
-
-	check_irq_off();
-	if (ac->touched) {
-		ac->touched = 0;
-	} else if (ac->avail) {
-		tofree = (ac->limit+4)/5;
-		if (tofree > ac->avail) {
-			tofree = (ac->avail+1)/2;
-		}
-		spin_lock(&cachep->spinlock);
-		free_block(cachep, ac_entry(ac), tofree);
-		spin_unlock(&cachep->spinlock);
-		ac->avail -= tofree;
-		memmove(&ac_entry(ac)[0], &ac_entry(ac)[tofree],
-					sizeof(void*)*ac->avail);
-	}
-}
-
 static void drain_array_locked(kmem_cache_t *cachep,
 				struct array_cache *ac, int force)
 {
@@ -2697,16 +2676,14 @@ static void cache_reap (void *unused)
 			goto next;
 
 		check_irq_on();
-		local_irq_disable();
-		drain_array(searchp, ac_data(searchp));
 
-		if(time_after(searchp->lists.next_reap, jiffies))
-			goto next_irqon;
+		spin_lock_irq(&searchp->spinlock);
+
+		drain_array_locked(searchp, ac_data(searchp), 0);
 
-		spin_lock(&searchp->spinlock);
-		if(time_after(searchp->lists.next_reap, jiffies)) {
+		if(time_after(searchp->lists.next_reap, jiffies))
 			goto next_unlock;
-		}
+
 		searchp->lists.next_reap = jiffies + REAPTIMEOUT_LIST3;
 
 		if (searchp->lists.shared)
@@ -2739,9 +2716,7 @@ static void cache_reap (void *unused)
 			spin_lock_irq(&searchp->spinlock);
 		} while(--tofree > 0);
 next_unlock:
-		spin_unlock(&searchp->spinlock);
-next_irqon:
-		local_irq_enable();
+		spin_unlock_irq(&searchp->spinlock);
 next:
 		;
 	}

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

#1 lore raw
Quoted 6 lines · Dimitri Sivanich

Here is another cache_reap optimization that reduces latency when applied after the 'Move cache_reap out of timer context' patch I submitted on 7/14 (for inclusion in -mm next week).

This applies to 2.6.8-rc2 + the above mentioned patch.

How does it "reduce latency"?

It looks like a reasonable cleanup, but afaict it will result in the per-cache spinlock actually being held for longer periods, thus increasing latencies???

Quoted 57 lines

Index: linux/mm/slab.c
===================================================================

mm/slab.c +5 -28
@@ -2619,27 +2619,6 @@ static void enable_cpucache (kmem_cache_
 					cachep->name, -err);
 }
 
-static void drain_array(kmem_cache_t *cachep, struct array_cache *ac)
-{
-	int tofree;
-
-	check_irq_off();
-	if (ac->touched) {
-		ac->touched = 0;
-	} else if (ac->avail) {
-		tofree = (ac->limit+4)/5;
-		if (tofree > ac->avail) {
-			tofree = (ac->avail+1)/2;
-		}
-		spin_lock(&cachep->spinlock);
-		free_block(cachep, ac_entry(ac), tofree);
-		spin_unlock(&cachep->spinlock);
-		ac->avail -= tofree;
-		memmove(&ac_entry(ac)[0], &ac_entry(ac)[tofree],
-					sizeof(void*)*ac->avail);
-	}
-}
-
 static void drain_array_locked(kmem_cache_t *cachep,
 				struct array_cache *ac, int force)
 {
@@ -2697,16 +2676,14 @@ static void cache_reap (void *unused)
 			goto next;
 
 		check_irq_on();
-		local_irq_disable();
-		drain_array(searchp, ac_data(searchp));
 
-		if(time_after(searchp->lists.next_reap, jiffies))
-			goto next_irqon;
+		spin_lock_irq(&searchp->spinlock);
+
+		drain_array_locked(searchp, ac_data(searchp), 0);
 
-		spin_lock(&searchp->spinlock);
-		if(time_after(searchp->lists.next_reap, jiffies)) {
+		if(time_after(searchp->lists.next_reap, jiffies))
 			goto next_unlock;
-		}
+
 		searchp->lists.next_reap = jiffies + REAPTIMEOUT_LIST3;
 
 		if (searchp->lists.shared)

mm/slab.c static void cache_reap (void *unused) · line 2722

Quoted 10 lines
mm/slab.c +1 -3
@@ -2739,9 +2716,7 @@ static void cache_reap (void *unused)
 			spin_lock_irq(&searchp->spinlock);
 		} while(--tofree > 0);
 next_unlock:
-		spin_unlock(&searchp->spinlock);
-next_irqon:
-		local_irq_enable();
+		spin_unlock_irq(&searchp->spinlock);
 next:
 		;
 	}

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

#2 lore raw
Quoted 6 lines · Andrew Morton
Quoted 5 lines · Dimitri Sivanich

Here is another cache_reap optimization that reduces latency when applied after the 'Move cache_reap out of timer context' patch I submitted on 7/14 (for inclusion in -mm next week).

Quoted 8 lines
Quoted 1 line

This applies to 2.6.8-rc2 + the above mentioned patch.

How does it "reduce latency"?

It looks like a reasonable cleanup, but afaict it will result in the per-cache spinlock actually being held for longer periods, thus increasing latencies???

While you've got irq's disabled, drain_array() (the function my patch removes) acquires the cache spin_lock, then releases it. Cache_reap then acquires it again (with irq's having been off the entire time). My testing has found that simply acquiring the lock once while irq's are off results in fewer excessively long latencies.

Results probably vary somewhat depending on the circumstance. --
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

Hi,

I have a simple doubt. Please answer it.
Why the error " Inappropriate ioctl for device While reading flags ......................" is ocuring?. YOur replies will be greatly appreciated.

Regards,
Aroop

---------------------------------------------------
"NO MATTER WHERE YOU ARE IN THE WORLD,IF YOU HAVE DECIDED TO DO SOMETHING
DEEP FROM YOUR HEART YOU CAN DO IT. IT HAS ALWAYS BEEN THE THOUGHT THAT
MATTERS... "
---------------------------------------------------

#7 lore raw
In reply to Dimitri Sivanich
Quoted 8 lines · Dimitri Sivanich

While you've got irq's disabled, drain_array() (the function my patch removes) acquires the cache spin_lock, then releases it. Cache_reap then acquires it again (with irq's having been off the entire time). My testing has found that simply acquiring the lock once while irq's are off results in fewer excessively long latencies.

Results probably vary somewhat depending on the circumstance.

Of course, I should add that all of this is from the perspective of the cpu doing the cache_reap. If others feel that this may add too much latency to other paths, other solutions may be in order.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

lsattr: Inappropriate ioctl for device While reading flags!!!

In reply to a message not in the archive

Hi,

Thanks for your quick reply. When i check lsattr of the file /usr/local/cpanel/3rdparty/etc/php.ini i got the following error.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Server[~]# lsattr /usr/local/cpanel/3rdparty/etc/php.ini
lsattr: Inappropriate ioctl for device While reading flags on /usr/local/cpanel/3rdparty/etc/php.ini
Server[~]#
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please get back to me if you need any more info. regarding this.

Thank You.

Quoted 7 lines · you
Quoted 4 lines · Aroop MP

I have a simple doubt. Please answer it.
Why the error " Inappropriate ioctl for device While reading flags ......................" is ocuring?. YOur replies will be greatly appreciated.

I have not seen this. Can you elaborate?

Signature · 7 lines
 Regards, 
 Aroop M.P
 ---------------------------------------------------
 "NO MATTER WHERE YOU ARE IN THE WORLD,IF YOU HAVE DECIDED TO DO  SOMETHING 
DEEP FROM YOUR HEART YOU CAN DO IT. IT HAS ALWAYS BEEN THE   THOUGHT THAT 
MATTERS... "
 ---------------------------------------------------
#6 lore raw

Re: lsattr: Inappropriate ioctl for device While reading flags!!!

Quoted 11 lines · Aroop MP

Hi,

Thanks for your quick reply. When i check lsattr of the file /usr/local/cpanel/3rdparty/etc/php.ini i got the following error.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Server[~]# lsattr /usr/local/cpanel/3rdparty/etc/php.ini
lsattr: Inappropriate ioctl for device While reading flags on /usr/local/cpanel/3rdparty/etc/php.ini
Server[~]#
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 1 line

Please get back to me if you need any more info. regarding this.

Because /usr/local/cpanel/3rdparty/etc/php.ini is not on an ext[23] filesystem? Remote mounting via NFS, or your favorite network fs does not count as ext[23].

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