diff options
Diffstat (limited to 'mm/slab.c')
-rw-r--r-- | mm/slab.c | 246 |
1 files changed, 132 insertions, 114 deletions
@@ -793,8 +793,10 @@ static inline struct kmem_cache *__find_general_cachep(size_t size, | |||
793 | * has cs_{dma,}cachep==NULL. Thus no special case | 793 | * has cs_{dma,}cachep==NULL. Thus no special case |
794 | * for large kmalloc calls required. | 794 | * for large kmalloc calls required. |
795 | */ | 795 | */ |
796 | #ifdef CONFIG_ZONE_DMA | ||
796 | if (unlikely(gfpflags & GFP_DMA)) | 797 | if (unlikely(gfpflags & GFP_DMA)) |
797 | return csizep->cs_dmacachep; | 798 | return csizep->cs_dmacachep; |
799 | #endif | ||
798 | return csizep->cs_cachep; | 800 | return csizep->cs_cachep; |
799 | } | 801 | } |
800 | 802 | ||
@@ -1493,13 +1495,15 @@ void __init kmem_cache_init(void) | |||
1493 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, | 1495 | ARCH_KMALLOC_FLAGS|SLAB_PANIC, |
1494 | NULL, NULL); | 1496 | NULL, NULL); |
1495 | } | 1497 | } |
1496 | 1498 | #ifdef CONFIG_ZONE_DMA | |
1497 | sizes->cs_dmacachep = kmem_cache_create(names->name_dma, | 1499 | sizes->cs_dmacachep = kmem_cache_create( |
1500 | names->name_dma, | ||
1498 | sizes->cs_size, | 1501 | sizes->cs_size, |
1499 | ARCH_KMALLOC_MINALIGN, | 1502 | ARCH_KMALLOC_MINALIGN, |
1500 | ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| | 1503 | ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| |
1501 | SLAB_PANIC, | 1504 | SLAB_PANIC, |
1502 | NULL, NULL); | 1505 | NULL, NULL); |
1506 | #endif | ||
1503 | sizes++; | 1507 | sizes++; |
1504 | names++; | 1508 | names++; |
1505 | } | 1509 | } |
@@ -2321,7 +2325,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2321 | cachep->slab_size = slab_size; | 2325 | cachep->slab_size = slab_size; |
2322 | cachep->flags = flags; | 2326 | cachep->flags = flags; |
2323 | cachep->gfpflags = 0; | 2327 | cachep->gfpflags = 0; |
2324 | if (flags & SLAB_CACHE_DMA) | 2328 | if (CONFIG_ZONE_DMA_FLAG && (flags & SLAB_CACHE_DMA)) |
2325 | cachep->gfpflags |= GFP_DMA; | 2329 | cachep->gfpflags |= GFP_DMA; |
2326 | cachep->buffer_size = size; | 2330 | cachep->buffer_size = size; |
2327 | cachep->reciprocal_buffer_size = reciprocal_value(size); | 2331 | cachep->reciprocal_buffer_size = reciprocal_value(size); |
@@ -2516,7 +2520,7 @@ EXPORT_SYMBOL(kmem_cache_shrink); | |||
2516 | * kmem_cache_destroy - delete a cache | 2520 | * kmem_cache_destroy - delete a cache |
2517 | * @cachep: the cache to destroy | 2521 | * @cachep: the cache to destroy |
2518 | * | 2522 | * |
2519 | * Remove a struct kmem_cache object from the slab cache. | 2523 | * Remove a &struct kmem_cache object from the slab cache. |
2520 | * | 2524 | * |
2521 | * It is expected this function will be called by a module when it is | 2525 | * It is expected this function will be called by a module when it is |
2522 | * unloaded. This will remove the cache completely, and avoid a duplicate | 2526 | * unloaded. This will remove the cache completely, and avoid a duplicate |
@@ -2643,10 +2647,12 @@ static void cache_init_objs(struct kmem_cache *cachep, | |||
2643 | 2647 | ||
2644 | static void kmem_flagcheck(struct kmem_cache *cachep, gfp_t flags) | 2648 | static void kmem_flagcheck(struct kmem_cache *cachep, gfp_t flags) |
2645 | { | 2649 | { |
2646 | if (flags & GFP_DMA) | 2650 | if (CONFIG_ZONE_DMA_FLAG) { |
2647 | BUG_ON(!(cachep->gfpflags & GFP_DMA)); | 2651 | if (flags & GFP_DMA) |
2648 | else | 2652 | BUG_ON(!(cachep->gfpflags & GFP_DMA)); |
2649 | BUG_ON(cachep->gfpflags & GFP_DMA); | 2653 | else |
2654 | BUG_ON(cachep->gfpflags & GFP_DMA); | ||
2655 | } | ||
2650 | } | 2656 | } |
2651 | 2657 | ||
2652 | static void *slab_get_obj(struct kmem_cache *cachep, struct slab *slabp, | 2658 | static void *slab_get_obj(struct kmem_cache *cachep, struct slab *slabp, |
@@ -2814,19 +2820,11 @@ failed: | |||
2814 | */ | 2820 | */ |
2815 | static void kfree_debugcheck(const void *objp) | 2821 | static void kfree_debugcheck(const void *objp) |
2816 | { | 2822 | { |
2817 | struct page *page; | ||
2818 | |||
2819 | if (!virt_addr_valid(objp)) { | 2823 | if (!virt_addr_valid(objp)) { |
2820 | printk(KERN_ERR "kfree_debugcheck: out of range ptr %lxh.\n", | 2824 | printk(KERN_ERR "kfree_debugcheck: out of range ptr %lxh.\n", |
2821 | (unsigned long)objp); | 2825 | (unsigned long)objp); |
2822 | BUG(); | 2826 | BUG(); |
2823 | } | 2827 | } |
2824 | page = virt_to_page(objp); | ||
2825 | if (!PageSlab(page)) { | ||
2826 | printk(KERN_ERR "kfree_debugcheck: bad ptr %lxh.\n", | ||
2827 | (unsigned long)objp); | ||
2828 | BUG(); | ||
2829 | } | ||
2830 | } | 2828 | } |
2831 | 2829 | ||
2832 | static inline void verify_redzone_free(struct kmem_cache *cache, void *obj) | 2830 | static inline void verify_redzone_free(struct kmem_cache *cache, void *obj) |
@@ -3197,35 +3195,6 @@ static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) | |||
3197 | return objp; | 3195 | return objp; |
3198 | } | 3196 | } |
3199 | 3197 | ||
3200 | static __always_inline void *__cache_alloc(struct kmem_cache *cachep, | ||
3201 | gfp_t flags, void *caller) | ||
3202 | { | ||
3203 | unsigned long save_flags; | ||
3204 | void *objp = NULL; | ||
3205 | |||
3206 | cache_alloc_debugcheck_before(cachep, flags); | ||
3207 | |||
3208 | local_irq_save(save_flags); | ||
3209 | |||
3210 | if (unlikely(NUMA_BUILD && | ||
3211 | current->flags & (PF_SPREAD_SLAB | PF_MEMPOLICY))) | ||
3212 | objp = alternate_node_alloc(cachep, flags); | ||
3213 | |||
3214 | if (!objp) | ||
3215 | objp = ____cache_alloc(cachep, flags); | ||
3216 | /* | ||
3217 | * We may just have run out of memory on the local node. | ||
3218 | * ____cache_alloc_node() knows how to locate memory on other nodes | ||
3219 | */ | ||
3220 | if (NUMA_BUILD && !objp) | ||
3221 | objp = ____cache_alloc_node(cachep, flags, numa_node_id()); | ||
3222 | local_irq_restore(save_flags); | ||
3223 | objp = cache_alloc_debugcheck_after(cachep, flags, objp, | ||
3224 | caller); | ||
3225 | prefetchw(objp); | ||
3226 | return objp; | ||
3227 | } | ||
3228 | |||
3229 | #ifdef CONFIG_NUMA | 3198 | #ifdef CONFIG_NUMA |
3230 | /* | 3199 | /* |
3231 | * Try allocating on another node if PF_SPREAD_SLAB|PF_MEMPOLICY. | 3200 | * Try allocating on another node if PF_SPREAD_SLAB|PF_MEMPOLICY. |
@@ -3257,14 +3226,20 @@ static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags) | |||
3257 | * allocator to do its reclaim / fallback magic. We then insert the | 3226 | * allocator to do its reclaim / fallback magic. We then insert the |
3258 | * slab into the proper nodelist and then allocate from it. | 3227 | * slab into the proper nodelist and then allocate from it. |
3259 | */ | 3228 | */ |
3260 | void *fallback_alloc(struct kmem_cache *cache, gfp_t flags) | 3229 | static void *fallback_alloc(struct kmem_cache *cache, gfp_t flags) |
3261 | { | 3230 | { |
3262 | struct zonelist *zonelist = &NODE_DATA(slab_node(current->mempolicy)) | 3231 | struct zonelist *zonelist; |
3263 | ->node_zonelists[gfp_zone(flags)]; | 3232 | gfp_t local_flags; |
3264 | struct zone **z; | 3233 | struct zone **z; |
3265 | void *obj = NULL; | 3234 | void *obj = NULL; |
3266 | int nid; | 3235 | int nid; |
3267 | gfp_t local_flags = (flags & GFP_LEVEL_MASK); | 3236 | |
3237 | if (flags & __GFP_THISNODE) | ||
3238 | return NULL; | ||
3239 | |||
3240 | zonelist = &NODE_DATA(slab_node(current->mempolicy)) | ||
3241 | ->node_zonelists[gfp_zone(flags)]; | ||
3242 | local_flags = (flags & GFP_LEVEL_MASK); | ||
3268 | 3243 | ||
3269 | retry: | 3244 | retry: |
3270 | /* | 3245 | /* |
@@ -3374,16 +3349,110 @@ must_grow: | |||
3374 | if (x) | 3349 | if (x) |
3375 | goto retry; | 3350 | goto retry; |
3376 | 3351 | ||
3377 | if (!(flags & __GFP_THISNODE)) | 3352 | return fallback_alloc(cachep, flags); |
3378 | /* Unable to grow the cache. Fall back to other nodes. */ | ||
3379 | return fallback_alloc(cachep, flags); | ||
3380 | |||
3381 | return NULL; | ||
3382 | 3353 | ||
3383 | done: | 3354 | done: |
3384 | return obj; | 3355 | return obj; |
3385 | } | 3356 | } |
3386 | #endif | 3357 | |
3358 | /** | ||
3359 | * kmem_cache_alloc_node - Allocate an object on the specified node | ||
3360 | * @cachep: The cache to allocate from. | ||
3361 | * @flags: See kmalloc(). | ||
3362 | * @nodeid: node number of the target node. | ||
3363 | * @caller: return address of caller, used for debug information | ||
3364 | * | ||
3365 | * Identical to kmem_cache_alloc but it will allocate memory on the given | ||
3366 | * node, which can improve the performance for cpu bound structures. | ||
3367 | * | ||
3368 | * Fallback to other node is possible if __GFP_THISNODE is not set. | ||
3369 | */ | ||
3370 | static __always_inline void * | ||
3371 | __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | ||
3372 | void *caller) | ||
3373 | { | ||
3374 | unsigned long save_flags; | ||
3375 | void *ptr; | ||
3376 | |||
3377 | cache_alloc_debugcheck_before(cachep, flags); | ||
3378 | local_irq_save(save_flags); | ||
3379 | |||
3380 | if (unlikely(nodeid == -1)) | ||
3381 | nodeid = numa_node_id(); | ||
3382 | |||
3383 | if (unlikely(!cachep->nodelists[nodeid])) { | ||
3384 | /* Node not bootstrapped yet */ | ||
3385 | ptr = fallback_alloc(cachep, flags); | ||
3386 | goto out; | ||
3387 | } | ||
3388 | |||
3389 | if (nodeid == numa_node_id()) { | ||
3390 | /* | ||
3391 | * Use the locally cached objects if possible. | ||
3392 | * However ____cache_alloc does not allow fallback | ||
3393 | * to other nodes. It may fail while we still have | ||
3394 | * objects on other nodes available. | ||
3395 | */ | ||
3396 | ptr = ____cache_alloc(cachep, flags); | ||
3397 | if (ptr) | ||
3398 | goto out; | ||
3399 | } | ||
3400 | /* ___cache_alloc_node can fall back to other nodes */ | ||
3401 | ptr = ____cache_alloc_node(cachep, flags, nodeid); | ||
3402 | out: | ||
3403 | local_irq_restore(save_flags); | ||
3404 | ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); | ||
3405 | |||
3406 | return ptr; | ||
3407 | } | ||
3408 | |||
3409 | static __always_inline void * | ||
3410 | __do_cache_alloc(struct kmem_cache *cache, gfp_t flags) | ||
3411 | { | ||
3412 | void *objp; | ||
3413 | |||
3414 | if (unlikely(current->flags & (PF_SPREAD_SLAB | PF_MEMPOLICY))) { | ||
3415 | objp = alternate_node_alloc(cache, flags); | ||
3416 | if (objp) | ||
3417 | goto out; | ||
3418 | } | ||
3419 | objp = ____cache_alloc(cache, flags); | ||
3420 | |||
3421 | /* | ||
3422 | * We may just have run out of memory on the local node. | ||
3423 | * ____cache_alloc_node() knows how to locate memory on other nodes | ||
3424 | */ | ||
3425 | if (!objp) | ||
3426 | objp = ____cache_alloc_node(cache, flags, numa_node_id()); | ||
3427 | |||
3428 | out: | ||
3429 | return objp; | ||
3430 | } | ||
3431 | #else | ||
3432 | |||
3433 | static __always_inline void * | ||
3434 | __do_cache_alloc(struct kmem_cache *cachep, gfp_t flags) | ||
3435 | { | ||
3436 | return ____cache_alloc(cachep, flags); | ||
3437 | } | ||
3438 | |||
3439 | #endif /* CONFIG_NUMA */ | ||
3440 | |||
3441 | static __always_inline void * | ||
3442 | __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller) | ||
3443 | { | ||
3444 | unsigned long save_flags; | ||
3445 | void *objp; | ||
3446 | |||
3447 | cache_alloc_debugcheck_before(cachep, flags); | ||
3448 | local_irq_save(save_flags); | ||
3449 | objp = __do_cache_alloc(cachep, flags); | ||
3450 | local_irq_restore(save_flags); | ||
3451 | objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); | ||
3452 | prefetchw(objp); | ||
3453 | |||
3454 | return objp; | ||
3455 | } | ||
3387 | 3456 | ||
3388 | /* | 3457 | /* |
3389 | * Caller needs to acquire correct kmem_list's list_lock | 3458 | * Caller needs to acquire correct kmem_list's list_lock |
@@ -3582,57 +3651,6 @@ out: | |||
3582 | } | 3651 | } |
3583 | 3652 | ||
3584 | #ifdef CONFIG_NUMA | 3653 | #ifdef CONFIG_NUMA |
3585 | /** | ||
3586 | * kmem_cache_alloc_node - Allocate an object on the specified node | ||
3587 | * @cachep: The cache to allocate from. | ||
3588 | * @flags: See kmalloc(). | ||
3589 | * @nodeid: node number of the target node. | ||
3590 | * @caller: return address of caller, used for debug information | ||
3591 | * | ||
3592 | * Identical to kmem_cache_alloc but it will allocate memory on the given | ||
3593 | * node, which can improve the performance for cpu bound structures. | ||
3594 | * | ||
3595 | * Fallback to other node is possible if __GFP_THISNODE is not set. | ||
3596 | */ | ||
3597 | static __always_inline void * | ||
3598 | __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, | ||
3599 | int nodeid, void *caller) | ||
3600 | { | ||
3601 | unsigned long save_flags; | ||
3602 | void *ptr = NULL; | ||
3603 | |||
3604 | cache_alloc_debugcheck_before(cachep, flags); | ||
3605 | local_irq_save(save_flags); | ||
3606 | |||
3607 | if (unlikely(nodeid == -1)) | ||
3608 | nodeid = numa_node_id(); | ||
3609 | |||
3610 | if (likely(cachep->nodelists[nodeid])) { | ||
3611 | if (nodeid == numa_node_id()) { | ||
3612 | /* | ||
3613 | * Use the locally cached objects if possible. | ||
3614 | * However ____cache_alloc does not allow fallback | ||
3615 | * to other nodes. It may fail while we still have | ||
3616 | * objects on other nodes available. | ||
3617 | */ | ||
3618 | ptr = ____cache_alloc(cachep, flags); | ||
3619 | } | ||
3620 | if (!ptr) { | ||
3621 | /* ___cache_alloc_node can fall back to other nodes */ | ||
3622 | ptr = ____cache_alloc_node(cachep, flags, nodeid); | ||
3623 | } | ||
3624 | } else { | ||
3625 | /* Node not bootstrapped yet */ | ||
3626 | if (!(flags & __GFP_THISNODE)) | ||
3627 | ptr = fallback_alloc(cachep, flags); | ||
3628 | } | ||
3629 | |||
3630 | local_irq_restore(save_flags); | ||
3631 | ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); | ||
3632 | |||
3633 | return ptr; | ||
3634 | } | ||
3635 | |||
3636 | void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) | 3654 | void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) |
3637 | { | 3655 | { |
3638 | return __cache_alloc_node(cachep, flags, nodeid, | 3656 | return __cache_alloc_node(cachep, flags, nodeid, |
@@ -3733,6 +3751,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) | |||
3733 | BUG_ON(virt_to_cache(objp) != cachep); | 3751 | BUG_ON(virt_to_cache(objp) != cachep); |
3734 | 3752 | ||
3735 | local_irq_save(flags); | 3753 | local_irq_save(flags); |
3754 | debug_check_no_locks_freed(objp, obj_size(cachep)); | ||
3736 | __cache_free(cachep, objp); | 3755 | __cache_free(cachep, objp); |
3737 | local_irq_restore(flags); | 3756 | local_irq_restore(flags); |
3738 | } | 3757 | } |
@@ -4017,18 +4036,17 @@ void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3, | |||
4017 | * If we cannot acquire the cache chain mutex then just give up - we'll try | 4036 | * If we cannot acquire the cache chain mutex then just give up - we'll try |
4018 | * again on the next iteration. | 4037 | * again on the next iteration. |
4019 | */ | 4038 | */ |
4020 | static void cache_reap(struct work_struct *unused) | 4039 | static void cache_reap(struct work_struct *w) |
4021 | { | 4040 | { |
4022 | struct kmem_cache *searchp; | 4041 | struct kmem_cache *searchp; |
4023 | struct kmem_list3 *l3; | 4042 | struct kmem_list3 *l3; |
4024 | int node = numa_node_id(); | 4043 | int node = numa_node_id(); |
4044 | struct delayed_work *work = | ||
4045 | container_of(w, struct delayed_work, work); | ||
4025 | 4046 | ||
4026 | if (!mutex_trylock(&cache_chain_mutex)) { | 4047 | if (!mutex_trylock(&cache_chain_mutex)) |
4027 | /* Give up. Setup the next iteration. */ | 4048 | /* Give up. Setup the next iteration. */ |
4028 | schedule_delayed_work(&__get_cpu_var(reap_work), | 4049 | goto out; |
4029 | round_jiffies_relative(REAPTIMEOUT_CPUC)); | ||
4030 | return; | ||
4031 | } | ||
4032 | 4050 | ||
4033 | list_for_each_entry(searchp, &cache_chain, next) { | 4051 | list_for_each_entry(searchp, &cache_chain, next) { |
4034 | check_irq_on(); | 4052 | check_irq_on(); |
@@ -4071,9 +4089,9 @@ next: | |||
4071 | mutex_unlock(&cache_chain_mutex); | 4089 | mutex_unlock(&cache_chain_mutex); |
4072 | next_reap_node(); | 4090 | next_reap_node(); |
4073 | refresh_cpu_vm_stats(smp_processor_id()); | 4091 | refresh_cpu_vm_stats(smp_processor_id()); |
4092 | out: | ||
4074 | /* Set up the next iteration */ | 4093 | /* Set up the next iteration */ |
4075 | schedule_delayed_work(&__get_cpu_var(reap_work), | 4094 | schedule_delayed_work(work, round_jiffies_relative(REAPTIMEOUT_CPUC)); |
4076 | round_jiffies_relative(REAPTIMEOUT_CPUC)); | ||
4077 | } | 4095 | } |
4078 | 4096 | ||
4079 | #ifdef CONFIG_PROC_FS | 4097 | #ifdef CONFIG_PROC_FS |