Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / include / linux / slab_def.h
blob322876fad975f38d36d9963029438126f11dd98b
1 #ifndef _LINUX_SLAB_DEF_H
2 #define _LINUX_SLAB_DEF_H
4 /*
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
10 * compile time.
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>
18 /* Size description struct for general caches. */
19 struct cache_sizes {
20 size_t cs_size;
21 struct kmem_cache *cs_cachep;
22 #ifdef CONFIG_ZONE_DMA
23 struct kmem_cache *cs_dmacachep;
24 #endif
26 extern struct cache_sizes malloc_sizes[];
28 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
29 void *__kmalloc(size_t size, gfp_t flags);
31 static inline void *kmalloc(size_t size, gfp_t flags)
33 if (__builtin_constant_p(size)) {
34 int i = 0;
36 if (!size)
37 return ZERO_SIZE_PTR;
39 #define CACHE(x) \
40 if (size <= x) \
41 goto found; \
42 else \
43 i++;
44 <<<<<<< HEAD:include/linux/slab_def.h
45 #include "kmalloc_sizes.h"
46 =======
47 #include <linux/kmalloc_sizes.h>
48 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/linux/slab_def.h
49 #undef CACHE
51 extern void __you_cannot_kmalloc_that_much(void);
52 __you_cannot_kmalloc_that_much();
54 found:
55 #ifdef CONFIG_ZONE_DMA
56 if (flags & GFP_DMA)
57 return kmem_cache_alloc(malloc_sizes[i].cs_dmacachep,
58 flags);
59 #endif
60 return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags);
62 return __kmalloc(size, flags);
65 #ifdef CONFIG_NUMA
66 extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
69 static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71 if (__builtin_constant_p(size)) {
72 int i = 0;
74 if (!size)
75 return ZERO_SIZE_PTR;
77 #define CACHE(x) \
78 if (size <= x) \
79 goto found; \
80 else \
81 i++;
82 <<<<<<< HEAD:include/linux/slab_def.h
83 #include "kmalloc_sizes.h"
84 =======
85 #include <linux/kmalloc_sizes.h>
86 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/linux/slab_def.h
87 #undef CACHE
89 extern void __you_cannot_kmalloc_that_much(void);
90 __you_cannot_kmalloc_that_much();
92 found:
93 #ifdef CONFIG_ZONE_DMA
94 if (flags & GFP_DMA)
95 return kmem_cache_alloc_node(malloc_sizes[i].cs_dmacachep,
96 flags, node);
97 #endif
98 return kmem_cache_alloc_node(malloc_sizes[i].cs_cachep,
99 flags, node);
101 return __kmalloc_node(size, flags, node);
104 #endif /* CONFIG_NUMA */
106 #endif /* _LINUX_SLAB_DEF_H */