diff options
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r-- | include/linux/slab.h | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index e2ee5b268797..3af03b19c983 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
@@ -64,6 +64,7 @@ extern kmem_cache_t *kmem_cache_create(const char *, size_t, size_t, unsigned lo | |||
64 | extern int kmem_cache_destroy(kmem_cache_t *); | 64 | extern int kmem_cache_destroy(kmem_cache_t *); |
65 | extern int kmem_cache_shrink(kmem_cache_t *); | 65 | extern int kmem_cache_shrink(kmem_cache_t *); |
66 | extern void *kmem_cache_alloc(kmem_cache_t *, gfp_t); | 66 | extern void *kmem_cache_alloc(kmem_cache_t *, gfp_t); |
67 | extern void *kmem_cache_zalloc(struct kmem_cache *, gfp_t); | ||
67 | extern void kmem_cache_free(kmem_cache_t *, void *); | 68 | extern void kmem_cache_free(kmem_cache_t *, void *); |
68 | extern unsigned int kmem_cache_size(kmem_cache_t *); | 69 | extern unsigned int kmem_cache_size(kmem_cache_t *); |
69 | extern const char *kmem_cache_name(kmem_cache_t *); | 70 | extern const char *kmem_cache_name(kmem_cache_t *); |
@@ -77,11 +78,12 @@ struct cache_sizes { | |||
77 | }; | 78 | }; |
78 | extern struct cache_sizes malloc_sizes[]; | 79 | extern struct cache_sizes malloc_sizes[]; |
79 | 80 | ||
80 | #ifndef CONFIG_DEBUG_SLAB | ||
81 | extern void *__kmalloc(size_t, gfp_t); | 81 | extern void *__kmalloc(size_t, gfp_t); |
82 | #ifndef CONFIG_DEBUG_SLAB | ||
83 | #define ____kmalloc(size, flags) __kmalloc(size, flags) | ||
82 | #else | 84 | #else |
83 | extern void *__kmalloc_track_caller(size_t, gfp_t, void*); | 85 | extern void *__kmalloc_track_caller(size_t, gfp_t, void*); |
84 | #define __kmalloc(size, flags) \ | 86 | #define ____kmalloc(size, flags) \ |
85 | __kmalloc_track_caller(size, flags, __builtin_return_address(0)) | 87 | __kmalloc_track_caller(size, flags, __builtin_return_address(0)) |
86 | #endif | 88 | #endif |
87 | 89 | ||
@@ -108,7 +110,30 @@ found: | |||
108 | return __kmalloc(size, flags); | 110 | return __kmalloc(size, flags); |
109 | } | 111 | } |
110 | 112 | ||
111 | extern void *kzalloc(size_t, gfp_t); | 113 | extern void *__kzalloc(size_t, gfp_t); |
114 | |||
115 | static inline void *kzalloc(size_t size, gfp_t flags) | ||
116 | { | ||
117 | if (__builtin_constant_p(size)) { | ||
118 | int i = 0; | ||
119 | #define CACHE(x) \ | ||
120 | if (size <= x) \ | ||
121 | goto found; \ | ||
122 | else \ | ||
123 | i++; | ||
124 | #include "kmalloc_sizes.h" | ||
125 | #undef CACHE | ||
126 | { | ||
127 | extern void __you_cannot_kzalloc_that_much(void); | ||
128 | __you_cannot_kzalloc_that_much(); | ||
129 | } | ||
130 | found: | ||
131 | return kmem_cache_zalloc((flags & GFP_DMA) ? | ||
132 | malloc_sizes[i].cs_dmacachep : | ||
133 | malloc_sizes[i].cs_cachep, flags); | ||
134 | } | ||
135 | return __kzalloc(size, flags); | ||
136 | } | ||
112 | 137 | ||
113 | /** | 138 | /** |
114 | * kcalloc - allocate memory for an array. The memory is set to zero. | 139 | * kcalloc - allocate memory for an array. The memory is set to zero. |
@@ -155,17 +180,18 @@ struct kmem_cache *kmem_cache_create(const char *c, size_t, size_t, | |||
155 | void (*)(void *, struct kmem_cache *, unsigned long)); | 180 | void (*)(void *, struct kmem_cache *, unsigned long)); |
156 | int kmem_cache_destroy(struct kmem_cache *c); | 181 | int kmem_cache_destroy(struct kmem_cache *c); |
157 | void *kmem_cache_alloc(struct kmem_cache *c, gfp_t flags); | 182 | void *kmem_cache_alloc(struct kmem_cache *c, gfp_t flags); |
183 | void *kmem_cache_zalloc(struct kmem_cache *, gfp_t); | ||
158 | void kmem_cache_free(struct kmem_cache *c, void *b); | 184 | void kmem_cache_free(struct kmem_cache *c, void *b); |
159 | const char *kmem_cache_name(struct kmem_cache *); | 185 | const char *kmem_cache_name(struct kmem_cache *); |
160 | void *kmalloc(size_t size, gfp_t flags); | 186 | void *kmalloc(size_t size, gfp_t flags); |
161 | void *kzalloc(size_t size, gfp_t flags); | 187 | void *__kzalloc(size_t size, gfp_t flags); |
162 | void kfree(const void *m); | 188 | void kfree(const void *m); |
163 | unsigned int ksize(const void *m); | 189 | unsigned int ksize(const void *m); |
164 | unsigned int kmem_cache_size(struct kmem_cache *c); | 190 | unsigned int kmem_cache_size(struct kmem_cache *c); |
165 | 191 | ||
166 | static inline void *kcalloc(size_t n, size_t size, gfp_t flags) | 192 | static inline void *kcalloc(size_t n, size_t size, gfp_t flags) |
167 | { | 193 | { |
168 | return kzalloc(n * size, flags); | 194 | return __kzalloc(n * size, flags); |
169 | } | 195 | } |
170 | 196 | ||
171 | #define kmem_cache_shrink(d) (0) | 197 | #define kmem_cache_shrink(d) (0) |
@@ -173,6 +199,8 @@ static inline void *kcalloc(size_t n, size_t size, gfp_t flags) | |||
173 | #define kmem_ptr_validate(a, b) (0) | 199 | #define kmem_ptr_validate(a, b) (0) |
174 | #define kmem_cache_alloc_node(c, f, n) kmem_cache_alloc(c, f) | 200 | #define kmem_cache_alloc_node(c, f, n) kmem_cache_alloc(c, f) |
175 | #define kmalloc_node(s, f, n) kmalloc(s, f) | 201 | #define kmalloc_node(s, f, n) kmalloc(s, f) |
202 | #define kzalloc(s, f) __kzalloc(s, f) | ||
203 | #define ____kmalloc kmalloc | ||
176 | 204 | ||
177 | #endif /* CONFIG_SLOB */ | 205 | #endif /* CONFIG_SLOB */ |
178 | 206 | ||
@@ -182,7 +210,6 @@ extern kmem_cache_t *names_cachep; | |||
182 | extern kmem_cache_t *files_cachep; | 210 | extern kmem_cache_t *files_cachep; |
183 | extern kmem_cache_t *filp_cachep; | 211 | extern kmem_cache_t *filp_cachep; |
184 | extern kmem_cache_t *fs_cachep; | 212 | extern kmem_cache_t *fs_cachep; |
185 | extern kmem_cache_t *signal_cachep; | ||
186 | extern kmem_cache_t *sighand_cachep; | 213 | extern kmem_cache_t *sighand_cachep; |
187 | extern kmem_cache_t *bio_cachep; | 214 | extern kmem_cache_t *bio_cachep; |
188 | 215 | ||