diff options
Diffstat (limited to 'mm/slab.c')
-rw-r--r-- | mm/slab.c | 126 |
1 files changed, 36 insertions, 90 deletions
@@ -114,6 +114,7 @@ | |||
114 | #include <linux/rtmutex.h> | 114 | #include <linux/rtmutex.h> |
115 | #include <linux/reciprocal_div.h> | 115 | #include <linux/reciprocal_div.h> |
116 | #include <linux/debugobjects.h> | 116 | #include <linux/debugobjects.h> |
117 | #include <linux/kmemcheck.h> | ||
117 | 118 | ||
118 | #include <asm/cacheflush.h> | 119 | #include <asm/cacheflush.h> |
119 | #include <asm/tlbflush.h> | 120 | #include <asm/tlbflush.h> |
@@ -179,13 +180,13 @@ | |||
179 | SLAB_STORE_USER | \ | 180 | SLAB_STORE_USER | \ |
180 | SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ | 181 | SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ |
181 | SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \ | 182 | SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \ |
182 | SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE) | 183 | SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK) |
183 | #else | 184 | #else |
184 | # define CREATE_MASK (SLAB_HWCACHE_ALIGN | \ | 185 | # define CREATE_MASK (SLAB_HWCACHE_ALIGN | \ |
185 | SLAB_CACHE_DMA | \ | 186 | SLAB_CACHE_DMA | \ |
186 | SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ | 187 | SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ |
187 | SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \ | 188 | SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \ |
188 | SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE) | 189 | SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK) |
189 | #endif | 190 | #endif |
190 | 191 | ||
191 | /* | 192 | /* |
@@ -380,87 +381,6 @@ static void kmem_list3_init(struct kmem_list3 *parent) | |||
380 | MAKE_LIST((cachep), (&(ptr)->slabs_free), slabs_free, nodeid); \ | 381 | MAKE_LIST((cachep), (&(ptr)->slabs_free), slabs_free, nodeid); \ |
381 | } while (0) | 382 | } while (0) |
382 | 383 | ||
383 | /* | ||
384 | * struct kmem_cache | ||
385 | * | ||
386 | * manages a cache. | ||
387 | */ | ||
388 | |||
389 | struct kmem_cache { | ||
390 | /* 1) per-cpu data, touched during every alloc/free */ | ||
391 | struct array_cache *array[NR_CPUS]; | ||
392 | /* 2) Cache tunables. Protected by cache_chain_mutex */ | ||
393 | unsigned int batchcount; | ||
394 | unsigned int limit; | ||
395 | unsigned int shared; | ||
396 | |||
397 | unsigned int buffer_size; | ||
398 | u32 reciprocal_buffer_size; | ||
399 | /* 3) touched by every alloc & free from the backend */ | ||
400 | |||
401 | unsigned int flags; /* constant flags */ | ||
402 | unsigned int num; /* # of objs per slab */ | ||
403 | |||
404 | /* 4) cache_grow/shrink */ | ||
405 | /* order of pgs per slab (2^n) */ | ||
406 | unsigned int gfporder; | ||
407 | |||
408 | /* force GFP flags, e.g. GFP_DMA */ | ||
409 | gfp_t gfpflags; | ||
410 | |||
411 | size_t colour; /* cache colouring range */ | ||
412 | unsigned int colour_off; /* colour offset */ | ||
413 | struct kmem_cache *slabp_cache; | ||
414 | unsigned int slab_size; | ||
415 | unsigned int dflags; /* dynamic flags */ | ||
416 | |||
417 | /* constructor func */ | ||
418 | void (*ctor)(void *obj); | ||
419 | |||
420 | /* 5) cache creation/removal */ | ||
421 | const char *name; | ||
422 | struct list_head next; | ||
423 | |||
424 | /* 6) statistics */ | ||
425 | #if STATS | ||
426 | unsigned long num_active; | ||
427 | unsigned long num_allocations; | ||
428 | unsigned long high_mark; | ||
429 | unsigned long grown; | ||
430 | unsigned long reaped; | ||
431 | unsigned long errors; | ||
432 | unsigned long max_freeable; | ||
433 | unsigned long node_allocs; | ||
434 | unsigned long node_frees; | ||
435 | unsigned long node_overflow; | ||
436 | atomic_t allochit; | ||
437 | atomic_t allocmiss; | ||
438 | atomic_t freehit; | ||
439 | atomic_t freemiss; | ||
440 | #endif | ||
441 | #if DEBUG | ||
442 | /* | ||
443 | * If debugging is enabled, then the allocator can add additional | ||
444 | * fields and/or padding to every object. buffer_size contains the total | ||
445 | * object size including these internal fields, the following two | ||
446 | * variables contain the offset to the user object and its size. | ||
447 | */ | ||
448 | int obj_offset; | ||
449 | int obj_size; | ||
450 | #endif | ||
451 | /* | ||
452 | * We put nodelists[] at the end of kmem_cache, because we want to size | ||
453 | * this array to nr_node_ids slots instead of MAX_NUMNODES | ||
454 | * (see kmem_cache_init()) | ||
455 | * We still use [MAX_NUMNODES] and not [1] or [0] because cache_cache | ||
456 | * is statically defined, so we reserve the max number of nodes. | ||
457 | */ | ||
458 | struct kmem_list3 *nodelists[MAX_NUMNODES]; | ||
459 | /* | ||
460 | * Do not add fields after nodelists[] | ||
461 | */ | ||
462 | }; | ||
463 | |||
464 | #define CFLGS_OFF_SLAB (0x80000000UL) | 384 | #define CFLGS_OFF_SLAB (0x80000000UL) |
465 | #define OFF_SLAB(x) ((x)->flags & CFLGS_OFF_SLAB) | 385 | #define OFF_SLAB(x) ((x)->flags & CFLGS_OFF_SLAB) |
466 | 386 | ||
@@ -898,7 +818,6 @@ static void __slab_error(const char *function, struct kmem_cache *cachep, | |||
898 | */ | 818 | */ |
899 | 819 | ||
900 | static int use_alien_caches __read_mostly = 1; | 820 | static int use_alien_caches __read_mostly = 1; |
901 | static int numa_platform __read_mostly = 1; | ||
902 | static int __init noaliencache_setup(char *s) | 821 | static int __init noaliencache_setup(char *s) |
903 | { | 822 | { |
904 | use_alien_caches = 0; | 823 | use_alien_caches = 0; |
@@ -1457,10 +1376,8 @@ void __init kmem_cache_init(void) | |||
1457 | int order; | 1376 | int order; |
1458 | int node; | 1377 | int node; |
1459 | 1378 | ||
1460 | if (num_possible_nodes() == 1) { | 1379 | if (num_possible_nodes() == 1) |
1461 | use_alien_caches = 0; | 1380 | use_alien_caches = 0; |
1462 | numa_platform = 0; | ||
1463 | } | ||
1464 | 1381 | ||
1465 | for (i = 0; i < NUM_INIT_LISTS; i++) { | 1382 | for (i = 0; i < NUM_INIT_LISTS; i++) { |
1466 | kmem_list3_init(&initkmem_list3[i]); | 1383 | kmem_list3_init(&initkmem_list3[i]); |
@@ -1707,7 +1624,7 @@ static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid) | |||
1707 | if (cachep->flags & SLAB_RECLAIM_ACCOUNT) | 1624 | if (cachep->flags & SLAB_RECLAIM_ACCOUNT) |
1708 | flags |= __GFP_RECLAIMABLE; | 1625 | flags |= __GFP_RECLAIMABLE; |
1709 | 1626 | ||
1710 | page = alloc_pages_node(nodeid, flags, cachep->gfporder); | 1627 | page = alloc_pages_exact_node(nodeid, flags | __GFP_NOTRACK, cachep->gfporder); |
1711 | if (!page) | 1628 | if (!page) |
1712 | return NULL; | 1629 | return NULL; |
1713 | 1630 | ||
@@ -1720,6 +1637,16 @@ static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid) | |||
1720 | NR_SLAB_UNRECLAIMABLE, nr_pages); | 1637 | NR_SLAB_UNRECLAIMABLE, nr_pages); |
1721 | for (i = 0; i < nr_pages; i++) | 1638 | for (i = 0; i < nr_pages; i++) |
1722 | __SetPageSlab(page + i); | 1639 | __SetPageSlab(page + i); |
1640 | |||
1641 | if (kmemcheck_enabled && !(cachep->flags & SLAB_NOTRACK)) { | ||
1642 | kmemcheck_alloc_shadow(page, cachep->gfporder, flags, nodeid); | ||
1643 | |||
1644 | if (cachep->ctor) | ||
1645 | kmemcheck_mark_uninitialized_pages(page, nr_pages); | ||
1646 | else | ||
1647 | kmemcheck_mark_unallocated_pages(page, nr_pages); | ||
1648 | } | ||
1649 | |||
1723 | return page_address(page); | 1650 | return page_address(page); |
1724 | } | 1651 | } |
1725 | 1652 | ||
@@ -1732,6 +1659,8 @@ static void kmem_freepages(struct kmem_cache *cachep, void *addr) | |||
1732 | struct page *page = virt_to_page(addr); | 1659 | struct page *page = virt_to_page(addr); |
1733 | const unsigned long nr_freed = i; | 1660 | const unsigned long nr_freed = i; |
1734 | 1661 | ||
1662 | kmemcheck_free_shadow(page, cachep->gfporder); | ||
1663 | |||
1735 | if (cachep->flags & SLAB_RECLAIM_ACCOUNT) | 1664 | if (cachep->flags & SLAB_RECLAIM_ACCOUNT) |
1736 | sub_zone_page_state(page_zone(page), | 1665 | sub_zone_page_state(page_zone(page), |
1737 | NR_SLAB_RECLAIMABLE, nr_freed); | 1666 | NR_SLAB_RECLAIMABLE, nr_freed); |
@@ -2379,6 +2308,15 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2379 | /* really off slab. No need for manual alignment */ | 2308 | /* really off slab. No need for manual alignment */ |
2380 | slab_size = | 2309 | slab_size = |
2381 | cachep->num * sizeof(kmem_bufctl_t) + sizeof(struct slab); | 2310 | cachep->num * sizeof(kmem_bufctl_t) + sizeof(struct slab); |
2311 | |||
2312 | #ifdef CONFIG_PAGE_POISONING | ||
2313 | /* If we're going to use the generic kernel_map_pages() | ||
2314 | * poisoning, then it's going to smash the contents of | ||
2315 | * the redzone and userword anyhow, so switch them off. | ||
2316 | */ | ||
2317 | if (size % PAGE_SIZE == 0 && flags & SLAB_POISON) | ||
2318 | flags &= ~(SLAB_RED_ZONE | SLAB_STORE_USER); | ||
2319 | #endif | ||
2382 | } | 2320 | } |
2383 | 2321 | ||
2384 | cachep->colour_off = cache_line_size(); | 2322 | cachep->colour_off = cache_line_size(); |
@@ -3261,7 +3199,7 @@ retry: | |||
3261 | if (local_flags & __GFP_WAIT) | 3199 | if (local_flags & __GFP_WAIT) |
3262 | local_irq_enable(); | 3200 | local_irq_enable(); |
3263 | kmem_flagcheck(cache, flags); | 3201 | kmem_flagcheck(cache, flags); |
3264 | obj = kmem_getpages(cache, local_flags, -1); | 3202 | obj = kmem_getpages(cache, local_flags, numa_node_id()); |
3265 | if (local_flags & __GFP_WAIT) | 3203 | if (local_flags & __GFP_WAIT) |
3266 | local_irq_disable(); | 3204 | local_irq_disable(); |
3267 | if (obj) { | 3205 | if (obj) { |
@@ -3407,6 +3345,9 @@ __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | |||
3407 | kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags, | 3345 | kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags, |
3408 | flags); | 3346 | flags); |
3409 | 3347 | ||
3348 | if (likely(ptr)) | ||
3349 | kmemcheck_slab_alloc(cachep, flags, ptr, obj_size(cachep)); | ||
3350 | |||
3410 | if (unlikely((flags & __GFP_ZERO) && ptr)) | 3351 | if (unlikely((flags & __GFP_ZERO) && ptr)) |
3411 | memset(ptr, 0, obj_size(cachep)); | 3352 | memset(ptr, 0, obj_size(cachep)); |
3412 | 3353 | ||
@@ -3467,6 +3408,9 @@ __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller) | |||
3467 | flags); | 3408 | flags); |
3468 | prefetchw(objp); | 3409 | prefetchw(objp); |
3469 | 3410 | ||
3411 | if (likely(objp)) | ||
3412 | kmemcheck_slab_alloc(cachep, flags, objp, obj_size(cachep)); | ||
3413 | |||
3470 | if (unlikely((flags & __GFP_ZERO) && objp)) | 3414 | if (unlikely((flags & __GFP_ZERO) && objp)) |
3471 | memset(objp, 0, obj_size(cachep)); | 3415 | memset(objp, 0, obj_size(cachep)); |
3472 | 3416 | ||
@@ -3583,6 +3527,8 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) | |||
3583 | kmemleak_free_recursive(objp, cachep->flags); | 3527 | kmemleak_free_recursive(objp, cachep->flags); |
3584 | objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0)); | 3528 | objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0)); |
3585 | 3529 | ||
3530 | kmemcheck_slab_free(cachep, objp, obj_size(cachep)); | ||
3531 | |||
3586 | /* | 3532 | /* |
3587 | * Skip calling cache_free_alien() when the platform is not numa. | 3533 | * Skip calling cache_free_alien() when the platform is not numa. |
3588 | * This will avoid cache misses that happen while accessing slabp (which | 3534 | * This will avoid cache misses that happen while accessing slabp (which |
@@ -3590,7 +3536,7 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) | |||
3590 | * variable to skip the call, which is mostly likely to be present in | 3536 | * variable to skip the call, which is mostly likely to be present in |
3591 | * the cache. | 3537 | * the cache. |
3592 | */ | 3538 | */ |
3593 | if (numa_platform && cache_free_alien(cachep, objp)) | 3539 | if (nr_online_nodes > 1 && cache_free_alien(cachep, objp)) |
3594 | return; | 3540 | return; |
3595 | 3541 | ||
3596 | if (likely(ac->avail < ac->limit)) { | 3542 | if (likely(ac->avail < ac->limit)) { |