1 #ifndef _LINUX_SLAB_DEF_H
2 #define _LINUX_SLAB_DEF_H
5 * Definitions unique to the original Linux SLAB allocator.
7 * What we provide here is a way to optimize the frequent kmalloc
8 * calls in the kernel by selecting the appropriate general cache
9 * if kmalloc was called with a size that can be established at
13 #include <linux/init.h>
14 #include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */
15 #include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */
16 #include <linux/compiler.h>
18 /* Size description struct for general caches. */
21 struct kmem_cache
*cs_cachep
;
22 #ifdef CONFIG_ZONE_DMA
23 struct kmem_cache
*cs_dmacachep
;
26 extern struct cache_sizes malloc_sizes
[];
28 static inline void *kmalloc(size_t size
, gfp_t flags
)
30 if (__builtin_constant_p(size
)) {
37 #include "kmalloc_sizes.h"
40 extern void __you_cannot_kmalloc_that_much(void);
41 __you_cannot_kmalloc_that_much();
44 #ifdef CONFIG_ZONE_DMA
46 return kmem_cache_alloc(malloc_sizes
[i
].cs_dmacachep
,
49 return kmem_cache_alloc(malloc_sizes
[i
].cs_cachep
, flags
);
51 return __kmalloc(size
, flags
);
54 static inline void *kzalloc(size_t size
, gfp_t flags
)
56 if (__builtin_constant_p(size
)) {
63 #include "kmalloc_sizes.h"
66 extern void __you_cannot_kzalloc_that_much(void);
67 __you_cannot_kzalloc_that_much();
70 #ifdef CONFIG_ZONE_DMA
72 return kmem_cache_zalloc(malloc_sizes
[i
].cs_dmacachep
,
75 return kmem_cache_zalloc(malloc_sizes
[i
].cs_cachep
, flags
);
77 return __kzalloc(size
, flags
);
81 extern void *__kmalloc_node(size_t size
, gfp_t flags
, int node
);
83 static inline void *kmalloc_node(size_t size
, gfp_t flags
, int node
)
85 if (__builtin_constant_p(size
)) {
92 #include "kmalloc_sizes.h"
95 extern void __you_cannot_kmalloc_that_much(void);
96 __you_cannot_kmalloc_that_much();
99 #ifdef CONFIG_ZONE_DMA
101 return kmem_cache_alloc_node(malloc_sizes
[i
].cs_dmacachep
,
104 return kmem_cache_alloc_node(malloc_sizes
[i
].cs_cachep
,
107 return __kmalloc_node(size
, flags
, node
);
110 #endif /* CONFIG_NUMA */
112 #endif /* _LINUX_SLAB_DEF_H */