Skip to content

Commit

Permalink
slab: Use common kmalloc_index/kmalloc_size functions
Browse files Browse the repository at this point in the history
Make slab use the common functions. We can get rid of a lot
of old ugly stuff as a results. Among them the sizes
array and the weird include/linux/kmalloc_sizes file and
some pretty bad #include statements in slab_def.h.

The one thing that is different in slab is that the 32 byte
cache will also be created for arches that have page sizes
larger than 4K. There are numerous smaller allocations that
SLOB and SLUB can handle better because of their support for
smaller allocation sizes so lets keep the 32 byte slab also
for arches with > 4K pages.

Reviewed-by: Glauber Costa <glommer@parallels.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
  • Loading branch information
Christoph Lameter authored and Pekka Enberg committed Feb 1, 2013
1 parent ce6a502 commit e336601
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 173 deletions.
45 changes: 0 additions & 45 deletions include/linux/kmalloc_sizes.h

This file was deleted.

47 changes: 12 additions & 35 deletions include/linux/slab_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/

#include <linux/init.h>
#include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */
#include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */
#include <linux/compiler.h>

/*
Expand Down Expand Up @@ -104,15 +102,8 @@ struct kmem_cache {
*/
};

/* Size description struct for general caches. */
struct cache_sizes {
size_t cs_size;
struct kmem_cache *cs_cachep;
#ifdef CONFIG_ZONE_DMA
struct kmem_cache *cs_dmacachep;
#endif
};
extern struct cache_sizes malloc_sizes[];
extern struct kmem_cache *kmalloc_caches[PAGE_SHIFT + MAX_ORDER];
extern struct kmem_cache *kmalloc_dma_caches[PAGE_SHIFT + MAX_ORDER];

void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
void *__kmalloc(size_t size, gfp_t flags);
Expand All @@ -133,26 +124,19 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
void *ret;

if (__builtin_constant_p(size)) {
int i = 0;
int i;

if (!size)
return ZERO_SIZE_PTR;

#define CACHE(x) \
if (size <= x) \
goto found; \
else \
i++;
#include <linux/kmalloc_sizes.h>
#undef CACHE
return NULL;
found:
i = kmalloc_index(size);

#ifdef CONFIG_ZONE_DMA
if (flags & GFP_DMA)
cachep = malloc_sizes[i].cs_dmacachep;
cachep = kmalloc_dma_caches[i];
else
#endif
cachep = malloc_sizes[i].cs_cachep;
cachep = kmalloc_caches[i];

ret = kmem_cache_alloc_trace(cachep, flags, size);

Expand Down Expand Up @@ -186,26 +170,19 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
struct kmem_cache *cachep;

if (__builtin_constant_p(size)) {
int i = 0;
int i;

if (!size)
return ZERO_SIZE_PTR;

#define CACHE(x) \
if (size <= x) \
goto found; \
else \
i++;
#include <linux/kmalloc_sizes.h>
#undef CACHE
return NULL;
found:
i = kmalloc_index(size);

#ifdef CONFIG_ZONE_DMA
if (flags & GFP_DMA)
cachep = malloc_sizes[i].cs_dmacachep;
cachep = kmalloc_dma_caches[i];
else
#endif
cachep = malloc_sizes[i].cs_cachep;
cachep = kmalloc_caches[i];

return kmem_cache_alloc_node_trace(cachep, flags, node, size);
}
Expand Down
Loading

0 comments on commit e336601

Please sign in to comment.