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>
25 /* 1) Cache tunables. Protected by cache_chain_mutex */
26 unsigned int batchcount
;
30 unsigned int buffer_size
;
31 u32 reciprocal_buffer_size
;
32 /* 2) touched by every alloc & free from the backend */
34 unsigned int flags
; /* constant flags */
35 unsigned int num
; /* # of objs per slab */
37 /* 3) cache_grow/shrink */
38 /* order of pgs per slab (2^n) */
39 unsigned int gfporder
;
41 /* force GFP flags, e.g. GFP_DMA */
44 size_t colour
; /* cache colouring range */
45 unsigned int colour_off
; /* colour offset */
46 struct kmem_cache
*slabp_cache
;
47 unsigned int slab_size
;
48 unsigned int dflags
; /* dynamic flags */
50 /* constructor func */
51 void (*ctor
)(void *obj
);
53 /* 4) cache creation/removal */
55 struct list_head next
;
58 #ifdef CONFIG_DEBUG_SLAB
59 unsigned long num_active
;
60 unsigned long num_allocations
;
61 unsigned long high_mark
;
65 unsigned long max_freeable
;
66 unsigned long node_allocs
;
67 unsigned long node_frees
;
68 unsigned long node_overflow
;
75 * If debugging is enabled, then the allocator can add additional
76 * fields and/or padding to every object. buffer_size contains the total
77 * object size including these internal fields, the following two
78 * variables contain the offset to the user object and its size.
82 #endif /* CONFIG_DEBUG_SLAB */
84 /* 6) per-cpu/per-node data, touched during every alloc/free */
86 * We put array[] at the end of kmem_cache, because we want to size
87 * this array to nr_cpu_ids slots instead of NR_CPUS
88 * (see kmem_cache_init())
89 * We still use [NR_CPUS] and not [1] or [0] because cache_cache
90 * is statically defined, so we reserve the max number of cpus.
92 struct kmem_list3
**nodelists
;
93 struct array_cache
*array
[NR_CPUS
];
95 * Do not add fields after array[]
99 /* Size description struct for general caches. */
102 struct kmem_cache
*cs_cachep
;
103 #ifdef CONFIG_ZONE_DMA
104 struct kmem_cache
*cs_dmacachep
;
107 extern struct cache_sizes malloc_sizes
[];
109 void *kmem_cache_alloc(struct kmem_cache
*, gfp_t
);
110 void *__kmalloc(size_t size
, gfp_t flags
);
112 #ifdef CONFIG_TRACING
113 extern void *kmem_cache_alloc_trace(size_t size
,
114 struct kmem_cache
*cachep
, gfp_t flags
);
115 extern size_t slab_buffer_size(struct kmem_cache
*cachep
);
117 static __always_inline
void *
118 kmem_cache_alloc_trace(size_t size
, struct kmem_cache
*cachep
, gfp_t flags
)
120 return kmem_cache_alloc(cachep
, flags
);
122 static inline size_t slab_buffer_size(struct kmem_cache
*cachep
)
128 static __always_inline
void *kmalloc(size_t size
, gfp_t flags
)
130 struct kmem_cache
*cachep
;
133 if (__builtin_constant_p(size
)) {
137 return ZERO_SIZE_PTR
;
144 #include <linux/kmalloc_sizes.h>
148 #ifdef CONFIG_ZONE_DMA
150 cachep
= malloc_sizes
[i
].cs_dmacachep
;
153 cachep
= malloc_sizes
[i
].cs_cachep
;
155 ret
= kmem_cache_alloc_trace(size
, cachep
, flags
);
159 return __kmalloc(size
, flags
);
163 extern void *__kmalloc_node(size_t size
, gfp_t flags
, int node
);
164 extern void *kmem_cache_alloc_node(struct kmem_cache
*, gfp_t flags
, int node
);
166 #ifdef CONFIG_TRACING
167 extern void *kmem_cache_alloc_node_trace(size_t size
,
168 struct kmem_cache
*cachep
,
172 static __always_inline
void *
173 kmem_cache_alloc_node_trace(size_t size
,
174 struct kmem_cache
*cachep
,
178 return kmem_cache_alloc_node(cachep
, flags
, nodeid
);
182 static __always_inline
void *kmalloc_node(size_t size
, gfp_t flags
, int node
)
184 struct kmem_cache
*cachep
;
186 if (__builtin_constant_p(size
)) {
190 return ZERO_SIZE_PTR
;
197 #include <linux/kmalloc_sizes.h>
201 #ifdef CONFIG_ZONE_DMA
203 cachep
= malloc_sizes
[i
].cs_dmacachep
;
206 cachep
= malloc_sizes
[i
].cs_cachep
;
208 return kmem_cache_alloc_node_trace(size
, cachep
, flags
, node
);
210 return __kmalloc_node(size
, flags
, node
);
213 #endif /* CONFIG_NUMA */
215 #endif /* _LINUX_SLAB_DEF_H */