Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 42657
b: refs/heads/master
c: 8f5be20
h: refs/heads/master
i:
  42655: 515a99d
v: v3
  • Loading branch information
Ravikiran G Thirumalai authored and Linus Torvalds committed Dec 7, 2006
1 parent 4c7bf88 commit 4bada93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a44b56d354b49f9abb184e5a14f71889856283bb
refs/heads/master: 8f5be20bf87da7c7c59c5cc84f630a1eca5cc99c
40 changes: 21 additions & 19 deletions trunk/mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,10 @@ static inline void init_lock_keys(void)
}
#endif

/* Guard access to the cache-chain. */
/*
* 1. Guard access to the cache-chain.
* 2. Protect sanity of cpu_online_map against cpu hotplug events
*/
static DEFINE_MUTEX(cache_chain_mutex);
static struct list_head cache_chain;

Expand Down Expand Up @@ -1230,12 +1233,18 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
kfree(shared);
free_alien_cache(alien);
}
mutex_unlock(&cache_chain_mutex);
break;
case CPU_ONLINE:
mutex_unlock(&cache_chain_mutex);
start_cpu_timer(cpu);
break;
#ifdef CONFIG_HOTPLUG_CPU
case CPU_DOWN_PREPARE:
mutex_lock(&cache_chain_mutex);
break;
case CPU_DOWN_FAILED:
mutex_unlock(&cache_chain_mutex);
break;
case CPU_DEAD:
/*
* Even if all the cpus of a node are down, we don't free the
Expand All @@ -1246,8 +1255,8 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
* gets destroyed at kmem_cache_destroy().
*/
/* fall thru */
#endif
case CPU_UP_CANCELED:
mutex_lock(&cache_chain_mutex);
list_for_each_entry(cachep, &cache_chain, next) {
struct array_cache *nc;
struct array_cache *shared;
Expand Down Expand Up @@ -1308,11 +1317,9 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
}
mutex_unlock(&cache_chain_mutex);
break;
#endif
}
return NOTIFY_OK;
bad:
mutex_unlock(&cache_chain_mutex);
return NOTIFY_BAD;
}

Expand Down Expand Up @@ -2098,11 +2105,9 @@ kmem_cache_create (const char *name, size_t size, size_t align,
}

/*
* Prevent CPUs from coming and going.
* lock_cpu_hotplug() nests outside cache_chain_mutex
* We use cache_chain_mutex to ensure a consistent view of
* cpu_online_map as well. Please see cpuup_callback
*/
lock_cpu_hotplug();

mutex_lock(&cache_chain_mutex);

list_for_each_entry(pc, &cache_chain, next) {
Expand Down Expand Up @@ -2325,7 +2330,6 @@ kmem_cache_create (const char *name, size_t size, size_t align,
panic("kmem_cache_create(): failed to create slab `%s'\n",
name);
mutex_unlock(&cache_chain_mutex);
unlock_cpu_hotplug();
return cachep;
}
EXPORT_SYMBOL(kmem_cache_create);
Expand Down Expand Up @@ -2443,6 +2447,7 @@ static int drain_freelist(struct kmem_cache *cache,
return nr_freed;
}

/* Called with cache_chain_mutex held to protect against cpu hotplug */
static int __cache_shrink(struct kmem_cache *cachep)
{
int ret = 0, i = 0;
Expand Down Expand Up @@ -2473,9 +2478,13 @@ static int __cache_shrink(struct kmem_cache *cachep)
*/
int kmem_cache_shrink(struct kmem_cache *cachep)
{
int ret;
BUG_ON(!cachep || in_interrupt());

return __cache_shrink(cachep);
mutex_lock(&cache_chain_mutex);
ret = __cache_shrink(cachep);
mutex_unlock(&cache_chain_mutex);
return ret;
}
EXPORT_SYMBOL(kmem_cache_shrink);

Expand All @@ -2499,31 +2508,24 @@ void kmem_cache_destroy(struct kmem_cache *cachep)
{
BUG_ON(!cachep || in_interrupt());

/* Don't let CPUs to come and go */
lock_cpu_hotplug();

/* Find the cache in the chain of caches. */
mutex_lock(&cache_chain_mutex);
/*
* the chain is never empty, cache_cache is never destroyed
*/
list_del(&cachep->next);
mutex_unlock(&cache_chain_mutex);

if (__cache_shrink(cachep)) {
slab_error(cachep, "Can't free all objects");
mutex_lock(&cache_chain_mutex);
list_add(&cachep->next, &cache_chain);
mutex_unlock(&cache_chain_mutex);
unlock_cpu_hotplug();
return;
}

if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU))
synchronize_rcu();

__kmem_cache_destroy(cachep);
unlock_cpu_hotplug();
mutex_unlock(&cache_chain_mutex);
}
EXPORT_SYMBOL(kmem_cache_destroy);

Expand Down

0 comments on commit 4bada93

Please sign in to comment.