aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2012-09-04 20:20:34 -0400
committerPekka Enberg <penberg@kernel.org>2012-09-05 05:00:36 -0400
commit278b1bb1313664d4999a7f7d47a8a8d964862d02 (patch)
tree65e05bc30338a24fd4afd4c4e8b49b8d3e002218 /mm/slub.c
parent96d17b7be0a9849d381442030886211dbb2a7061 (diff)
mm/sl[aou]b: Move kmem_cache allocations into common code
Shift the allocations to common code. That way the allocation and freeing of the kmem_cache structures is handled by 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/slub.c')
-rw-r--r--mm/slub.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/mm/slub.c b/mm/slub.c
index 8d00fd78df23..0ad3fffc7d23 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3034,7 +3034,6 @@ static int kmem_cache_open(struct kmem_cache *s,
3034 size_t align, unsigned long flags, 3034 size_t align, unsigned long flags,
3035 void (*ctor)(void *)) 3035 void (*ctor)(void *))
3036{ 3036{
3037 memset(s, 0, kmem_size);
3038 s->name = name; 3037 s->name = name;
3039 s->ctor = ctor; 3038 s->ctor = ctor;
3040 s->object_size = size; 3039 s->object_size = size;
@@ -3109,7 +3108,7 @@ static int kmem_cache_open(struct kmem_cache *s,
3109 goto error; 3108 goto error;
3110 3109
3111 if (alloc_kmem_cache_cpus(s)) 3110 if (alloc_kmem_cache_cpus(s))
3112 return 1; 3111 return 0;
3113 3112
3114 free_kmem_cache_nodes(s); 3113 free_kmem_cache_nodes(s);
3115error: 3114error:
@@ -3118,7 +3117,7 @@ error:
3118 "order=%u offset=%u flags=%lx\n", 3117 "order=%u offset=%u flags=%lx\n",
3119 s->name, (unsigned long)size, s->size, oo_order(s->oo), 3118 s->name, (unsigned long)size, s->size, oo_order(s->oo),
3120 s->offset, flags); 3119 s->offset, flags);
3121 return 0; 3120 return -EINVAL;
3122} 3121}
3123 3122
3124/* 3123/*
@@ -3260,13 +3259,13 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
3260{ 3259{
3261 struct kmem_cache *s; 3260 struct kmem_cache *s;
3262 3261
3263 s = kmem_cache_alloc(kmem_cache, GFP_NOWAIT); 3262 s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
3264 3263
3265 /* 3264 /*
3266 * This function is called with IRQs disabled during early-boot on 3265 * This function is called with IRQs disabled during early-boot on
3267 * single CPU so there's no need to take slab_mutex here. 3266 * single CPU so there's no need to take slab_mutex here.
3268 */ 3267 */
3269 if (!kmem_cache_open(s, name, size, ARCH_KMALLOC_MINALIGN, 3268 if (kmem_cache_open(s, name, size, ARCH_KMALLOC_MINALIGN,
3270 flags, NULL)) 3269 flags, NULL))
3271 goto panic; 3270 goto panic;
3272 3271
@@ -3944,20 +3943,11 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
3944 return s; 3943 return s;
3945} 3944}
3946 3945
3947struct kmem_cache *__kmem_cache_create(const char *name, size_t size, 3946int __kmem_cache_create(struct kmem_cache *s,
3947 const char *name, size_t size,
3948 size_t align, unsigned long flags, void (*ctor)(void *)) 3948 size_t align, unsigned long flags, void (*ctor)(void *))
3949{ 3949{
3950 struct kmem_cache *s; 3950 return kmem_cache_open(s, name, size, align, flags, ctor);
3951
3952 s = kmem_cache_alloc(kmem_cache, GFP_KERNEL);
3953 if (s) {
3954 if (kmem_cache_open(s, name,
3955 size, align, flags, ctor)) {
3956 return s;
3957 }
3958 kmem_cache_free(kmem_cache, s);
3959 }
3960 return NULL;
3961} 3951}
3962 3952
3963#ifdef CONFIG_SMP 3953#ifdef CONFIG_SMP