diff options
author | Christoph Lameter <cl@linux.com> | 2012-07-06 16:25:13 -0400 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2012-07-09 05:13:42 -0400 |
commit | 20cea9683ecc6dd75a80c0dd02dc69c64e95be75 (patch) | |
tree | c52994730d2d280f9300197cc4f561b15e3dd4b2 /mm/slab.c | |
parent | 18004c5d4084d965aa1396392706b8688306427a (diff) |
mm, sl[aou]b: Move kmem_cache_create mutex handling to common code
Move the mutex handling into the common kmem_cache_create()
function.
Then we can also move more checks out of SLAB's kmem_cache_create()
into the common code.
Reviewed-by: Glauber Costa <glommer@parallels.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm/slab.c')
-rw-r--r-- | mm/slab.c | 52 |
1 files changed, 1 insertions, 51 deletions
@@ -2228,55 +2228,10 @@ __kmem_cache_create (const char *name, size_t size, size_t align, | |||
2228 | unsigned long flags, void (*ctor)(void *)) | 2228 | unsigned long flags, void (*ctor)(void *)) |
2229 | { | 2229 | { |
2230 | size_t left_over, slab_size, ralign; | 2230 | size_t left_over, slab_size, ralign; |
2231 | struct kmem_cache *cachep = NULL, *pc; | 2231 | struct kmem_cache *cachep = NULL; |
2232 | gfp_t gfp; | 2232 | gfp_t gfp; |
2233 | 2233 | ||
2234 | /* | ||
2235 | * Sanity checks... these are all serious usage bugs. | ||
2236 | */ | ||
2237 | if (!name || in_interrupt() || (size < BYTES_PER_WORD) || | ||
2238 | size > KMALLOC_MAX_SIZE) { | ||
2239 | printk(KERN_ERR "%s: Early error in slab %s\n", __func__, | ||
2240 | name); | ||
2241 | BUG(); | ||
2242 | } | ||
2243 | |||
2244 | /* | ||
2245 | * We use cache_chain_mutex to ensure a consistent view of | ||
2246 | * cpu_online_mask as well. Please see cpuup_callback | ||
2247 | */ | ||
2248 | if (slab_is_available()) { | ||
2249 | get_online_cpus(); | ||
2250 | mutex_lock(&slab_mutex); | ||
2251 | } | ||
2252 | |||
2253 | list_for_each_entry(pc, &slab_caches, list) { | ||
2254 | char tmp; | ||
2255 | int res; | ||
2256 | |||
2257 | /* | ||
2258 | * This happens when the module gets unloaded and doesn't | ||
2259 | * destroy its slab cache and no-one else reuses the vmalloc | ||
2260 | * area of the module. Print a warning. | ||
2261 | */ | ||
2262 | res = probe_kernel_address(pc->name, tmp); | ||
2263 | if (res) { | ||
2264 | printk(KERN_ERR | ||
2265 | "SLAB: cache with size %d has lost its name\n", | ||
2266 | pc->size); | ||
2267 | continue; | ||
2268 | } | ||
2269 | |||
2270 | if (!strcmp(pc->name, name)) { | ||
2271 | printk(KERN_ERR | ||
2272 | "kmem_cache_create: duplicate cache %s\n", name); | ||
2273 | dump_stack(); | ||
2274 | goto oops; | ||
2275 | } | ||
2276 | } | ||
2277 | |||
2278 | #if DEBUG | 2234 | #if DEBUG |
2279 | WARN_ON(strchr(name, ' ')); /* It confuses parsers */ | ||
2280 | #if FORCED_DEBUG | 2235 | #if FORCED_DEBUG |
2281 | /* | 2236 | /* |
2282 | * Enable redzoning and last user accounting, except for caches with | 2237 | * Enable redzoning and last user accounting, except for caches with |
@@ -2495,11 +2450,6 @@ __kmem_cache_create (const char *name, size_t size, size_t align, | |||
2495 | 2450 | ||
2496 | /* cache setup completed, link it into the list */ | 2451 | /* cache setup completed, link it into the list */ |
2497 | list_add(&cachep->list, &slab_caches); | 2452 | list_add(&cachep->list, &slab_caches); |
2498 | oops: | ||
2499 | if (slab_is_available()) { | ||
2500 | mutex_unlock(&slab_mutex); | ||
2501 | put_online_cpus(); | ||
2502 | } | ||
2503 | return cachep; | 2453 | return cachep; |
2504 | } | 2454 | } |
2505 | 2455 | ||