diff options
| -rw-r--r-- | mm/slub.c | 66 |
1 files changed, 36 insertions, 30 deletions
| @@ -2272,6 +2272,40 @@ panic: | |||
| 2272 | panic("Creation of kmalloc slab %s size=%d failed.\n", name, size); | 2272 | panic("Creation of kmalloc slab %s size=%d failed.\n", name, size); |
| 2273 | } | 2273 | } |
| 2274 | 2274 | ||
| 2275 | #ifdef CONFIG_ZONE_DMA | ||
| 2276 | static noinline struct kmem_cache *dma_kmalloc_cache(int index, gfp_t flags) | ||
| 2277 | { | ||
| 2278 | struct kmem_cache *s; | ||
| 2279 | struct kmem_cache *x; | ||
| 2280 | char *text; | ||
| 2281 | size_t realsize; | ||
| 2282 | |||
| 2283 | s = kmalloc_caches_dma[index]; | ||
| 2284 | if (s) | ||
| 2285 | return s; | ||
| 2286 | |||
| 2287 | /* Dynamically create dma cache */ | ||
| 2288 | x = kmalloc(kmem_size, flags & ~SLUB_DMA); | ||
| 2289 | if (!x) | ||
| 2290 | panic("Unable to allocate memory for dma cache\n"); | ||
| 2291 | |||
| 2292 | if (index <= KMALLOC_SHIFT_HIGH) | ||
| 2293 | realsize = 1 << index; | ||
| 2294 | else { | ||
| 2295 | if (index == 1) | ||
| 2296 | realsize = 96; | ||
| 2297 | else | ||
| 2298 | realsize = 192; | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | text = kasprintf(flags & ~SLUB_DMA, "kmalloc_dma-%d", | ||
| 2302 | (unsigned int)realsize); | ||
| 2303 | s = create_kmalloc_cache(x, text, realsize, flags); | ||
| 2304 | kmalloc_caches_dma[index] = s; | ||
| 2305 | return s; | ||
| 2306 | } | ||
| 2307 | #endif | ||
| 2308 | |||
| 2275 | static struct kmem_cache *get_slab(size_t size, gfp_t flags) | 2309 | static struct kmem_cache *get_slab(size_t size, gfp_t flags) |
| 2276 | { | 2310 | { |
| 2277 | int index = kmalloc_index(size); | 2311 | int index = kmalloc_index(size); |
| @@ -2284,36 +2318,8 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags) | |||
| 2284 | return NULL; | 2318 | return NULL; |
| 2285 | 2319 | ||
| 2286 | #ifdef CONFIG_ZONE_DMA | 2320 | #ifdef CONFIG_ZONE_DMA |
| 2287 | if ((flags & SLUB_DMA)) { | 2321 | if ((flags & SLUB_DMA)) |
| 2288 | struct kmem_cache *s; | 2322 | return dma_kmalloc_cache(index, flags); |
| 2289 | struct kmem_cache *x; | ||
| 2290 | char *text; | ||
| 2291 | size_t realsize; | ||
| 2292 | |||
| 2293 | s = kmalloc_caches_dma[index]; | ||
| 2294 | if (s) | ||
| 2295 | return s; | ||
| 2296 | |||
| 2297 | /* Dynamically create dma cache */ | ||
| 2298 | x = kmalloc(kmem_size, flags & ~SLUB_DMA); | ||
| 2299 | if (!x) | ||
| 2300 | panic("Unable to allocate memory for dma cache\n"); | ||
| 2301 | |||
| 2302 | if (index <= KMALLOC_SHIFT_HIGH) | ||
| 2303 | realsize = 1 << index; | ||
| 2304 | else { | ||
| 2305 | if (index == 1) | ||
| 2306 | realsize = 96; | ||
| 2307 | else | ||
| 2308 | realsize = 192; | ||
| 2309 | } | ||
| 2310 | |||
| 2311 | text = kasprintf(flags & ~SLUB_DMA, "kmalloc_dma-%d", | ||
| 2312 | (unsigned int)realsize); | ||
| 2313 | s = create_kmalloc_cache(x, text, realsize, flags); | ||
| 2314 | kmalloc_caches_dma[index] = s; | ||
| 2315 | return s; | ||
| 2316 | } | ||
| 2317 | #endif | 2323 | #endif |
| 2318 | return &kmalloc_caches[index]; | 2324 | return &kmalloc_caches[index]; |
| 2319 | } | 2325 | } |
