1#ifndef _LINUX_SLAB_DEF_H
2#define _LINUX_SLAB_DEF_H
3
4
5
6
7
8
9
10
11
12
13#include <linux/init.h>
14#include <asm/page.h>
15#include <asm/cache.h>
16#include <linux/compiler.h>
17
18
19
20
21
22
23
24struct kmem_cache {
25
26 unsigned int batchcount;
27 unsigned int limit;
28 unsigned int shared;
29
30 unsigned int size;
31 u32 reciprocal_buffer_size;
32
33
34 unsigned int flags;
35 unsigned int num;
36
37
38
39 unsigned int gfporder;
40
41
42 gfp_t allocflags;
43
44 size_t colour;
45 unsigned int colour_off;
46 struct kmem_cache *slabp_cache;
47 unsigned int slab_size;
48
49
50 void (*ctor)(void *obj);
51
52
53 const char *name;
54 struct list_head list;
55 int refcount;
56 int object_size;
57 int align;
58
59
60#ifdef CONFIG_DEBUG_SLAB
61 unsigned long num_active;
62 unsigned long num_allocations;
63 unsigned long high_mark;
64 unsigned long grown;
65 unsigned long reaped;
66 unsigned long errors;
67 unsigned long max_freeable;
68 unsigned long node_allocs;
69 unsigned long node_frees;
70 unsigned long node_overflow;
71 atomic_t allochit;
72 atomic_t allocmiss;
73 atomic_t freehit;
74 atomic_t freemiss;
75
76
77
78
79
80
81
82 int obj_offset;
83#endif
84
85
86
87
88
89
90
91
92
93 struct kmem_list3 **nodelists;
94 struct array_cache *array[NR_CPUS];
95
96
97
98};
99
100
101struct cache_sizes {
102 size_t cs_size;
103 struct kmem_cache *cs_cachep;
104#ifdef CONFIG_ZONE_DMA
105 struct kmem_cache *cs_dmacachep;
106#endif
107};
108extern struct cache_sizes malloc_sizes[];
109
110void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
111void *__kmalloc(size_t size, gfp_t flags);
112
113#ifdef CONFIG_TRACING
114extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
115#else
116static __always_inline void *
117kmem_cache_alloc_trace(struct kmem_cache *cachep, gfp_t flags, size_t size)
118{
119 return kmem_cache_alloc(cachep, flags);
120}
121#endif
122
123static __always_inline void *kmalloc(size_t size, gfp_t flags)
124{
125 struct kmem_cache *cachep;
126 void *ret;
127
128 if (__builtin_constant_p(size)) {
129 int i = 0;
130
131 if (!size)
132 return ZERO_SIZE_PTR;
133
134#define CACHE(x) \
135 if (size <= x) \
136 goto found; \
137 else \
138 i++;
139#include <linux/kmalloc_sizes.h>
140#undef CACHE
141 return NULL;
142found:
143#ifdef CONFIG_ZONE_DMA
144 if (flags & GFP_DMA)
145 cachep = malloc_sizes[i].cs_dmacachep;
146 else
147#endif
148 cachep = malloc_sizes[i].cs_cachep;
149
150 ret = kmem_cache_alloc_trace(cachep, flags, size);
151
152 return ret;
153 }
154 return __kmalloc(size, flags);
155}
156
157#ifdef CONFIG_NUMA
158extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
159extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
160
161#ifdef CONFIG_TRACING
162extern void *kmem_cache_alloc_node_trace(struct kmem_cache *cachep,
163 gfp_t flags,
164 int nodeid,
165 size_t size);
166#else
167static __always_inline void *
168kmem_cache_alloc_node_trace(struct kmem_cache *cachep,
169 gfp_t flags,
170 int nodeid,
171 size_t size)
172{
173 return kmem_cache_alloc_node(cachep, flags, nodeid);
174}
175#endif
176
177static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
178{
179 struct kmem_cache *cachep;
180
181 if (__builtin_constant_p(size)) {
182 int i = 0;
183
184 if (!size)
185 return ZERO_SIZE_PTR;
186
187#define CACHE(x) \
188 if (size <= x) \
189 goto found; \
190 else \
191 i++;
192#include <linux/kmalloc_sizes.h>
193#undef CACHE
194 return NULL;
195found:
196#ifdef CONFIG_ZONE_DMA
197 if (flags & GFP_DMA)
198 cachep = malloc_sizes[i].cs_dmacachep;
199 else
200#endif
201 cachep = malloc_sizes[i].cs_cachep;
202
203 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
204 }
205 return __kmalloc_node(size, flags, node);
206}
207
208#endif
209
210#endif
211