diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/slab.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index 3e4e5491102c..138bcdf65275 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -62,7 +62,38 @@ extern void *kmem_cache_alloc(kmem_cache_t *, int); extern void kmem_cache_free(kmem_cache_t *, void *); extern unsigned int kmem_cache_size(kmem_cache_t *); -extern void *kmalloc(size_t, int); +/* Size description struct for general caches. */ +struct cache_sizes { + size_t cs_size; + kmem_cache_t *cs_cachep; + kmem_cache_t *cs_dmacachep; +}; +extern struct cache_sizes malloc_sizes[]; +extern void *__kmalloc(size_t, int); + +static inline void *kmalloc(size_t size, int flags) +{ + if (__builtin_constant_p(size)) { + int i = 0; +#define CACHE(x) \ + if (size <= x) \ + goto found; \ + else \ + i++; +#include "kmalloc_sizes.h" +#undef CACHE + { + extern void __you_cannot_kmalloc_that_much(void); + __you_cannot_kmalloc_that_much(); + } +found: + return kmem_cache_alloc((flags & GFP_DMA) ? + malloc_sizes[i].cs_dmacachep : + malloc_sizes[i].cs_cachep, flags); + } + return __kmalloc(size, flags); +} + extern void kfree(const void *); extern unsigned int ksize(const void *); |
