slub: Dynamically size kmalloc cache allocations
kmalloc caches are statically defined and may take up a lot of space just because the sizes of the node array has to be dimensioned for the largest node count supported. This patch makes the size of the kmem_cache structure dynamic throughout by creating a kmem_cache slab cache for the kmem_cache objects. The bootstrap occurs by allocating the initial one or two kmem_cache objects from the page allocator. C2->C3 - Fix various issues indicated by David - Make create kmalloc_cache return a kmem_cache * pointer. Acked-by: David Rientjes <rientjes@google.com> Signed-off-by: Christoph Lameter <cl@linux-foundation.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:

committed by
Pekka Enberg

parent
6c182dc0de
commit
51df114281
@@ -139,19 +139,16 @@ struct kmem_cache {
|
||||
|
||||
#ifdef CONFIG_ZONE_DMA
|
||||
#define SLUB_DMA __GFP_DMA
|
||||
/* Reserve extra caches for potential DMA use */
|
||||
#define KMALLOC_CACHES (2 * SLUB_PAGE_SHIFT)
|
||||
#else
|
||||
/* Disable DMA functionality */
|
||||
#define SLUB_DMA (__force gfp_t)0
|
||||
#define KMALLOC_CACHES SLUB_PAGE_SHIFT
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We keep the general caches in an array of slab caches that are used for
|
||||
* 2^x bytes of allocations.
|
||||
*/
|
||||
extern struct kmem_cache kmalloc_caches[KMALLOC_CACHES];
|
||||
extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
|
||||
|
||||
/*
|
||||
* Sorry that the following has to be that ugly but some versions of GCC
|
||||
@@ -216,7 +213,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
|
||||
if (index == 0)
|
||||
return NULL;
|
||||
|
||||
return &kmalloc_caches[index];
|
||||
return kmalloc_caches[index];
|
||||
}
|
||||
|
||||
void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
|
||||
|
Reference in New Issue
Block a user