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.h92
1 files changed, 49 insertions, 43 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h
index c4947b8a2c03..2271886744f8 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -7,27 +7,17 @@
7#ifndef _LINUX_SLAB_H 7#ifndef _LINUX_SLAB_H
8#define _LINUX_SLAB_H 8#define _LINUX_SLAB_H
9 9
10#if defined(__KERNEL__) 10#ifdef __KERNEL__
11 11
12typedef struct kmem_cache kmem_cache_t; 12#include <linux/gfp.h>
13#include <linux/init.h>
14#include <linux/types.h>
15#include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */
16#include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */
17#include <linux/compiler.h>
13 18
14#include <linux/gfp.h> 19/* kmem_cache_t exists for legacy reasons and is not used by code in mm */
15#include <linux/init.h> 20typedef struct kmem_cache kmem_cache_t __deprecated;
16#include <linux/types.h>
17#include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */
18#include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */
19
20/* flags for kmem_cache_alloc() */
21#define SLAB_NOFS GFP_NOFS
22#define SLAB_NOIO GFP_NOIO
23#define SLAB_ATOMIC GFP_ATOMIC
24#define SLAB_USER GFP_USER
25#define SLAB_KERNEL GFP_KERNEL
26#define SLAB_DMA GFP_DMA
27
28#define SLAB_LEVEL_MASK GFP_LEVEL_MASK
29
30#define SLAB_NO_GROW __GFP_NO_GROW /* don't grow a cache */
31 21
32/* flags to pass to kmem_cache_create(). 22/* flags to pass to kmem_cache_create().
33 * The first 3 are only valid when the allocator as been build 23 * The first 3 are only valid when the allocator as been build
@@ -57,22 +47,23 @@ typedef struct kmem_cache kmem_cache_t;
57/* prototypes */ 47/* prototypes */
58extern void __init kmem_cache_init(void); 48extern void __init kmem_cache_init(void);
59 49
60extern kmem_cache_t *kmem_cache_create(const char *, size_t, size_t, unsigned long, 50extern struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
61 void (*)(void *, kmem_cache_t *, unsigned long), 51 unsigned long,
62 void (*)(void *, kmem_cache_t *, unsigned long)); 52 void (*)(void *, struct kmem_cache *, unsigned long),
63extern void kmem_cache_destroy(kmem_cache_t *); 53 void (*)(void *, struct kmem_cache *, unsigned long));
64extern int kmem_cache_shrink(kmem_cache_t *); 54extern void kmem_cache_destroy(struct kmem_cache *);
65extern void *kmem_cache_alloc(kmem_cache_t *, gfp_t); 55extern int kmem_cache_shrink(struct kmem_cache *);
56extern void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66extern void *kmem_cache_zalloc(struct kmem_cache *, gfp_t); 57extern void *kmem_cache_zalloc(struct kmem_cache *, gfp_t);
67extern void kmem_cache_free(kmem_cache_t *, void *); 58extern void kmem_cache_free(struct kmem_cache *, void *);
68extern unsigned int kmem_cache_size(kmem_cache_t *); 59extern unsigned int kmem_cache_size(struct kmem_cache *);
69extern const char *kmem_cache_name(kmem_cache_t *); 60extern const char *kmem_cache_name(struct kmem_cache *);
70 61
71/* Size description struct for general caches. */ 62/* Size description struct for general caches. */
72struct cache_sizes { 63struct cache_sizes {
73 size_t cs_size; 64 size_t cs_size;
74 kmem_cache_t *cs_cachep; 65 struct kmem_cache *cs_cachep;
75 kmem_cache_t *cs_dmacachep; 66 struct kmem_cache *cs_dmacachep;
76}; 67};
77extern struct cache_sizes malloc_sizes[]; 68extern struct cache_sizes malloc_sizes[];
78 69
@@ -211,7 +202,7 @@ extern unsigned int ksize(const void *);
211extern int slab_is_available(void); 202extern int slab_is_available(void);
212 203
213#ifdef CONFIG_NUMA 204#ifdef CONFIG_NUMA
214extern void *kmem_cache_alloc_node(kmem_cache_t *, gfp_t flags, int node); 205extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
215extern void *__kmalloc_node(size_t size, gfp_t flags, int node); 206extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
216 207
217static inline void *kmalloc_node(size_t size, gfp_t flags, int node) 208static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
@@ -236,8 +227,27 @@ found:
236 } 227 }
237 return __kmalloc_node(size, flags, node); 228 return __kmalloc_node(size, flags, node);
238} 229}
230
231/*
232 * kmalloc_node_track_caller is a special version of kmalloc_node that
233 * records the calling function of the routine calling it for slab leak
234 * tracking instead of just the calling function (confusing, eh?).
235 * It's useful when the call to kmalloc_node comes from a widely-used
236 * standard allocator where we care about the real place the memory
237 * allocation request comes from.
238 */
239#ifndef CONFIG_DEBUG_SLAB
240#define kmalloc_node_track_caller(size, flags, node) \
241 __kmalloc_node(size, flags, node)
239#else 242#else
240static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int node) 243extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, void *);
244#define kmalloc_node_track_caller(size, flags, node) \
245 __kmalloc_node_track_caller(size, flags, node, \
246 __builtin_return_address(0))
247#endif
248#else /* CONFIG_NUMA */
249static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
250 gfp_t flags, int node)
241{ 251{
242 return kmem_cache_alloc(cachep, flags); 252 return kmem_cache_alloc(cachep, flags);
243} 253}
@@ -245,10 +255,13 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
245{ 255{
246 return kmalloc(size, flags); 256 return kmalloc(size, flags);
247} 257}
258
259#define kmalloc_node_track_caller(size, flags, node) \
260 kmalloc_track_caller(size, flags)
248#endif 261#endif
249 262
250extern int FASTCALL(kmem_cache_reap(int)); 263extern int FASTCALL(kmem_cache_reap(int));
251extern int FASTCALL(kmem_ptr_validate(kmem_cache_t *cachep, void *ptr)); 264extern int FASTCALL(kmem_ptr_validate(struct kmem_cache *cachep, void *ptr));
252 265
253#else /* CONFIG_SLOB */ 266#else /* CONFIG_SLOB */
254 267
@@ -283,16 +296,9 @@ static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
283#define kzalloc(s, f) __kzalloc(s, f) 296#define kzalloc(s, f) __kzalloc(s, f)
284#define kmalloc_track_caller kmalloc 297#define kmalloc_track_caller kmalloc
285 298
286#endif /* CONFIG_SLOB */ 299#define kmalloc_node_track_caller kmalloc_node
287 300
288/* System wide caches */ 301#endif /* CONFIG_SLOB */
289extern kmem_cache_t *vm_area_cachep;
290extern kmem_cache_t *names_cachep;
291extern kmem_cache_t *files_cachep;
292extern kmem_cache_t *filp_cachep;
293extern kmem_cache_t *fs_cachep;
294extern kmem_cache_t *sighand_cachep;
295extern kmem_cache_t *bio_cachep;
296 302
297#endif /* __KERNEL__ */ 303#endif /* __KERNEL__ */
298 304