Commit 716b7ab1 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] slab: Remove cache_chain_lock

Manfred added a new lock to protect the global list of slab caches.  We
already have a semaphore from those but he needs locking from timer
context.

So here we remove that lock and just do a down_trylock() on the
existing semaphore.  If that fails give up - we'll try again next timer
tick.
parent bf19f75e
...@@ -459,7 +459,6 @@ static kmem_cache_t cache_cache = { ...@@ -459,7 +459,6 @@ static kmem_cache_t cache_cache = {
/* Guard access to the cache-chain. */ /* Guard access to the cache-chain. */
static struct semaphore cache_chain_sem; static struct semaphore cache_chain_sem;
static rwlock_t cache_chain_lock = RW_LOCK_UNLOCKED;
struct list_head cache_chain; struct list_head cache_chain;
...@@ -1054,9 +1053,7 @@ kmem_cache_create (const char *name, size_t size, size_t offset, ...@@ -1054,9 +1053,7 @@ kmem_cache_create (const char *name, size_t size, size_t offset,
} }
/* cache setup completed, link it into the list */ /* cache setup completed, link it into the list */
write_lock_bh(&cache_chain_lock);
list_add(&cachep->next, &cache_chain); list_add(&cachep->next, &cache_chain);
write_unlock_bh(&cache_chain_lock);
up(&cache_chain_sem); up(&cache_chain_sem);
opps: opps:
return cachep; return cachep;
...@@ -1190,19 +1187,17 @@ int kmem_cache_destroy (kmem_cache_t * cachep) ...@@ -1190,19 +1187,17 @@ int kmem_cache_destroy (kmem_cache_t * cachep)
/* Find the cache in the chain of caches. */ /* Find the cache in the chain of caches. */
down(&cache_chain_sem); down(&cache_chain_sem);
/* the chain is never empty, cache_cache is never destroyed */ /*
write_lock_bh(&cache_chain_lock); * the chain is never empty, cache_cache is never destroyed
*/
list_del(&cachep->next); list_del(&cachep->next);
write_unlock_bh(&cache_chain_lock);
up(&cache_chain_sem); up(&cache_chain_sem);
if (__cache_shrink(cachep)) { if (__cache_shrink(cachep)) {
printk(KERN_ERR "kmem_cache_destroy: Can't free all objects %p\n", printk(KERN_ERR "kmem_cache_destroy: Can't free all objects %p\n",
cachep); cachep);
down(&cache_chain_sem); down(&cache_chain_sem);
write_lock_bh(&cache_chain_lock);
list_add(&cachep->next,&cache_chain); list_add(&cachep->next,&cache_chain);
write_unlock_bh(&cache_chain_lock);
up(&cache_chain_sem); up(&cache_chain_sem);
return 1; return 1;
} }
...@@ -1956,9 +1951,12 @@ static void enable_cpucache (kmem_cache_t *cachep) ...@@ -1956,9 +1951,12 @@ static void enable_cpucache (kmem_cache_t *cachep)
* cache_reap - Reclaim memory from caches. * cache_reap - Reclaim memory from caches.
* *
* Called from a timer, every few seconds * Called from a timer, every few seconds
* Purpuse: * Purpose:
* - clear the per-cpu caches for this CPU. * - clear the per-cpu caches for this CPU.
* - return freeable pages to the main free memory pool. * - return freeable pages to the main free memory pool.
*
* If we cannot acquire the cache chain semaphore then just give up - we'll
* try again next timer interrupt.
*/ */
static inline void cache_reap (void) static inline void cache_reap (void)
{ {
...@@ -1968,7 +1966,8 @@ static inline void cache_reap (void) ...@@ -1968,7 +1966,8 @@ static inline void cache_reap (void)
BUG_ON(!in_interrupt()); BUG_ON(!in_interrupt());
BUG_ON(in_irq()); BUG_ON(in_irq());
#endif #endif
read_lock(&cache_chain_lock); if (down_trylock(&cache_chain_sem))
return;
list_for_each(walk, &cache_chain) { list_for_each(walk, &cache_chain) {
kmem_cache_t *searchp; kmem_cache_t *searchp;
...@@ -2038,8 +2037,7 @@ static inline void cache_reap (void) ...@@ -2038,8 +2037,7 @@ static inline void cache_reap (void)
next: next:
} }
check_irq_on(); check_irq_on();
up(&cache_chain_sem);
read_unlock(&cache_chain_lock);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment