diff options
author | Christoph Lameter <cl@linux.com> | 2012-07-06 16:25:10 -0400 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2012-07-09 05:13:30 -0400 |
commit | 039363f38bfe5f6281e9eae5e0518b11577d9d50 (patch) | |
tree | 11aa16feccb68b035aa9e9f390a54e57fa2ffd83 /mm/slab.c | |
parent | 068ce415bea9e2b96bde76dc1bf6e672a89903ee (diff) |
mm, sl[aou]b: Extract common code for kmem_cache_create()
Kmem_cache_create() does a variety of sanity checks but those
vary depending on the allocator. Use the strictest tests and put them into
a slab_common file. Make the tests conditional on CONFIG_DEBUG_VM.
This patch has the effect of adding sanity checks for SLUB and SLOB
under CONFIG_DEBUG_VM and removes the checks in SLAB for !CONFIG_DEBUG_VM.
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 | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -1558,7 +1558,7 @@ void __init kmem_cache_init(void) | |||
1558 | * bug. | 1558 | * bug. |
1559 | */ | 1559 | */ |
1560 | 1560 | ||
1561 | sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name, | 1561 | sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name, |
1562 | sizes[INDEX_AC].cs_size, | 1562 | sizes[INDEX_AC].cs_size, |
1563 | ARCH_KMALLOC_MINALIGN, | 1563 | ARCH_KMALLOC_MINALIGN, |
1564 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, | 1564 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, |
@@ -1566,7 +1566,7 @@ void __init kmem_cache_init(void) | |||
1566 | 1566 | ||
1567 | if (INDEX_AC != INDEX_L3) { | 1567 | if (INDEX_AC != INDEX_L3) { |
1568 | sizes[INDEX_L3].cs_cachep = | 1568 | sizes[INDEX_L3].cs_cachep = |
1569 | kmem_cache_create(names[INDEX_L3].name, | 1569 | __kmem_cache_create(names[INDEX_L3].name, |
1570 | sizes[INDEX_L3].cs_size, | 1570 | sizes[INDEX_L3].cs_size, |
1571 | ARCH_KMALLOC_MINALIGN, | 1571 | ARCH_KMALLOC_MINALIGN, |
1572 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, | 1572 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, |
@@ -1584,14 +1584,14 @@ void __init kmem_cache_init(void) | |||
1584 | * allow tighter packing of the smaller caches. | 1584 | * allow tighter packing of the smaller caches. |
1585 | */ | 1585 | */ |
1586 | if (!sizes->cs_cachep) { | 1586 | if (!sizes->cs_cachep) { |
1587 | sizes->cs_cachep = kmem_cache_create(names->name, | 1587 | sizes->cs_cachep = __kmem_cache_create(names->name, |
1588 | sizes->cs_size, | 1588 | sizes->cs_size, |
1589 | ARCH_KMALLOC_MINALIGN, | 1589 | ARCH_KMALLOC_MINALIGN, |
1590 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, | 1590 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, |
1591 | NULL); | 1591 | NULL); |
1592 | } | 1592 | } |
1593 | #ifdef CONFIG_ZONE_DMA | 1593 | #ifdef CONFIG_ZONE_DMA |
1594 | sizes->cs_dmacachep = kmem_cache_create( | 1594 | sizes->cs_dmacachep = __kmem_cache_create( |
1595 | names->name_dma, | 1595 | names->name_dma, |
1596 | sizes->cs_size, | 1596 | sizes->cs_size, |
1597 | ARCH_KMALLOC_MINALIGN, | 1597 | ARCH_KMALLOC_MINALIGN, |
@@ -2220,7 +2220,7 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp) | |||
2220 | } | 2220 | } |
2221 | 2221 | ||
2222 | /** | 2222 | /** |
2223 | * kmem_cache_create - Create a cache. | 2223 | * __kmem_cache_create - Create a cache. |
2224 | * @name: A string which is used in /proc/slabinfo to identify this cache. | 2224 | * @name: A string which is used in /proc/slabinfo to identify this cache. |
2225 | * @size: The size of objects to be created in this cache. | 2225 | * @size: The size of objects to be created in this cache. |
2226 | * @align: The required alignment for the objects. | 2226 | * @align: The required alignment for the objects. |
@@ -2247,7 +2247,7 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp) | |||
2247 | * as davem. | 2247 | * as davem. |
2248 | */ | 2248 | */ |
2249 | struct kmem_cache * | 2249 | struct kmem_cache * |
2250 | kmem_cache_create (const char *name, size_t size, size_t align, | 2250 | __kmem_cache_create (const char *name, size_t size, size_t align, |
2251 | unsigned long flags, void (*ctor)(void *)) | 2251 | unsigned long flags, void (*ctor)(void *)) |
2252 | { | 2252 | { |
2253 | size_t left_over, slab_size, ralign; | 2253 | size_t left_over, slab_size, ralign; |
@@ -2388,7 +2388,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2388 | /* Get cache's description obj. */ | 2388 | /* Get cache's description obj. */ |
2389 | cachep = kmem_cache_zalloc(&cache_cache, gfp); | 2389 | cachep = kmem_cache_zalloc(&cache_cache, gfp); |
2390 | if (!cachep) | 2390 | if (!cachep) |
2391 | goto oops; | 2391 | return NULL; |
2392 | 2392 | ||
2393 | cachep->nodelists = (struct kmem_list3 **)&cachep->array[nr_cpu_ids]; | 2393 | cachep->nodelists = (struct kmem_list3 **)&cachep->array[nr_cpu_ids]; |
2394 | cachep->object_size = size; | 2394 | cachep->object_size = size; |
@@ -2445,8 +2445,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2445 | printk(KERN_ERR | 2445 | printk(KERN_ERR |
2446 | "kmem_cache_create: couldn't create cache %s.\n", name); | 2446 | "kmem_cache_create: couldn't create cache %s.\n", name); |
2447 | kmem_cache_free(&cache_cache, cachep); | 2447 | kmem_cache_free(&cache_cache, cachep); |
2448 | cachep = NULL; | 2448 | return NULL; |
2449 | goto oops; | ||
2450 | } | 2449 | } |
2451 | slab_size = ALIGN(cachep->num * sizeof(kmem_bufctl_t) | 2450 | slab_size = ALIGN(cachep->num * sizeof(kmem_bufctl_t) |
2452 | + sizeof(struct slab), align); | 2451 | + sizeof(struct slab), align); |
@@ -2504,8 +2503,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2504 | 2503 | ||
2505 | if (setup_cpu_cache(cachep, gfp)) { | 2504 | if (setup_cpu_cache(cachep, gfp)) { |
2506 | __kmem_cache_destroy(cachep); | 2505 | __kmem_cache_destroy(cachep); |
2507 | cachep = NULL; | 2506 | return NULL; |
2508 | goto oops; | ||
2509 | } | 2507 | } |
2510 | 2508 | ||
2511 | if (flags & SLAB_DEBUG_OBJECTS) { | 2509 | if (flags & SLAB_DEBUG_OBJECTS) { |
@@ -2521,16 +2519,12 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2521 | /* cache setup completed, link it into the list */ | 2519 | /* cache setup completed, link it into the list */ |
2522 | list_add(&cachep->list, &cache_chain); | 2520 | list_add(&cachep->list, &cache_chain); |
2523 | oops: | 2521 | oops: |
2524 | if (!cachep && (flags & SLAB_PANIC)) | ||
2525 | panic("kmem_cache_create(): failed to create slab `%s'\n", | ||
2526 | name); | ||
2527 | if (slab_is_available()) { | 2522 | if (slab_is_available()) { |
2528 | mutex_unlock(&cache_chain_mutex); | 2523 | mutex_unlock(&cache_chain_mutex); |
2529 | put_online_cpus(); | 2524 | put_online_cpus(); |
2530 | } | 2525 | } |
2531 | return cachep; | 2526 | return cachep; |
2532 | } | 2527 | } |
2533 | EXPORT_SYMBOL(kmem_cache_create); | ||
2534 | 2528 | ||
2535 | #if DEBUG | 2529 | #if DEBUG |
2536 | static void check_irq_off(void) | 2530 | static void check_irq_off(void) |