aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/slab.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r--include/linux/slab.h43
1 files changed, 35 insertions, 8 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 8cf52939d0ab..3af03b19c983 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -38,7 +38,6 @@ typedef struct kmem_cache kmem_cache_t;
38#define SLAB_DEBUG_INITIAL 0x00000200UL /* Call constructor (as verifier) */ 38#define SLAB_DEBUG_INITIAL 0x00000200UL /* Call constructor (as verifier) */
39#define SLAB_RED_ZONE 0x00000400UL /* Red zone objs in a cache */ 39#define SLAB_RED_ZONE 0x00000400UL /* Red zone objs in a cache */
40#define SLAB_POISON 0x00000800UL /* Poison objects */ 40#define SLAB_POISON 0x00000800UL /* Poison objects */
41#define SLAB_NO_REAP 0x00001000UL /* never reap from the cache */
42#define SLAB_HWCACHE_ALIGN 0x00002000UL /* align objs on a h/w cache lines */ 41#define SLAB_HWCACHE_ALIGN 0x00002000UL /* align objs on a h/w cache lines */
43#define SLAB_CACHE_DMA 0x00004000UL /* use GFP_DMA memory */ 42#define SLAB_CACHE_DMA 0x00004000UL /* use GFP_DMA memory */
44#define SLAB_MUST_HWCACHE_ALIGN 0x00008000UL /* force alignment */ 43#define SLAB_MUST_HWCACHE_ALIGN 0x00008000UL /* force alignment */
@@ -47,6 +46,7 @@ typedef struct kmem_cache kmem_cache_t;
47 what is reclaimable later*/ 46 what is reclaimable later*/
48#define SLAB_PANIC 0x00040000UL /* panic if kmem_cache_create() fails */ 47#define SLAB_PANIC 0x00040000UL /* panic if kmem_cache_create() fails */
49#define SLAB_DESTROY_BY_RCU 0x00080000UL /* defer freeing pages to RCU */ 48#define SLAB_DESTROY_BY_RCU 0x00080000UL /* defer freeing pages to RCU */
49#define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */
50 50
51/* flags passed to a constructor func */ 51/* flags passed to a constructor func */
52#define SLAB_CTOR_CONSTRUCTOR 0x001UL /* if not set, then deconstructor */ 52#define SLAB_CTOR_CONSTRUCTOR 0x001UL /* if not set, then deconstructor */
@@ -64,6 +64,7 @@ extern kmem_cache_t *kmem_cache_create(const char *, size_t, size_t, unsigned lo
64extern int kmem_cache_destroy(kmem_cache_t *); 64extern int kmem_cache_destroy(kmem_cache_t *);
65extern int kmem_cache_shrink(kmem_cache_t *); 65extern int kmem_cache_shrink(kmem_cache_t *);
66extern void *kmem_cache_alloc(kmem_cache_t *, gfp_t); 66extern void *kmem_cache_alloc(kmem_cache_t *, gfp_t);
67extern void *kmem_cache_zalloc(struct kmem_cache *, gfp_t);
67extern void kmem_cache_free(kmem_cache_t *, void *); 68extern void kmem_cache_free(kmem_cache_t *, void *);
68extern unsigned int kmem_cache_size(kmem_cache_t *); 69extern unsigned int kmem_cache_size(kmem_cache_t *);
69extern const char *kmem_cache_name(kmem_cache_t *); 70extern const char *kmem_cache_name(kmem_cache_t *);
@@ -77,11 +78,12 @@ struct cache_sizes {
77}; 78};
78extern struct cache_sizes malloc_sizes[]; 79extern struct cache_sizes malloc_sizes[];
79 80
80#ifndef CONFIG_DEBUG_SLAB
81extern void *__kmalloc(size_t, gfp_t); 81extern void *__kmalloc(size_t, gfp_t);
82#ifndef CONFIG_DEBUG_SLAB
83#define ____kmalloc(size, flags) __kmalloc(size, flags)
82#else 84#else
83extern void *__kmalloc_track_caller(size_t, gfp_t, void*); 85extern 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
111extern void *kzalloc(size_t, gfp_t); 113extern void *__kzalloc(size_t, gfp_t);
114
115static 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 }
130found:
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.
@@ -118,7 +143,7 @@ extern void *kzalloc(size_t, gfp_t);
118 */ 143 */
119static inline void *kcalloc(size_t n, size_t size, gfp_t flags) 144static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
120{ 145{
121 if (n != 0 && size > INT_MAX / n) 146 if (n != 0 && size > ULONG_MAX / n)
122 return NULL; 147 return NULL;
123 return kzalloc(n * size, flags); 148 return kzalloc(n * size, flags);
124} 149}
@@ -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));
156int kmem_cache_destroy(struct kmem_cache *c); 181int kmem_cache_destroy(struct kmem_cache *c);
157void *kmem_cache_alloc(struct kmem_cache *c, gfp_t flags); 182void *kmem_cache_alloc(struct kmem_cache *c, gfp_t flags);
183void *kmem_cache_zalloc(struct kmem_cache *, gfp_t);
158void kmem_cache_free(struct kmem_cache *c, void *b); 184void kmem_cache_free(struct kmem_cache *c, void *b);
159const char *kmem_cache_name(struct kmem_cache *); 185const char *kmem_cache_name(struct kmem_cache *);
160void *kmalloc(size_t size, gfp_t flags); 186void *kmalloc(size_t size, gfp_t flags);
161void *kzalloc(size_t size, gfp_t flags); 187void *__kzalloc(size_t size, gfp_t flags);
162void kfree(const void *m); 188void kfree(const void *m);
163unsigned int ksize(const void *m); 189unsigned int ksize(const void *m);
164unsigned int kmem_cache_size(struct kmem_cache *c); 190unsigned int kmem_cache_size(struct kmem_cache *c);
165 191
166static inline void *kcalloc(size_t n, size_t size, gfp_t flags) 192static 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;
182extern kmem_cache_t *files_cachep; 210extern kmem_cache_t *files_cachep;
183extern kmem_cache_t *filp_cachep; 211extern kmem_cache_t *filp_cachep;
184extern kmem_cache_t *fs_cachep; 212extern kmem_cache_t *fs_cachep;
185extern kmem_cache_t *signal_cachep;
186extern kmem_cache_t *sighand_cachep; 213extern kmem_cache_t *sighand_cachep;
187extern kmem_cache_t *bio_cachep; 214extern kmem_cache_t *bio_cachep;
188 215