diff options
Diffstat (limited to 'include/linux/slab_def.h')
| -rw-r--r-- | include/linux/slab_def.h | 54 |
1 files changed, 17 insertions, 37 deletions
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 8bb6e0eaf3c6..cd401580bdd3 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h | |||
| @@ -11,8 +11,6 @@ | |||
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include <linux/init.h> | 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> | 14 | #include <linux/compiler.h> |
| 17 | 15 | ||
| 18 | /* | 16 | /* |
| @@ -97,23 +95,13 @@ struct kmem_cache { | |||
| 97 | * pointer for each node since "nodelists" uses the remainder of | 95 | * pointer for each node since "nodelists" uses the remainder of |
| 98 | * available pointers. | 96 | * available pointers. |
| 99 | */ | 97 | */ |
| 100 | struct kmem_list3 **nodelists; | 98 | struct kmem_cache_node **node; |
| 101 | struct array_cache *array[NR_CPUS + MAX_NUMNODES]; | 99 | struct array_cache *array[NR_CPUS + MAX_NUMNODES]; |
| 102 | /* | 100 | /* |
| 103 | * Do not add fields after array[] | 101 | * Do not add fields after array[] |
| 104 | */ | 102 | */ |
| 105 | }; | 103 | }; |
| 106 | 104 | ||
| 107 | /* Size description struct for general caches. */ | ||
| 108 | struct cache_sizes { | ||
| 109 | size_t cs_size; | ||
| 110 | struct kmem_cache *cs_cachep; | ||
| 111 | #ifdef CONFIG_ZONE_DMA | ||
| 112 | struct kmem_cache *cs_dmacachep; | ||
| 113 | #endif | ||
| 114 | }; | ||
| 115 | extern struct cache_sizes malloc_sizes[]; | ||
| 116 | |||
| 117 | void *kmem_cache_alloc(struct kmem_cache *, gfp_t); | 105 | void *kmem_cache_alloc(struct kmem_cache *, gfp_t); |
| 118 | void *__kmalloc(size_t size, gfp_t flags); | 106 | void *__kmalloc(size_t size, gfp_t flags); |
| 119 | 107 | ||
| @@ -133,26 +121,22 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags) | |||
| 133 | void *ret; | 121 | void *ret; |
| 134 | 122 | ||
| 135 | if (__builtin_constant_p(size)) { | 123 | if (__builtin_constant_p(size)) { |
| 136 | int i = 0; | 124 | int i; |
| 137 | 125 | ||
| 138 | if (!size) | 126 | if (!size) |
| 139 | return ZERO_SIZE_PTR; | 127 | return ZERO_SIZE_PTR; |
| 140 | 128 | ||
| 141 | #define CACHE(x) \ | 129 | if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE)) |
| 142 | if (size <= x) \ | 130 | return NULL; |
| 143 | goto found; \ | 131 | |
| 144 | else \ | 132 | i = kmalloc_index(size); |
| 145 | i++; | 133 | |
| 146 | #include <linux/kmalloc_sizes.h> | ||
| 147 | #undef CACHE | ||
| 148 | return NULL; | ||
| 149 | found: | ||
| 150 | #ifdef CONFIG_ZONE_DMA | 134 | #ifdef CONFIG_ZONE_DMA |
| 151 | if (flags & GFP_DMA) | 135 | if (flags & GFP_DMA) |
| 152 | cachep = malloc_sizes[i].cs_dmacachep; | 136 | cachep = kmalloc_dma_caches[i]; |
| 153 | else | 137 | else |
| 154 | #endif | 138 | #endif |
| 155 | cachep = malloc_sizes[i].cs_cachep; | 139 | cachep = kmalloc_caches[i]; |
| 156 | 140 | ||
| 157 | ret = kmem_cache_alloc_trace(cachep, flags, size); | 141 | ret = kmem_cache_alloc_trace(cachep, flags, size); |
| 158 | 142 | ||
| @@ -186,26 +170,22 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) | |||
| 186 | struct kmem_cache *cachep; | 170 | struct kmem_cache *cachep; |
| 187 | 171 | ||
| 188 | if (__builtin_constant_p(size)) { | 172 | if (__builtin_constant_p(size)) { |
| 189 | int i = 0; | 173 | int i; |
| 190 | 174 | ||
| 191 | if (!size) | 175 | if (!size) |
| 192 | return ZERO_SIZE_PTR; | 176 | return ZERO_SIZE_PTR; |
| 193 | 177 | ||
| 194 | #define CACHE(x) \ | 178 | if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE)) |
| 195 | if (size <= x) \ | 179 | return NULL; |
| 196 | goto found; \ | 180 | |
| 197 | else \ | 181 | i = kmalloc_index(size); |
| 198 | i++; | 182 | |
| 199 | #include <linux/kmalloc_sizes.h> | ||
| 200 | #undef CACHE | ||
| 201 | return NULL; | ||
| 202 | found: | ||
| 203 | #ifdef CONFIG_ZONE_DMA | 183 | #ifdef CONFIG_ZONE_DMA |
| 204 | if (flags & GFP_DMA) | 184 | if (flags & GFP_DMA) |
| 205 | cachep = malloc_sizes[i].cs_dmacachep; | 185 | cachep = kmalloc_dma_caches[i]; |
| 206 | else | 186 | else |
| 207 | #endif | 187 | #endif |
| 208 | cachep = malloc_sizes[i].cs_cachep; | 188 | cachep = kmalloc_caches[i]; |
| 209 | 189 | ||
| 210 | return kmem_cache_alloc_node_trace(cachep, flags, node, size); | 190 | return kmem_cache_alloc_node_trace(cachep, flags, node, size); |
| 211 | } | 191 | } |
