aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slab_common.c
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2013-01-10 14:12:17 -0500
committerPekka Enberg <penberg@kernel.org>2013-02-01 05:32:08 -0500
commitf97d5f634d3b5133951424fae751db1f339548bd (patch)
treecb4db9a78c8eb1bd0522679d90f553d40d15f3e9 /mm/slab_common.c
parent9425c58e5445277699ff3c2a87bac1cfebc1b48d (diff)
slab: Common function to create the kmalloc array
The kmalloc array is created in similar ways in both SLAB and SLUB. Create a common function and have both allocators call that function. V1->V2: Whitespace cleanup 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_common.c')
-rw-r--r--mm/slab_common.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 0437b8189b8a..2b0ebb6d071d 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -327,6 +327,60 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
327EXPORT_SYMBOL(kmalloc_dma_caches); 327EXPORT_SYMBOL(kmalloc_dma_caches);
328#endif 328#endif
329 329
330/*
331 * Create the kmalloc array. Some of the regular kmalloc arrays
332 * may already have been created because they were needed to
333 * enable allocations for slab creation.
334 */
335void __init create_kmalloc_caches(unsigned long flags)
336{
337 int i;
338
339 /* Caches that are not of the two-to-the-power-of size */
340 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1])
341 kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
342
343 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2])
344 kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
345
346 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++)
347 if (!kmalloc_caches[i])
348 kmalloc_caches[i] = create_kmalloc_cache(NULL,
349 1 << i, flags);
350
351 /* Kmalloc array is now usable */
352 slab_state = UP;
353
354 for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
355 struct kmem_cache *s = kmalloc_caches[i];
356 char *n;
357
358 if (s) {
359 n = kasprintf(GFP_NOWAIT, "kmalloc-%d", kmalloc_size(i));
360
361 BUG_ON(!n);
362 s->name = n;
363 }
364 }
365
366#ifdef CONFIG_ZONE_DMA
367 for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
368 struct kmem_cache *s = kmalloc_caches[i];
369
370 if (s) {
371 int size = kmalloc_size(i);
372 char *n = kasprintf(GFP_NOWAIT,
373 "dma-kmalloc-%d", size);
374
375 BUG_ON(!n);
376 kmalloc_dma_caches[i] = create_kmalloc_cache(n,
377 size, SLAB_CACHE_DMA | flags);
378 }
379 }
380#endif
381}
382
383
330#endif /* !CONFIG_SLOB */ 384#endif /* !CONFIG_SLOB */
331 385
332 386