Commit | Line | Data |
---|---|---|
2e892f43 CL |
1 | #ifndef _LINUX_SLAB_DEF_H |
2 | #define _LINUX_SLAB_DEF_H | |
3 | ||
4 | /* | |
5 | * Definitions unique to the original Linux SLAB allocator. | |
6 | * | |
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. | |
11 | */ | |
12 | ||
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> | |
17 | ||
18 | /* Size description struct for general caches. */ | |
19 | struct cache_sizes { | |
20 | size_t cs_size; | |
21 | struct kmem_cache *cs_cachep; | |
4b51d669 | 22 | #ifdef CONFIG_ZONE_DMA |
2e892f43 | 23 | struct kmem_cache *cs_dmacachep; |
4b51d669 | 24 | #endif |
2e892f43 CL |
25 | }; |
26 | extern struct cache_sizes malloc_sizes[]; | |
27 | ||
6193a2ff PM |
28 | void *kmem_cache_alloc(struct kmem_cache *, gfp_t); |
29 | void *__kmalloc(size_t size, gfp_t flags); | |
30 | ||
2e892f43 CL |
31 | static inline void *kmalloc(size_t size, gfp_t flags) |
32 | { | |
33 | if (__builtin_constant_p(size)) { | |
34 | int i = 0; | |
6cb8f913 CL |
35 | |
36 | if (!size) | |
37 | return ZERO_SIZE_PTR; | |
38 | ||
2e892f43 CL |
39 | #define CACHE(x) \ |
40 | if (size <= x) \ | |
41 | goto found; \ | |
42 | else \ | |
43 | i++; | |
44 | #include "kmalloc_sizes.h" | |
45 | #undef CACHE | |
46 | { | |
47 | extern void __you_cannot_kmalloc_that_much(void); | |
48 | __you_cannot_kmalloc_that_much(); | |
49 | } | |
50 | found: | |
4b51d669 CL |
51 | #ifdef CONFIG_ZONE_DMA |
52 | if (flags & GFP_DMA) | |
53 | return kmem_cache_alloc(malloc_sizes[i].cs_dmacachep, | |
54 | flags); | |
55 | #endif | |
56 | return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags); | |
2e892f43 CL |
57 | } |
58 | return __kmalloc(size, flags); | |
59 | } | |
60 | ||
2e892f43 CL |
61 | #ifdef CONFIG_NUMA |
62 | extern void *__kmalloc_node(size_t size, gfp_t flags, int node); | |
6193a2ff | 63 | extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); |
2e892f43 CL |
64 | |
65 | static inline void *kmalloc_node(size_t size, gfp_t flags, int node) | |
66 | { | |
67 | if (__builtin_constant_p(size)) { | |
68 | int i = 0; | |
6cb8f913 CL |
69 | |
70 | if (!size) | |
71 | return ZERO_SIZE_PTR; | |
72 | ||
2e892f43 CL |
73 | #define CACHE(x) \ |
74 | if (size <= x) \ | |
75 | goto found; \ | |
76 | else \ | |
77 | i++; | |
78 | #include "kmalloc_sizes.h" | |
79 | #undef CACHE | |
80 | { | |
81 | extern void __you_cannot_kmalloc_that_much(void); | |
82 | __you_cannot_kmalloc_that_much(); | |
83 | } | |
84 | found: | |
4b51d669 CL |
85 | #ifdef CONFIG_ZONE_DMA |
86 | if (flags & GFP_DMA) | |
87 | return kmem_cache_alloc_node(malloc_sizes[i].cs_dmacachep, | |
88 | flags, node); | |
89 | #endif | |
90 | return kmem_cache_alloc_node(malloc_sizes[i].cs_cachep, | |
91 | flags, node); | |
2e892f43 CL |
92 | } |
93 | return __kmalloc_node(size, flags, node); | |
94 | } | |
95 | ||
96 | #endif /* CONFIG_NUMA */ | |
97 | ||
3ca12ee5 CL |
98 | extern const struct seq_operations slabinfo_op; |
99 | ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *); | |
100 | ||
2e892f43 | 101 | #endif /* _LINUX_SLAB_DEF_H */ |