diff options
Diffstat (limited to 'mm/slab.c')
-rw-r--r-- | mm/slab.c | 1247 |
1 files changed, 642 insertions, 605 deletions
@@ -68,7 +68,7 @@ | |||
68 | * Further notes from the original documentation: | 68 | * Further notes from the original documentation: |
69 | * | 69 | * |
70 | * 11 April '97. Started multi-threading - markhe | 70 | * 11 April '97. Started multi-threading - markhe |
71 | * The global cache-chain is protected by the semaphore 'cache_chain_sem'. | 71 | * The global cache-chain is protected by the mutex 'cache_chain_mutex'. |
72 | * The sem is only needed when accessing/extending the cache-chain, which | 72 | * The sem is only needed when accessing/extending the cache-chain, which |
73 | * can never happen inside an interrupt (kmem_cache_create(), | 73 | * can never happen inside an interrupt (kmem_cache_create(), |
74 | * kmem_cache_shrink() and kmem_cache_reap()). | 74 | * kmem_cache_shrink() and kmem_cache_reap()). |
@@ -103,6 +103,8 @@ | |||
103 | #include <linux/rcupdate.h> | 103 | #include <linux/rcupdate.h> |
104 | #include <linux/string.h> | 104 | #include <linux/string.h> |
105 | #include <linux/nodemask.h> | 105 | #include <linux/nodemask.h> |
106 | #include <linux/mempolicy.h> | ||
107 | #include <linux/mutex.h> | ||
106 | 108 | ||
107 | #include <asm/uaccess.h> | 109 | #include <asm/uaccess.h> |
108 | #include <asm/cacheflush.h> | 110 | #include <asm/cacheflush.h> |
@@ -130,7 +132,6 @@ | |||
130 | #define FORCED_DEBUG 0 | 132 | #define FORCED_DEBUG 0 |
131 | #endif | 133 | #endif |
132 | 134 | ||
133 | |||
134 | /* Shouldn't this be in a header file somewhere? */ | 135 | /* Shouldn't this be in a header file somewhere? */ |
135 | #define BYTES_PER_WORD sizeof(void *) | 136 | #define BYTES_PER_WORD sizeof(void *) |
136 | 137 | ||
@@ -217,12 +218,12 @@ static unsigned long offslab_limit; | |||
217 | * Slabs are chained into three list: fully used, partial, fully free slabs. | 218 | * Slabs are chained into three list: fully used, partial, fully free slabs. |
218 | */ | 219 | */ |
219 | struct slab { | 220 | struct slab { |
220 | struct list_head list; | 221 | struct list_head list; |
221 | unsigned long colouroff; | 222 | unsigned long colouroff; |
222 | void *s_mem; /* including colour offset */ | 223 | void *s_mem; /* including colour offset */ |
223 | unsigned int inuse; /* num of objs active in slab */ | 224 | unsigned int inuse; /* num of objs active in slab */ |
224 | kmem_bufctl_t free; | 225 | kmem_bufctl_t free; |
225 | unsigned short nodeid; | 226 | unsigned short nodeid; |
226 | }; | 227 | }; |
227 | 228 | ||
228 | /* | 229 | /* |
@@ -242,9 +243,9 @@ struct slab { | |||
242 | * We assume struct slab_rcu can overlay struct slab when destroying. | 243 | * We assume struct slab_rcu can overlay struct slab when destroying. |
243 | */ | 244 | */ |
244 | struct slab_rcu { | 245 | struct slab_rcu { |
245 | struct rcu_head head; | 246 | struct rcu_head head; |
246 | kmem_cache_t *cachep; | 247 | kmem_cache_t *cachep; |
247 | void *addr; | 248 | void *addr; |
248 | }; | 249 | }; |
249 | 250 | ||
250 | /* | 251 | /* |
@@ -279,23 +280,23 @@ struct array_cache { | |||
279 | #define BOOT_CPUCACHE_ENTRIES 1 | 280 | #define BOOT_CPUCACHE_ENTRIES 1 |
280 | struct arraycache_init { | 281 | struct arraycache_init { |
281 | struct array_cache cache; | 282 | struct array_cache cache; |
282 | void * entries[BOOT_CPUCACHE_ENTRIES]; | 283 | void *entries[BOOT_CPUCACHE_ENTRIES]; |
283 | }; | 284 | }; |
284 | 285 | ||
285 | /* | 286 | /* |
286 | * The slab lists for all objects. | 287 | * The slab lists for all objects. |
287 | */ | 288 | */ |
288 | struct kmem_list3 { | 289 | struct kmem_list3 { |
289 | struct list_head slabs_partial; /* partial list first, better asm code */ | 290 | struct list_head slabs_partial; /* partial list first, better asm code */ |
290 | struct list_head slabs_full; | 291 | struct list_head slabs_full; |
291 | struct list_head slabs_free; | 292 | struct list_head slabs_free; |
292 | unsigned long free_objects; | 293 | unsigned long free_objects; |
293 | unsigned long next_reap; | 294 | unsigned long next_reap; |
294 | int free_touched; | 295 | int free_touched; |
295 | unsigned int free_limit; | 296 | unsigned int free_limit; |
296 | spinlock_t list_lock; | 297 | spinlock_t list_lock; |
297 | struct array_cache *shared; /* shared per node */ | 298 | struct array_cache *shared; /* shared per node */ |
298 | struct array_cache **alien; /* on other nodes */ | 299 | struct array_cache **alien; /* on other nodes */ |
299 | }; | 300 | }; |
300 | 301 | ||
301 | /* | 302 | /* |
@@ -367,63 +368,63 @@ static inline void kmem_list3_init(struct kmem_list3 *parent) | |||
367 | * | 368 | * |
368 | * manages a cache. | 369 | * manages a cache. |
369 | */ | 370 | */ |
370 | 371 | ||
371 | struct kmem_cache { | 372 | struct kmem_cache { |
372 | /* 1) per-cpu data, touched during every alloc/free */ | 373 | /* 1) per-cpu data, touched during every alloc/free */ |
373 | struct array_cache *array[NR_CPUS]; | 374 | struct array_cache *array[NR_CPUS]; |
374 | unsigned int batchcount; | 375 | unsigned int batchcount; |
375 | unsigned int limit; | 376 | unsigned int limit; |
376 | unsigned int shared; | 377 | unsigned int shared; |
377 | unsigned int objsize; | 378 | unsigned int objsize; |
378 | /* 2) touched by every alloc & free from the backend */ | 379 | /* 2) touched by every alloc & free from the backend */ |
379 | struct kmem_list3 *nodelists[MAX_NUMNODES]; | 380 | struct kmem_list3 *nodelists[MAX_NUMNODES]; |
380 | unsigned int flags; /* constant flags */ | 381 | unsigned int flags; /* constant flags */ |
381 | unsigned int num; /* # of objs per slab */ | 382 | unsigned int num; /* # of objs per slab */ |
382 | spinlock_t spinlock; | 383 | spinlock_t spinlock; |
383 | 384 | ||
384 | /* 3) cache_grow/shrink */ | 385 | /* 3) cache_grow/shrink */ |
385 | /* order of pgs per slab (2^n) */ | 386 | /* order of pgs per slab (2^n) */ |
386 | unsigned int gfporder; | 387 | unsigned int gfporder; |
387 | 388 | ||
388 | /* force GFP flags, e.g. GFP_DMA */ | 389 | /* force GFP flags, e.g. GFP_DMA */ |
389 | gfp_t gfpflags; | 390 | gfp_t gfpflags; |
390 | 391 | ||
391 | size_t colour; /* cache colouring range */ | 392 | size_t colour; /* cache colouring range */ |
392 | unsigned int colour_off; /* colour offset */ | 393 | unsigned int colour_off; /* colour offset */ |
393 | unsigned int colour_next; /* cache colouring */ | 394 | unsigned int colour_next; /* cache colouring */ |
394 | kmem_cache_t *slabp_cache; | 395 | kmem_cache_t *slabp_cache; |
395 | unsigned int slab_size; | 396 | unsigned int slab_size; |
396 | unsigned int dflags; /* dynamic flags */ | 397 | unsigned int dflags; /* dynamic flags */ |
397 | 398 | ||
398 | /* constructor func */ | 399 | /* constructor func */ |
399 | void (*ctor)(void *, kmem_cache_t *, unsigned long); | 400 | void (*ctor) (void *, kmem_cache_t *, unsigned long); |
400 | 401 | ||
401 | /* de-constructor func */ | 402 | /* de-constructor func */ |
402 | void (*dtor)(void *, kmem_cache_t *, unsigned long); | 403 | void (*dtor) (void *, kmem_cache_t *, unsigned long); |
403 | 404 | ||
404 | /* 4) cache creation/removal */ | 405 | /* 4) cache creation/removal */ |
405 | const char *name; | 406 | const char *name; |
406 | struct list_head next; | 407 | struct list_head next; |
407 | 408 | ||
408 | /* 5) statistics */ | 409 | /* 5) statistics */ |
409 | #if STATS | 410 | #if STATS |
410 | unsigned long num_active; | 411 | unsigned long num_active; |
411 | unsigned long num_allocations; | 412 | unsigned long num_allocations; |
412 | unsigned long high_mark; | 413 | unsigned long high_mark; |
413 | unsigned long grown; | 414 | unsigned long grown; |
414 | unsigned long reaped; | 415 | unsigned long reaped; |
415 | unsigned long errors; | 416 | unsigned long errors; |
416 | unsigned long max_freeable; | 417 | unsigned long max_freeable; |
417 | unsigned long node_allocs; | 418 | unsigned long node_allocs; |
418 | unsigned long node_frees; | 419 | unsigned long node_frees; |
419 | atomic_t allochit; | 420 | atomic_t allochit; |
420 | atomic_t allocmiss; | 421 | atomic_t allocmiss; |
421 | atomic_t freehit; | 422 | atomic_t freehit; |
422 | atomic_t freemiss; | 423 | atomic_t freemiss; |
423 | #endif | 424 | #endif |
424 | #if DEBUG | 425 | #if DEBUG |
425 | int dbghead; | 426 | int dbghead; |
426 | int reallen; | 427 | int reallen; |
427 | #endif | 428 | #endif |
428 | }; | 429 | }; |
429 | 430 | ||
@@ -434,7 +435,7 @@ struct kmem_cache { | |||
434 | /* Optimization question: fewer reaps means less | 435 | /* Optimization question: fewer reaps means less |
435 | * probability for unnessary cpucache drain/refill cycles. | 436 | * probability for unnessary cpucache drain/refill cycles. |
436 | * | 437 | * |
437 | * OTHO the cpuarrays can contain lots of objects, | 438 | * OTOH the cpuarrays can contain lots of objects, |
438 | * which could lock up otherwise freeable slabs. | 439 | * which could lock up otherwise freeable slabs. |
439 | */ | 440 | */ |
440 | #define REAPTIMEOUT_CPUC (2*HZ) | 441 | #define REAPTIMEOUT_CPUC (2*HZ) |
@@ -523,14 +524,15 @@ static unsigned long *dbg_redzone2(kmem_cache_t *cachep, void *objp) | |||
523 | { | 524 | { |
524 | BUG_ON(!(cachep->flags & SLAB_RED_ZONE)); | 525 | BUG_ON(!(cachep->flags & SLAB_RED_ZONE)); |
525 | if (cachep->flags & SLAB_STORE_USER) | 526 | if (cachep->flags & SLAB_STORE_USER) |
526 | return (unsigned long*) (objp+cachep->objsize-2*BYTES_PER_WORD); | 527 | return (unsigned long *)(objp + cachep->objsize - |
527 | return (unsigned long*) (objp+cachep->objsize-BYTES_PER_WORD); | 528 | 2 * BYTES_PER_WORD); |
529 | return (unsigned long *)(objp + cachep->objsize - BYTES_PER_WORD); | ||
528 | } | 530 | } |
529 | 531 | ||
530 | static void **dbg_userword(kmem_cache_t *cachep, void *objp) | 532 | static void **dbg_userword(kmem_cache_t *cachep, void *objp) |
531 | { | 533 | { |
532 | BUG_ON(!(cachep->flags & SLAB_STORE_USER)); | 534 | BUG_ON(!(cachep->flags & SLAB_STORE_USER)); |
533 | return (void**)(objp+cachep->objsize-BYTES_PER_WORD); | 535 | return (void **)(objp + cachep->objsize - BYTES_PER_WORD); |
534 | } | 536 | } |
535 | 537 | ||
536 | #else | 538 | #else |
@@ -565,14 +567,29 @@ static void **dbg_userword(kmem_cache_t *cachep, void *objp) | |||
565 | #define BREAK_GFP_ORDER_LO 0 | 567 | #define BREAK_GFP_ORDER_LO 0 |
566 | static int slab_break_gfp_order = BREAK_GFP_ORDER_LO; | 568 | static int slab_break_gfp_order = BREAK_GFP_ORDER_LO; |
567 | 569 | ||
568 | /* Macros for storing/retrieving the cachep and or slab from the | 570 | /* Functions for storing/retrieving the cachep and or slab from the |
569 | * global 'mem_map'. These are used to find the slab an obj belongs to. | 571 | * global 'mem_map'. These are used to find the slab an obj belongs to. |
570 | * With kfree(), these are used to find the cache which an obj belongs to. | 572 | * With kfree(), these are used to find the cache which an obj belongs to. |
571 | */ | 573 | */ |
572 | #define SET_PAGE_CACHE(pg,x) ((pg)->lru.next = (struct list_head *)(x)) | 574 | static inline void page_set_cache(struct page *page, struct kmem_cache *cache) |
573 | #define GET_PAGE_CACHE(pg) ((kmem_cache_t *)(pg)->lru.next) | 575 | { |
574 | #define SET_PAGE_SLAB(pg,x) ((pg)->lru.prev = (struct list_head *)(x)) | 576 | page->lru.next = (struct list_head *)cache; |
575 | #define GET_PAGE_SLAB(pg) ((struct slab *)(pg)->lru.prev) | 577 | } |
578 | |||
579 | static inline struct kmem_cache *page_get_cache(struct page *page) | ||
580 | { | ||
581 | return (struct kmem_cache *)page->lru.next; | ||
582 | } | ||
583 | |||
584 | static inline void page_set_slab(struct page *page, struct slab *slab) | ||
585 | { | ||
586 | page->lru.prev = (struct list_head *)slab; | ||
587 | } | ||
588 | |||
589 | static inline struct slab *page_get_slab(struct page *page) | ||
590 | { | ||
591 | return (struct slab *)page->lru.prev; | ||
592 | } | ||
576 | 593 | ||
577 | /* These are the default caches for kmalloc. Custom caches can have other sizes. */ | 594 | /* These are the default caches for kmalloc. Custom caches can have other sizes. */ |
578 | struct cache_sizes malloc_sizes[] = { | 595 | struct cache_sizes malloc_sizes[] = { |
@@ -592,31 +609,31 @@ struct cache_names { | |||
592 | static struct cache_names __initdata cache_names[] = { | 609 | static struct cache_names __initdata cache_names[] = { |
593 | #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" }, | 610 | #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" }, |
594 | #include <linux/kmalloc_sizes.h> | 611 | #include <linux/kmalloc_sizes.h> |
595 | { NULL, } | 612 | {NULL,} |
596 | #undef CACHE | 613 | #undef CACHE |
597 | }; | 614 | }; |
598 | 615 | ||
599 | static struct arraycache_init initarray_cache __initdata = | 616 | static struct arraycache_init initarray_cache __initdata = |
600 | { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; | 617 | { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; |
601 | static struct arraycache_init initarray_generic = | 618 | static struct arraycache_init initarray_generic = |
602 | { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; | 619 | { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; |
603 | 620 | ||
604 | /* internal cache of cache description objs */ | 621 | /* internal cache of cache description objs */ |
605 | static kmem_cache_t cache_cache = { | 622 | static kmem_cache_t cache_cache = { |
606 | .batchcount = 1, | 623 | .batchcount = 1, |
607 | .limit = BOOT_CPUCACHE_ENTRIES, | 624 | .limit = BOOT_CPUCACHE_ENTRIES, |
608 | .shared = 1, | 625 | .shared = 1, |
609 | .objsize = sizeof(kmem_cache_t), | 626 | .objsize = sizeof(kmem_cache_t), |
610 | .flags = SLAB_NO_REAP, | 627 | .flags = SLAB_NO_REAP, |
611 | .spinlock = SPIN_LOCK_UNLOCKED, | 628 | .spinlock = SPIN_LOCK_UNLOCKED, |
612 | .name = "kmem_cache", | 629 | .name = "kmem_cache", |
613 | #if DEBUG | 630 | #if DEBUG |
614 | .reallen = sizeof(kmem_cache_t), | 631 | .reallen = sizeof(kmem_cache_t), |
615 | #endif | 632 | #endif |
616 | }; | 633 | }; |
617 | 634 | ||
618 | /* Guard access to the cache-chain. */ | 635 | /* Guard access to the cache-chain. */ |
619 | static struct semaphore cache_chain_sem; | 636 | static DEFINE_MUTEX(cache_chain_mutex); |
620 | static struct list_head cache_chain; | 637 | static struct list_head cache_chain; |
621 | 638 | ||
622 | /* | 639 | /* |
@@ -640,9 +657,9 @@ static enum { | |||
640 | 657 | ||
641 | static DEFINE_PER_CPU(struct work_struct, reap_work); | 658 | static DEFINE_PER_CPU(struct work_struct, reap_work); |
642 | 659 | ||
643 | static void free_block(kmem_cache_t* cachep, void** objpp, int len, int node); | 660 | static void free_block(kmem_cache_t *cachep, void **objpp, int len, int node); |
644 | static void enable_cpucache (kmem_cache_t *cachep); | 661 | static void enable_cpucache(kmem_cache_t *cachep); |
645 | static void cache_reap (void *unused); | 662 | static void cache_reap(void *unused); |
646 | static int __node_shrink(kmem_cache_t *cachep, int node); | 663 | static int __node_shrink(kmem_cache_t *cachep, int node); |
647 | 664 | ||
648 | static inline struct array_cache *ac_data(kmem_cache_t *cachep) | 665 | static inline struct array_cache *ac_data(kmem_cache_t *cachep) |
@@ -656,9 +673,9 @@ static inline kmem_cache_t *__find_general_cachep(size_t size, gfp_t gfpflags) | |||
656 | 673 | ||
657 | #if DEBUG | 674 | #if DEBUG |
658 | /* This happens if someone tries to call | 675 | /* This happens if someone tries to call |
659 | * kmem_cache_create(), or __kmalloc(), before | 676 | * kmem_cache_create(), or __kmalloc(), before |
660 | * the generic caches are initialized. | 677 | * the generic caches are initialized. |
661 | */ | 678 | */ |
662 | BUG_ON(malloc_sizes[INDEX_AC].cs_cachep == NULL); | 679 | BUG_ON(malloc_sizes[INDEX_AC].cs_cachep == NULL); |
663 | #endif | 680 | #endif |
664 | while (size > csizep->cs_size) | 681 | while (size > csizep->cs_size) |
@@ -682,10 +699,10 @@ EXPORT_SYMBOL(kmem_find_general_cachep); | |||
682 | 699 | ||
683 | /* Cal the num objs, wastage, and bytes left over for a given slab size. */ | 700 | /* Cal the num objs, wastage, and bytes left over for a given slab size. */ |
684 | static void cache_estimate(unsigned long gfporder, size_t size, size_t align, | 701 | static void cache_estimate(unsigned long gfporder, size_t size, size_t align, |
685 | int flags, size_t *left_over, unsigned int *num) | 702 | int flags, size_t *left_over, unsigned int *num) |
686 | { | 703 | { |
687 | int i; | 704 | int i; |
688 | size_t wastage = PAGE_SIZE<<gfporder; | 705 | size_t wastage = PAGE_SIZE << gfporder; |
689 | size_t extra = 0; | 706 | size_t extra = 0; |
690 | size_t base = 0; | 707 | size_t base = 0; |
691 | 708 | ||
@@ -694,7 +711,7 @@ static void cache_estimate(unsigned long gfporder, size_t size, size_t align, | |||
694 | extra = sizeof(kmem_bufctl_t); | 711 | extra = sizeof(kmem_bufctl_t); |
695 | } | 712 | } |
696 | i = 0; | 713 | i = 0; |
697 | while (i*size + ALIGN(base+i*extra, align) <= wastage) | 714 | while (i * size + ALIGN(base + i * extra, align) <= wastage) |
698 | i++; | 715 | i++; |
699 | if (i > 0) | 716 | if (i > 0) |
700 | i--; | 717 | i--; |
@@ -703,8 +720,8 @@ static void cache_estimate(unsigned long gfporder, size_t size, size_t align, | |||
703 | i = SLAB_LIMIT; | 720 | i = SLAB_LIMIT; |
704 | 721 | ||
705 | *num = i; | 722 | *num = i; |
706 | wastage -= i*size; | 723 | wastage -= i * size; |
707 | wastage -= ALIGN(base+i*extra, align); | 724 | wastage -= ALIGN(base + i * extra, align); |
708 | *left_over = wastage; | 725 | *left_over = wastage; |
709 | } | 726 | } |
710 | 727 | ||
@@ -713,7 +730,7 @@ static void cache_estimate(unsigned long gfporder, size_t size, size_t align, | |||
713 | static void __slab_error(const char *function, kmem_cache_t *cachep, char *msg) | 730 | static void __slab_error(const char *function, kmem_cache_t *cachep, char *msg) |
714 | { | 731 | { |
715 | printk(KERN_ERR "slab error in %s(): cache `%s': %s\n", | 732 | printk(KERN_ERR "slab error in %s(): cache `%s': %s\n", |
716 | function, cachep->name, msg); | 733 | function, cachep->name, msg); |
717 | dump_stack(); | 734 | dump_stack(); |
718 | } | 735 | } |
719 | 736 | ||
@@ -740,9 +757,9 @@ static void __devinit start_cpu_timer(int cpu) | |||
740 | } | 757 | } |
741 | 758 | ||
742 | static struct array_cache *alloc_arraycache(int node, int entries, | 759 | static struct array_cache *alloc_arraycache(int node, int entries, |
743 | int batchcount) | 760 | int batchcount) |
744 | { | 761 | { |
745 | int memsize = sizeof(void*)*entries+sizeof(struct array_cache); | 762 | int memsize = sizeof(void *) * entries + sizeof(struct array_cache); |
746 | struct array_cache *nc = NULL; | 763 | struct array_cache *nc = NULL; |
747 | 764 | ||
748 | nc = kmalloc_node(memsize, GFP_KERNEL, node); | 765 | nc = kmalloc_node(memsize, GFP_KERNEL, node); |
@@ -757,10 +774,12 @@ static struct array_cache *alloc_arraycache(int node, int entries, | |||
757 | } | 774 | } |
758 | 775 | ||
759 | #ifdef CONFIG_NUMA | 776 | #ifdef CONFIG_NUMA |
777 | static void *__cache_alloc_node(kmem_cache_t *, gfp_t, int); | ||
778 | |||
760 | static inline struct array_cache **alloc_alien_cache(int node, int limit) | 779 | static inline struct array_cache **alloc_alien_cache(int node, int limit) |
761 | { | 780 | { |
762 | struct array_cache **ac_ptr; | 781 | struct array_cache **ac_ptr; |
763 | int memsize = sizeof(void*)*MAX_NUMNODES; | 782 | int memsize = sizeof(void *) * MAX_NUMNODES; |
764 | int i; | 783 | int i; |
765 | 784 | ||
766 | if (limit > 1) | 785 | if (limit > 1) |
@@ -774,7 +793,7 @@ static inline struct array_cache **alloc_alien_cache(int node, int limit) | |||
774 | } | 793 | } |
775 | ac_ptr[i] = alloc_arraycache(node, limit, 0xbaadf00d); | 794 | ac_ptr[i] = alloc_arraycache(node, limit, 0xbaadf00d); |
776 | if (!ac_ptr[i]) { | 795 | if (!ac_ptr[i]) { |
777 | for (i--; i <=0; i--) | 796 | for (i--; i <= 0; i--) |
778 | kfree(ac_ptr[i]); | 797 | kfree(ac_ptr[i]); |
779 | kfree(ac_ptr); | 798 | kfree(ac_ptr); |
780 | return NULL; | 799 | return NULL; |
@@ -792,12 +811,13 @@ static inline void free_alien_cache(struct array_cache **ac_ptr) | |||
792 | return; | 811 | return; |
793 | 812 | ||
794 | for_each_node(i) | 813 | for_each_node(i) |
795 | kfree(ac_ptr[i]); | 814 | kfree(ac_ptr[i]); |
796 | 815 | ||
797 | kfree(ac_ptr); | 816 | kfree(ac_ptr); |
798 | } | 817 | } |
799 | 818 | ||
800 | static inline void __drain_alien_cache(kmem_cache_t *cachep, struct array_cache *ac, int node) | 819 | static inline void __drain_alien_cache(kmem_cache_t *cachep, |
820 | struct array_cache *ac, int node) | ||
801 | { | 821 | { |
802 | struct kmem_list3 *rl3 = cachep->nodelists[node]; | 822 | struct kmem_list3 *rl3 = cachep->nodelists[node]; |
803 | 823 | ||
@@ -811,7 +831,7 @@ static inline void __drain_alien_cache(kmem_cache_t *cachep, struct array_cache | |||
811 | 831 | ||
812 | static void drain_alien_cache(kmem_cache_t *cachep, struct kmem_list3 *l3) | 832 | static void drain_alien_cache(kmem_cache_t *cachep, struct kmem_list3 *l3) |
813 | { | 833 | { |
814 | int i=0; | 834 | int i = 0; |
815 | struct array_cache *ac; | 835 | struct array_cache *ac; |
816 | unsigned long flags; | 836 | unsigned long flags; |
817 | 837 | ||
@@ -831,18 +851,17 @@ static void drain_alien_cache(kmem_cache_t *cachep, struct kmem_list3 *l3) | |||
831 | #endif | 851 | #endif |
832 | 852 | ||
833 | static int __devinit cpuup_callback(struct notifier_block *nfb, | 853 | static int __devinit cpuup_callback(struct notifier_block *nfb, |
834 | unsigned long action, void *hcpu) | 854 | unsigned long action, void *hcpu) |
835 | { | 855 | { |
836 | long cpu = (long)hcpu; | 856 | long cpu = (long)hcpu; |
837 | kmem_cache_t* cachep; | 857 | kmem_cache_t *cachep; |
838 | struct kmem_list3 *l3 = NULL; | 858 | struct kmem_list3 *l3 = NULL; |
839 | int node = cpu_to_node(cpu); | 859 | int node = cpu_to_node(cpu); |
840 | int memsize = sizeof(struct kmem_list3); | 860 | int memsize = sizeof(struct kmem_list3); |
841 | struct array_cache *nc = NULL; | ||
842 | 861 | ||
843 | switch (action) { | 862 | switch (action) { |
844 | case CPU_UP_PREPARE: | 863 | case CPU_UP_PREPARE: |
845 | down(&cache_chain_sem); | 864 | mutex_lock(&cache_chain_mutex); |
846 | /* we need to do this right in the beginning since | 865 | /* we need to do this right in the beginning since |
847 | * alloc_arraycache's are going to use this list. | 866 | * alloc_arraycache's are going to use this list. |
848 | * kmalloc_node allows us to add the slab to the right | 867 | * kmalloc_node allows us to add the slab to the right |
@@ -856,27 +875,29 @@ static int __devinit cpuup_callback(struct notifier_block *nfb, | |||
856 | */ | 875 | */ |
857 | if (!cachep->nodelists[node]) { | 876 | if (!cachep->nodelists[node]) { |
858 | if (!(l3 = kmalloc_node(memsize, | 877 | if (!(l3 = kmalloc_node(memsize, |
859 | GFP_KERNEL, node))) | 878 | GFP_KERNEL, node))) |
860 | goto bad; | 879 | goto bad; |
861 | kmem_list3_init(l3); | 880 | kmem_list3_init(l3); |
862 | l3->next_reap = jiffies + REAPTIMEOUT_LIST3 + | 881 | l3->next_reap = jiffies + REAPTIMEOUT_LIST3 + |
863 | ((unsigned long)cachep)%REAPTIMEOUT_LIST3; | 882 | ((unsigned long)cachep) % REAPTIMEOUT_LIST3; |
864 | 883 | ||
865 | cachep->nodelists[node] = l3; | 884 | cachep->nodelists[node] = l3; |
866 | } | 885 | } |
867 | 886 | ||
868 | spin_lock_irq(&cachep->nodelists[node]->list_lock); | 887 | spin_lock_irq(&cachep->nodelists[node]->list_lock); |
869 | cachep->nodelists[node]->free_limit = | 888 | cachep->nodelists[node]->free_limit = |
870 | (1 + nr_cpus_node(node)) * | 889 | (1 + nr_cpus_node(node)) * |
871 | cachep->batchcount + cachep->num; | 890 | cachep->batchcount + cachep->num; |
872 | spin_unlock_irq(&cachep->nodelists[node]->list_lock); | 891 | spin_unlock_irq(&cachep->nodelists[node]->list_lock); |
873 | } | 892 | } |
874 | 893 | ||
875 | /* Now we can go ahead with allocating the shared array's | 894 | /* Now we can go ahead with allocating the shared array's |
876 | & array cache's */ | 895 | & array cache's */ |
877 | list_for_each_entry(cachep, &cache_chain, next) { | 896 | list_for_each_entry(cachep, &cache_chain, next) { |
897 | struct array_cache *nc; | ||
898 | |||
878 | nc = alloc_arraycache(node, cachep->limit, | 899 | nc = alloc_arraycache(node, cachep->limit, |
879 | cachep->batchcount); | 900 | cachep->batchcount); |
880 | if (!nc) | 901 | if (!nc) |
881 | goto bad; | 902 | goto bad; |
882 | cachep->array[cpu] = nc; | 903 | cachep->array[cpu] = nc; |
@@ -885,16 +906,17 @@ static int __devinit cpuup_callback(struct notifier_block *nfb, | |||
885 | BUG_ON(!l3); | 906 | BUG_ON(!l3); |
886 | if (!l3->shared) { | 907 | if (!l3->shared) { |
887 | if (!(nc = alloc_arraycache(node, | 908 | if (!(nc = alloc_arraycache(node, |
888 | cachep->shared*cachep->batchcount, | 909 | cachep->shared * |
889 | 0xbaadf00d))) | 910 | cachep->batchcount, |
890 | goto bad; | 911 | 0xbaadf00d))) |
912 | goto bad; | ||
891 | 913 | ||
892 | /* we are serialised from CPU_DEAD or | 914 | /* we are serialised from CPU_DEAD or |
893 | CPU_UP_CANCELLED by the cpucontrol lock */ | 915 | CPU_UP_CANCELLED by the cpucontrol lock */ |
894 | l3->shared = nc; | 916 | l3->shared = nc; |
895 | } | 917 | } |
896 | } | 918 | } |
897 | up(&cache_chain_sem); | 919 | mutex_unlock(&cache_chain_mutex); |
898 | break; | 920 | break; |
899 | case CPU_ONLINE: | 921 | case CPU_ONLINE: |
900 | start_cpu_timer(cpu); | 922 | start_cpu_timer(cpu); |
@@ -903,7 +925,7 @@ static int __devinit cpuup_callback(struct notifier_block *nfb, | |||
903 | case CPU_DEAD: | 925 | case CPU_DEAD: |
904 | /* fall thru */ | 926 | /* fall thru */ |
905 | case CPU_UP_CANCELED: | 927 | case CPU_UP_CANCELED: |
906 | down(&cache_chain_sem); | 928 | mutex_lock(&cache_chain_mutex); |
907 | 929 | ||
908 | list_for_each_entry(cachep, &cache_chain, next) { | 930 | list_for_each_entry(cachep, &cache_chain, next) { |
909 | struct array_cache *nc; | 931 | struct array_cache *nc; |
@@ -927,13 +949,13 @@ static int __devinit cpuup_callback(struct notifier_block *nfb, | |||
927 | free_block(cachep, nc->entry, nc->avail, node); | 949 | free_block(cachep, nc->entry, nc->avail, node); |
928 | 950 | ||
929 | if (!cpus_empty(mask)) { | 951 | if (!cpus_empty(mask)) { |
930 | spin_unlock(&l3->list_lock); | 952 | spin_unlock(&l3->list_lock); |
931 | goto unlock_cache; | 953 | goto unlock_cache; |
932 | } | 954 | } |
933 | 955 | ||
934 | if (l3->shared) { | 956 | if (l3->shared) { |
935 | free_block(cachep, l3->shared->entry, | 957 | free_block(cachep, l3->shared->entry, |
936 | l3->shared->avail, node); | 958 | l3->shared->avail, node); |
937 | kfree(l3->shared); | 959 | kfree(l3->shared); |
938 | l3->shared = NULL; | 960 | l3->shared = NULL; |
939 | } | 961 | } |
@@ -951,17 +973,17 @@ static int __devinit cpuup_callback(struct notifier_block *nfb, | |||
951 | } else { | 973 | } else { |
952 | spin_unlock(&l3->list_lock); | 974 | spin_unlock(&l3->list_lock); |
953 | } | 975 | } |
954 | unlock_cache: | 976 | unlock_cache: |
955 | spin_unlock_irq(&cachep->spinlock); | 977 | spin_unlock_irq(&cachep->spinlock); |
956 | kfree(nc); | 978 | kfree(nc); |
957 | } | 979 | } |
958 | up(&cache_chain_sem); | 980 | mutex_unlock(&cache_chain_mutex); |
959 | break; | 981 | break; |
960 | #endif | 982 | #endif |
961 | } | 983 | } |
962 | return NOTIFY_OK; | 984 | return NOTIFY_OK; |
963 | bad: | 985 | bad: |
964 | up(&cache_chain_sem); | 986 | mutex_unlock(&cache_chain_mutex); |
965 | return NOTIFY_BAD; | 987 | return NOTIFY_BAD; |
966 | } | 988 | } |
967 | 989 | ||
@@ -970,8 +992,7 @@ static struct notifier_block cpucache_notifier = { &cpuup_callback, NULL, 0 }; | |||
970 | /* | 992 | /* |
971 | * swap the static kmem_list3 with kmalloced memory | 993 | * swap the static kmem_list3 with kmalloced memory |
972 | */ | 994 | */ |
973 | static void init_list(kmem_cache_t *cachep, struct kmem_list3 *list, | 995 | static void init_list(kmem_cache_t *cachep, struct kmem_list3 *list, int nodeid) |
974 | int nodeid) | ||
975 | { | 996 | { |
976 | struct kmem_list3 *ptr; | 997 | struct kmem_list3 *ptr; |
977 | 998 | ||
@@ -1030,7 +1051,6 @@ void __init kmem_cache_init(void) | |||
1030 | */ | 1051 | */ |
1031 | 1052 | ||
1032 | /* 1) create the cache_cache */ | 1053 | /* 1) create the cache_cache */ |
1033 | init_MUTEX(&cache_chain_sem); | ||
1034 | INIT_LIST_HEAD(&cache_chain); | 1054 | INIT_LIST_HEAD(&cache_chain); |
1035 | list_add(&cache_cache.next, &cache_chain); | 1055 | list_add(&cache_cache.next, &cache_chain); |
1036 | cache_cache.colour_off = cache_line_size(); | 1056 | cache_cache.colour_off = cache_line_size(); |
@@ -1040,14 +1060,14 @@ void __init kmem_cache_init(void) | |||
1040 | cache_cache.objsize = ALIGN(cache_cache.objsize, cache_line_size()); | 1060 | cache_cache.objsize = ALIGN(cache_cache.objsize, cache_line_size()); |
1041 | 1061 | ||
1042 | cache_estimate(0, cache_cache.objsize, cache_line_size(), 0, | 1062 | cache_estimate(0, cache_cache.objsize, cache_line_size(), 0, |
1043 | &left_over, &cache_cache.num); | 1063 | &left_over, &cache_cache.num); |
1044 | if (!cache_cache.num) | 1064 | if (!cache_cache.num) |
1045 | BUG(); | 1065 | BUG(); |
1046 | 1066 | ||
1047 | cache_cache.colour = left_over/cache_cache.colour_off; | 1067 | cache_cache.colour = left_over / cache_cache.colour_off; |
1048 | cache_cache.colour_next = 0; | 1068 | cache_cache.colour_next = 0; |
1049 | cache_cache.slab_size = ALIGN(cache_cache.num*sizeof(kmem_bufctl_t) + | 1069 | cache_cache.slab_size = ALIGN(cache_cache.num * sizeof(kmem_bufctl_t) + |
1050 | sizeof(struct slab), cache_line_size()); | 1070 | sizeof(struct slab), cache_line_size()); |
1051 | 1071 | ||
1052 | /* 2+3) create the kmalloc caches */ | 1072 | /* 2+3) create the kmalloc caches */ |
1053 | sizes = malloc_sizes; | 1073 | sizes = malloc_sizes; |
@@ -1059,14 +1079,18 @@ void __init kmem_cache_init(void) | |||
1059 | */ | 1079 | */ |
1060 | 1080 | ||
1061 | sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name, | 1081 | sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name, |
1062 | sizes[INDEX_AC].cs_size, ARCH_KMALLOC_MINALIGN, | 1082 | sizes[INDEX_AC].cs_size, |
1063 | (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL); | 1083 | ARCH_KMALLOC_MINALIGN, |
1084 | (ARCH_KMALLOC_FLAGS | | ||
1085 | SLAB_PANIC), NULL, NULL); | ||
1064 | 1086 | ||
1065 | if (INDEX_AC != INDEX_L3) | 1087 | if (INDEX_AC != INDEX_L3) |
1066 | sizes[INDEX_L3].cs_cachep = | 1088 | sizes[INDEX_L3].cs_cachep = |
1067 | kmem_cache_create(names[INDEX_L3].name, | 1089 | kmem_cache_create(names[INDEX_L3].name, |
1068 | sizes[INDEX_L3].cs_size, ARCH_KMALLOC_MINALIGN, | 1090 | sizes[INDEX_L3].cs_size, |
1069 | (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL); | 1091 | ARCH_KMALLOC_MINALIGN, |
1092 | (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, | ||
1093 | NULL); | ||
1070 | 1094 | ||
1071 | while (sizes->cs_size != ULONG_MAX) { | 1095 | while (sizes->cs_size != ULONG_MAX) { |
1072 | /* | 1096 | /* |
@@ -1076,35 +1100,41 @@ void __init kmem_cache_init(void) | |||
1076 | * Note for systems short on memory removing the alignment will | 1100 | * Note for systems short on memory removing the alignment will |
1077 | * allow tighter packing of the smaller caches. | 1101 | * allow tighter packing of the smaller caches. |
1078 | */ | 1102 | */ |
1079 | if(!sizes->cs_cachep) | 1103 | if (!sizes->cs_cachep) |
1080 | sizes->cs_cachep = kmem_cache_create(names->name, | 1104 | sizes->cs_cachep = kmem_cache_create(names->name, |
1081 | sizes->cs_size, ARCH_KMALLOC_MINALIGN, | 1105 | sizes->cs_size, |
1082 | (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL); | 1106 | ARCH_KMALLOC_MINALIGN, |
1107 | (ARCH_KMALLOC_FLAGS | ||
1108 | | SLAB_PANIC), | ||
1109 | NULL, NULL); | ||
1083 | 1110 | ||
1084 | /* Inc off-slab bufctl limit until the ceiling is hit. */ | 1111 | /* Inc off-slab bufctl limit until the ceiling is hit. */ |
1085 | if (!(OFF_SLAB(sizes->cs_cachep))) { | 1112 | if (!(OFF_SLAB(sizes->cs_cachep))) { |
1086 | offslab_limit = sizes->cs_size-sizeof(struct slab); | 1113 | offslab_limit = sizes->cs_size - sizeof(struct slab); |
1087 | offslab_limit /= sizeof(kmem_bufctl_t); | 1114 | offslab_limit /= sizeof(kmem_bufctl_t); |
1088 | } | 1115 | } |
1089 | 1116 | ||
1090 | sizes->cs_dmacachep = kmem_cache_create(names->name_dma, | 1117 | sizes->cs_dmacachep = kmem_cache_create(names->name_dma, |
1091 | sizes->cs_size, ARCH_KMALLOC_MINALIGN, | 1118 | sizes->cs_size, |
1092 | (ARCH_KMALLOC_FLAGS | SLAB_CACHE_DMA | SLAB_PANIC), | 1119 | ARCH_KMALLOC_MINALIGN, |
1093 | NULL, NULL); | 1120 | (ARCH_KMALLOC_FLAGS | |
1121 | SLAB_CACHE_DMA | | ||
1122 | SLAB_PANIC), NULL, | ||
1123 | NULL); | ||
1094 | 1124 | ||
1095 | sizes++; | 1125 | sizes++; |
1096 | names++; | 1126 | names++; |
1097 | } | 1127 | } |
1098 | /* 4) Replace the bootstrap head arrays */ | 1128 | /* 4) Replace the bootstrap head arrays */ |
1099 | { | 1129 | { |
1100 | void * ptr; | 1130 | void *ptr; |
1101 | 1131 | ||
1102 | ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL); | 1132 | ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL); |
1103 | 1133 | ||
1104 | local_irq_disable(); | 1134 | local_irq_disable(); |
1105 | BUG_ON(ac_data(&cache_cache) != &initarray_cache.cache); | 1135 | BUG_ON(ac_data(&cache_cache) != &initarray_cache.cache); |
1106 | memcpy(ptr, ac_data(&cache_cache), | 1136 | memcpy(ptr, ac_data(&cache_cache), |
1107 | sizeof(struct arraycache_init)); | 1137 | sizeof(struct arraycache_init)); |
1108 | cache_cache.array[smp_processor_id()] = ptr; | 1138 | cache_cache.array[smp_processor_id()] = ptr; |
1109 | local_irq_enable(); | 1139 | local_irq_enable(); |
1110 | 1140 | ||
@@ -1112,11 +1142,11 @@ void __init kmem_cache_init(void) | |||
1112 | 1142 | ||
1113 | local_irq_disable(); | 1143 | local_irq_disable(); |
1114 | BUG_ON(ac_data(malloc_sizes[INDEX_AC].cs_cachep) | 1144 | BUG_ON(ac_data(malloc_sizes[INDEX_AC].cs_cachep) |
1115 | != &initarray_generic.cache); | 1145 | != &initarray_generic.cache); |
1116 | memcpy(ptr, ac_data(malloc_sizes[INDEX_AC].cs_cachep), | 1146 | memcpy(ptr, ac_data(malloc_sizes[INDEX_AC].cs_cachep), |
1117 | sizeof(struct arraycache_init)); | 1147 | sizeof(struct arraycache_init)); |
1118 | malloc_sizes[INDEX_AC].cs_cachep->array[smp_processor_id()] = | 1148 | malloc_sizes[INDEX_AC].cs_cachep->array[smp_processor_id()] = |
1119 | ptr; | 1149 | ptr; |
1120 | local_irq_enable(); | 1150 | local_irq_enable(); |
1121 | } | 1151 | } |
1122 | /* 5) Replace the bootstrap kmem_list3's */ | 1152 | /* 5) Replace the bootstrap kmem_list3's */ |
@@ -1124,16 +1154,16 @@ void __init kmem_cache_init(void) | |||
1124 | int node; | 1154 | int node; |
1125 | /* Replace the static kmem_list3 structures for the boot cpu */ | 1155 | /* Replace the static kmem_list3 structures for the boot cpu */ |
1126 | init_list(&cache_cache, &initkmem_list3[CACHE_CACHE], | 1156 | init_list(&cache_cache, &initkmem_list3[CACHE_CACHE], |
1127 | numa_node_id()); | 1157 | numa_node_id()); |
1128 | 1158 | ||
1129 | for_each_online_node(node) { | 1159 | for_each_online_node(node) { |
1130 | init_list(malloc_sizes[INDEX_AC].cs_cachep, | 1160 | init_list(malloc_sizes[INDEX_AC].cs_cachep, |
1131 | &initkmem_list3[SIZE_AC+node], node); | 1161 | &initkmem_list3[SIZE_AC + node], node); |
1132 | 1162 | ||
1133 | if (INDEX_AC != INDEX_L3) { | 1163 | if (INDEX_AC != INDEX_L3) { |
1134 | init_list(malloc_sizes[INDEX_L3].cs_cachep, | 1164 | init_list(malloc_sizes[INDEX_L3].cs_cachep, |
1135 | &initkmem_list3[SIZE_L3+node], | 1165 | &initkmem_list3[SIZE_L3 + node], |
1136 | node); | 1166 | node); |
1137 | } | 1167 | } |
1138 | } | 1168 | } |
1139 | } | 1169 | } |
@@ -1141,10 +1171,10 @@ void __init kmem_cache_init(void) | |||
1141 | /* 6) resize the head arrays to their final sizes */ | 1171 | /* 6) resize the head arrays to their final sizes */ |
1142 | { | 1172 | { |
1143 | kmem_cache_t *cachep; | 1173 | kmem_cache_t *cachep; |
1144 | down(&cache_chain_sem); | 1174 | mutex_lock(&cache_chain_mutex); |
1145 | list_for_each_entry(cachep, &cache_chain, next) | 1175 | list_for_each_entry(cachep, &cache_chain, next) |
1146 | enable_cpucache(cachep); | 1176 | enable_cpucache(cachep); |
1147 | up(&cache_chain_sem); | 1177 | mutex_unlock(&cache_chain_mutex); |
1148 | } | 1178 | } |
1149 | 1179 | ||
1150 | /* Done! */ | 1180 | /* Done! */ |
@@ -1169,7 +1199,7 @@ static int __init cpucache_init(void) | |||
1169 | * pages to gfp. | 1199 | * pages to gfp. |
1170 | */ | 1200 | */ |
1171 | for_each_online_cpu(cpu) | 1201 | for_each_online_cpu(cpu) |
1172 | start_cpu_timer(cpu); | 1202 | start_cpu_timer(cpu); |
1173 | 1203 | ||
1174 | return 0; | 1204 | return 0; |
1175 | } | 1205 | } |
@@ -1190,11 +1220,7 @@ static void *kmem_getpages(kmem_cache_t *cachep, gfp_t flags, int nodeid) | |||
1190 | int i; | 1220 | int i; |
1191 | 1221 | ||
1192 | flags |= cachep->gfpflags; | 1222 | flags |= cachep->gfpflags; |
1193 | if (likely(nodeid == -1)) { | 1223 | page = alloc_pages_node(nodeid, flags, cachep->gfporder); |
1194 | page = alloc_pages(flags, cachep->gfporder); | ||
1195 | } else { | ||
1196 | page = alloc_pages_node(nodeid, flags, cachep->gfporder); | ||
1197 | } | ||
1198 | if (!page) | 1224 | if (!page) |
1199 | return NULL; | 1225 | return NULL; |
1200 | addr = page_address(page); | 1226 | addr = page_address(page); |
@@ -1215,7 +1241,7 @@ static void *kmem_getpages(kmem_cache_t *cachep, gfp_t flags, int nodeid) | |||
1215 | */ | 1241 | */ |
1216 | static void kmem_freepages(kmem_cache_t *cachep, void *addr) | 1242 | static void kmem_freepages(kmem_cache_t *cachep, void *addr) |
1217 | { | 1243 | { |
1218 | unsigned long i = (1<<cachep->gfporder); | 1244 | unsigned long i = (1 << cachep->gfporder); |
1219 | struct page *page = virt_to_page(addr); | 1245 | struct page *page = virt_to_page(addr); |
1220 | const unsigned long nr_freed = i; | 1246 | const unsigned long nr_freed = i; |
1221 | 1247 | ||
@@ -1228,13 +1254,13 @@ static void kmem_freepages(kmem_cache_t *cachep, void *addr) | |||
1228 | if (current->reclaim_state) | 1254 | if (current->reclaim_state) |
1229 | current->reclaim_state->reclaimed_slab += nr_freed; | 1255 | current->reclaim_state->reclaimed_slab += nr_freed; |
1230 | free_pages((unsigned long)addr, cachep->gfporder); | 1256 | free_pages((unsigned long)addr, cachep->gfporder); |
1231 | if (cachep->flags & SLAB_RECLAIM_ACCOUNT) | 1257 | if (cachep->flags & SLAB_RECLAIM_ACCOUNT) |
1232 | atomic_sub(1<<cachep->gfporder, &slab_reclaim_pages); | 1258 | atomic_sub(1 << cachep->gfporder, &slab_reclaim_pages); |
1233 | } | 1259 | } |
1234 | 1260 | ||
1235 | static void kmem_rcu_free(struct rcu_head *head) | 1261 | static void kmem_rcu_free(struct rcu_head *head) |
1236 | { | 1262 | { |
1237 | struct slab_rcu *slab_rcu = (struct slab_rcu *) head; | 1263 | struct slab_rcu *slab_rcu = (struct slab_rcu *)head; |
1238 | kmem_cache_t *cachep = slab_rcu->cachep; | 1264 | kmem_cache_t *cachep = slab_rcu->cachep; |
1239 | 1265 | ||
1240 | kmem_freepages(cachep, slab_rcu->addr); | 1266 | kmem_freepages(cachep, slab_rcu->addr); |
@@ -1246,19 +1272,19 @@ static void kmem_rcu_free(struct rcu_head *head) | |||
1246 | 1272 | ||
1247 | #ifdef CONFIG_DEBUG_PAGEALLOC | 1273 | #ifdef CONFIG_DEBUG_PAGEALLOC |
1248 | static void store_stackinfo(kmem_cache_t *cachep, unsigned long *addr, | 1274 | static void store_stackinfo(kmem_cache_t *cachep, unsigned long *addr, |
1249 | unsigned long caller) | 1275 | unsigned long caller) |
1250 | { | 1276 | { |
1251 | int size = obj_reallen(cachep); | 1277 | int size = obj_reallen(cachep); |
1252 | 1278 | ||
1253 | addr = (unsigned long *)&((char*)addr)[obj_dbghead(cachep)]; | 1279 | addr = (unsigned long *)&((char *)addr)[obj_dbghead(cachep)]; |
1254 | 1280 | ||
1255 | if (size < 5*sizeof(unsigned long)) | 1281 | if (size < 5 * sizeof(unsigned long)) |
1256 | return; | 1282 | return; |
1257 | 1283 | ||
1258 | *addr++=0x12345678; | 1284 | *addr++ = 0x12345678; |
1259 | *addr++=caller; | 1285 | *addr++ = caller; |
1260 | *addr++=smp_processor_id(); | 1286 | *addr++ = smp_processor_id(); |
1261 | size -= 3*sizeof(unsigned long); | 1287 | size -= 3 * sizeof(unsigned long); |
1262 | { | 1288 | { |
1263 | unsigned long *sptr = &caller; | 1289 | unsigned long *sptr = &caller; |
1264 | unsigned long svalue; | 1290 | unsigned long svalue; |
@@ -1266,7 +1292,7 @@ static void store_stackinfo(kmem_cache_t *cachep, unsigned long *addr, | |||
1266 | while (!kstack_end(sptr)) { | 1292 | while (!kstack_end(sptr)) { |
1267 | svalue = *sptr++; | 1293 | svalue = *sptr++; |
1268 | if (kernel_text_address(svalue)) { | 1294 | if (kernel_text_address(svalue)) { |
1269 | *addr++=svalue; | 1295 | *addr++ = svalue; |
1270 | size -= sizeof(unsigned long); | 1296 | size -= sizeof(unsigned long); |
1271 | if (size <= sizeof(unsigned long)) | 1297 | if (size <= sizeof(unsigned long)) |
1272 | break; | 1298 | break; |
@@ -1274,25 +1300,25 @@ static void store_stackinfo(kmem_cache_t *cachep, unsigned long *addr, | |||
1274 | } | 1300 | } |
1275 | 1301 | ||
1276 | } | 1302 | } |
1277 | *addr++=0x87654321; | 1303 | *addr++ = 0x87654321; |
1278 | } | 1304 | } |
1279 | #endif | 1305 | #endif |
1280 | 1306 | ||
1281 | static void poison_obj(kmem_cache_t *cachep, void *addr, unsigned char val) | 1307 | static void poison_obj(kmem_cache_t *cachep, void *addr, unsigned char val) |
1282 | { | 1308 | { |
1283 | int size = obj_reallen(cachep); | 1309 | int size = obj_reallen(cachep); |
1284 | addr = &((char*)addr)[obj_dbghead(cachep)]; | 1310 | addr = &((char *)addr)[obj_dbghead(cachep)]; |
1285 | 1311 | ||
1286 | memset(addr, val, size); | 1312 | memset(addr, val, size); |
1287 | *(unsigned char *)(addr+size-1) = POISON_END; | 1313 | *(unsigned char *)(addr + size - 1) = POISON_END; |
1288 | } | 1314 | } |
1289 | 1315 | ||
1290 | static void dump_line(char *data, int offset, int limit) | 1316 | static void dump_line(char *data, int offset, int limit) |
1291 | { | 1317 | { |
1292 | int i; | 1318 | int i; |
1293 | printk(KERN_ERR "%03x:", offset); | 1319 | printk(KERN_ERR "%03x:", offset); |
1294 | for (i=0;i<limit;i++) { | 1320 | for (i = 0; i < limit; i++) { |
1295 | printk(" %02x", (unsigned char)data[offset+i]); | 1321 | printk(" %02x", (unsigned char)data[offset + i]); |
1296 | } | 1322 | } |
1297 | printk("\n"); | 1323 | printk("\n"); |
1298 | } | 1324 | } |
@@ -1307,24 +1333,24 @@ static void print_objinfo(kmem_cache_t *cachep, void *objp, int lines) | |||
1307 | 1333 | ||
1308 | if (cachep->flags & SLAB_RED_ZONE) { | 1334 | if (cachep->flags & SLAB_RED_ZONE) { |
1309 | printk(KERN_ERR "Redzone: 0x%lx/0x%lx.\n", | 1335 | printk(KERN_ERR "Redzone: 0x%lx/0x%lx.\n", |
1310 | *dbg_redzone1(cachep, objp), | 1336 | *dbg_redzone1(cachep, objp), |
1311 | *dbg_redzone2(cachep, objp)); | 1337 | *dbg_redzone2(cachep, objp)); |
1312 | } | 1338 | } |
1313 | 1339 | ||
1314 | if (cachep->flags & SLAB_STORE_USER) { | 1340 | if (cachep->flags & SLAB_STORE_USER) { |
1315 | printk(KERN_ERR "Last user: [<%p>]", | 1341 | printk(KERN_ERR "Last user: [<%p>]", |
1316 | *dbg_userword(cachep, objp)); | 1342 | *dbg_userword(cachep, objp)); |
1317 | print_symbol("(%s)", | 1343 | print_symbol("(%s)", |
1318 | (unsigned long)*dbg_userword(cachep, objp)); | 1344 | (unsigned long)*dbg_userword(cachep, objp)); |
1319 | printk("\n"); | 1345 | printk("\n"); |
1320 | } | 1346 | } |
1321 | realobj = (char*)objp+obj_dbghead(cachep); | 1347 | realobj = (char *)objp + obj_dbghead(cachep); |
1322 | size = obj_reallen(cachep); | 1348 | size = obj_reallen(cachep); |
1323 | for (i=0; i<size && lines;i+=16, lines--) { | 1349 | for (i = 0; i < size && lines; i += 16, lines--) { |
1324 | int limit; | 1350 | int limit; |
1325 | limit = 16; | 1351 | limit = 16; |
1326 | if (i+limit > size) | 1352 | if (i + limit > size) |
1327 | limit = size-i; | 1353 | limit = size - i; |
1328 | dump_line(realobj, i, limit); | 1354 | dump_line(realobj, i, limit); |
1329 | } | 1355 | } |
1330 | } | 1356 | } |
@@ -1335,27 +1361,28 @@ static void check_poison_obj(kmem_cache_t *cachep, void *objp) | |||
1335 | int size, i; | 1361 | int size, i; |
1336 | int lines = 0; | 1362 | int lines = 0; |
1337 | 1363 | ||
1338 | realobj = (char*)objp+obj_dbghead(cachep); | 1364 | realobj = (char *)objp + obj_dbghead(cachep); |
1339 | size = obj_reallen(cachep); | 1365 | size = obj_reallen(cachep); |
1340 | 1366 | ||
1341 | for (i=0;i<size;i++) { | 1367 | for (i = 0; i < size; i++) { |
1342 | char exp = POISON_FREE; | 1368 | char exp = POISON_FREE; |
1343 | if (i == size-1) | 1369 | if (i == size - 1) |
1344 | exp = POISON_END; | 1370 | exp = POISON_END; |
1345 | if (realobj[i] != exp) { | 1371 | if (realobj[i] != exp) { |
1346 | int limit; | 1372 | int limit; |
1347 | /* Mismatch ! */ | 1373 | /* Mismatch ! */ |
1348 | /* Print header */ | 1374 | /* Print header */ |
1349 | if (lines == 0) { | 1375 | if (lines == 0) { |
1350 | printk(KERN_ERR "Slab corruption: start=%p, len=%d\n", | 1376 | printk(KERN_ERR |
1351 | realobj, size); | 1377 | "Slab corruption: start=%p, len=%d\n", |
1378 | realobj, size); | ||
1352 | print_objinfo(cachep, objp, 0); | 1379 | print_objinfo(cachep, objp, 0); |
1353 | } | 1380 | } |
1354 | /* Hexdump the affected line */ | 1381 | /* Hexdump the affected line */ |
1355 | i = (i/16)*16; | 1382 | i = (i / 16) * 16; |
1356 | limit = 16; | 1383 | limit = 16; |
1357 | if (i+limit > size) | 1384 | if (i + limit > size) |
1358 | limit = size-i; | 1385 | limit = size - i; |
1359 | dump_line(realobj, i, limit); | 1386 | dump_line(realobj, i, limit); |
1360 | i += 16; | 1387 | i += 16; |
1361 | lines++; | 1388 | lines++; |
@@ -1368,22 +1395,22 @@ static void check_poison_obj(kmem_cache_t *cachep, void *objp) | |||
1368 | /* Print some data about the neighboring objects, if they | 1395 | /* Print some data about the neighboring objects, if they |
1369 | * exist: | 1396 | * exist: |
1370 | */ | 1397 | */ |
1371 | struct slab *slabp = GET_PAGE_SLAB(virt_to_page(objp)); | 1398 | struct slab *slabp = page_get_slab(virt_to_page(objp)); |
1372 | int objnr; | 1399 | int objnr; |
1373 | 1400 | ||
1374 | objnr = (objp-slabp->s_mem)/cachep->objsize; | 1401 | objnr = (objp - slabp->s_mem) / cachep->objsize; |
1375 | if (objnr) { | 1402 | if (objnr) { |
1376 | objp = slabp->s_mem+(objnr-1)*cachep->objsize; | 1403 | objp = slabp->s_mem + (objnr - 1) * cachep->objsize; |
1377 | realobj = (char*)objp+obj_dbghead(cachep); | 1404 | realobj = (char *)objp + obj_dbghead(cachep); |
1378 | printk(KERN_ERR "Prev obj: start=%p, len=%d\n", | 1405 | printk(KERN_ERR "Prev obj: start=%p, len=%d\n", |
1379 | realobj, size); | 1406 | realobj, size); |
1380 | print_objinfo(cachep, objp, 2); | 1407 | print_objinfo(cachep, objp, 2); |
1381 | } | 1408 | } |
1382 | if (objnr+1 < cachep->num) { | 1409 | if (objnr + 1 < cachep->num) { |
1383 | objp = slabp->s_mem+(objnr+1)*cachep->objsize; | 1410 | objp = slabp->s_mem + (objnr + 1) * cachep->objsize; |
1384 | realobj = (char*)objp+obj_dbghead(cachep); | 1411 | realobj = (char *)objp + obj_dbghead(cachep); |
1385 | printk(KERN_ERR "Next obj: start=%p, len=%d\n", | 1412 | printk(KERN_ERR "Next obj: start=%p, len=%d\n", |
1386 | realobj, size); | 1413 | realobj, size); |
1387 | print_objinfo(cachep, objp, 2); | 1414 | print_objinfo(cachep, objp, 2); |
1388 | } | 1415 | } |
1389 | } | 1416 | } |
@@ -1394,7 +1421,7 @@ static void check_poison_obj(kmem_cache_t *cachep, void *objp) | |||
1394 | * Before calling the slab must have been unlinked from the cache. | 1421 | * Before calling the slab must have been unlinked from the cache. |
1395 | * The cache-lock is not held/needed. | 1422 | * The cache-lock is not held/needed. |
1396 | */ | 1423 | */ |
1397 | static void slab_destroy (kmem_cache_t *cachep, struct slab *slabp) | 1424 | static void slab_destroy(kmem_cache_t *cachep, struct slab *slabp) |
1398 | { | 1425 | { |
1399 | void *addr = slabp->s_mem - slabp->colouroff; | 1426 | void *addr = slabp->s_mem - slabp->colouroff; |
1400 | 1427 | ||
@@ -1405,8 +1432,11 @@ static void slab_destroy (kmem_cache_t *cachep, struct slab *slabp) | |||
1405 | 1432 | ||
1406 | if (cachep->flags & SLAB_POISON) { | 1433 | if (cachep->flags & SLAB_POISON) { |
1407 | #ifdef CONFIG_DEBUG_PAGEALLOC | 1434 | #ifdef CONFIG_DEBUG_PAGEALLOC |
1408 | if ((cachep->objsize%PAGE_SIZE)==0 && OFF_SLAB(cachep)) | 1435 | if ((cachep->objsize % PAGE_SIZE) == 0 |
1409 | kernel_map_pages(virt_to_page(objp), cachep->objsize/PAGE_SIZE,1); | 1436 | && OFF_SLAB(cachep)) |
1437 | kernel_map_pages(virt_to_page(objp), | ||
1438 | cachep->objsize / PAGE_SIZE, | ||
1439 | 1); | ||
1410 | else | 1440 | else |
1411 | check_poison_obj(cachep, objp); | 1441 | check_poison_obj(cachep, objp); |
1412 | #else | 1442 | #else |
@@ -1416,20 +1446,20 @@ static void slab_destroy (kmem_cache_t *cachep, struct slab *slabp) | |||
1416 | if (cachep->flags & SLAB_RED_ZONE) { | 1446 | if (cachep->flags & SLAB_RED_ZONE) { |
1417 | if (*dbg_redzone1(cachep, objp) != RED_INACTIVE) | 1447 | if (*dbg_redzone1(cachep, objp) != RED_INACTIVE) |
1418 | slab_error(cachep, "start of a freed object " | 1448 | slab_error(cachep, "start of a freed object " |
1419 | "was overwritten"); | 1449 | "was overwritten"); |
1420 | if (*dbg_redzone2(cachep, objp) != RED_INACTIVE) | 1450 | if (*dbg_redzone2(cachep, objp) != RED_INACTIVE) |
1421 | slab_error(cachep, "end of a freed object " | 1451 | slab_error(cachep, "end of a freed object " |
1422 | "was overwritten"); | 1452 | "was overwritten"); |
1423 | } | 1453 | } |
1424 | if (cachep->dtor && !(cachep->flags & SLAB_POISON)) | 1454 | if (cachep->dtor && !(cachep->flags & SLAB_POISON)) |
1425 | (cachep->dtor)(objp+obj_dbghead(cachep), cachep, 0); | 1455 | (cachep->dtor) (objp + obj_dbghead(cachep), cachep, 0); |
1426 | } | 1456 | } |
1427 | #else | 1457 | #else |
1428 | if (cachep->dtor) { | 1458 | if (cachep->dtor) { |
1429 | int i; | 1459 | int i; |
1430 | for (i = 0; i < cachep->num; i++) { | 1460 | for (i = 0; i < cachep->num; i++) { |
1431 | void* objp = slabp->s_mem+cachep->objsize*i; | 1461 | void *objp = slabp->s_mem + cachep->objsize * i; |
1432 | (cachep->dtor)(objp, cachep, 0); | 1462 | (cachep->dtor) (objp, cachep, 0); |
1433 | } | 1463 | } |
1434 | } | 1464 | } |
1435 | #endif | 1465 | #endif |
@@ -1437,7 +1467,7 @@ static void slab_destroy (kmem_cache_t *cachep, struct slab *slabp) | |||
1437 | if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) { | 1467 | if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) { |
1438 | struct slab_rcu *slab_rcu; | 1468 | struct slab_rcu *slab_rcu; |
1439 | 1469 | ||
1440 | slab_rcu = (struct slab_rcu *) slabp; | 1470 | slab_rcu = (struct slab_rcu *)slabp; |
1441 | slab_rcu->cachep = cachep; | 1471 | slab_rcu->cachep = cachep; |
1442 | slab_rcu->addr = addr; | 1472 | slab_rcu->addr = addr; |
1443 | call_rcu(&slab_rcu->head, kmem_rcu_free); | 1473 | call_rcu(&slab_rcu->head, kmem_rcu_free); |
@@ -1455,11 +1485,58 @@ static inline void set_up_list3s(kmem_cache_t *cachep, int index) | |||
1455 | int node; | 1485 | int node; |
1456 | 1486 | ||
1457 | for_each_online_node(node) { | 1487 | for_each_online_node(node) { |
1458 | cachep->nodelists[node] = &initkmem_list3[index+node]; | 1488 | cachep->nodelists[node] = &initkmem_list3[index + node]; |
1459 | cachep->nodelists[node]->next_reap = jiffies + | 1489 | cachep->nodelists[node]->next_reap = jiffies + |
1460 | REAPTIMEOUT_LIST3 + | 1490 | REAPTIMEOUT_LIST3 + |
1461 | ((unsigned long)cachep)%REAPTIMEOUT_LIST3; | 1491 | ((unsigned long)cachep) % REAPTIMEOUT_LIST3; |
1492 | } | ||
1493 | } | ||
1494 | |||
1495 | /** | ||
1496 | * calculate_slab_order - calculate size (page order) of slabs and the number | ||
1497 | * of objects per slab. | ||
1498 | * | ||
1499 | * This could be made much more intelligent. For now, try to avoid using | ||
1500 | * high order pages for slabs. When the gfp() functions are more friendly | ||
1501 | * towards high-order requests, this should be changed. | ||
1502 | */ | ||
1503 | static inline size_t calculate_slab_order(kmem_cache_t *cachep, size_t size, | ||
1504 | size_t align, gfp_t flags) | ||
1505 | { | ||
1506 | size_t left_over = 0; | ||
1507 | |||
1508 | for (;; cachep->gfporder++) { | ||
1509 | unsigned int num; | ||
1510 | size_t remainder; | ||
1511 | |||
1512 | if (cachep->gfporder > MAX_GFP_ORDER) { | ||
1513 | cachep->num = 0; | ||
1514 | break; | ||
1515 | } | ||
1516 | |||
1517 | cache_estimate(cachep->gfporder, size, align, flags, | ||
1518 | &remainder, &num); | ||
1519 | if (!num) | ||
1520 | continue; | ||
1521 | /* More than offslab_limit objects will cause problems */ | ||
1522 | if (flags & CFLGS_OFF_SLAB && cachep->num > offslab_limit) | ||
1523 | break; | ||
1524 | |||
1525 | cachep->num = num; | ||
1526 | left_over = remainder; | ||
1527 | |||
1528 | /* | ||
1529 | * Large number of objects is good, but very large slabs are | ||
1530 | * currently bad for the gfp()s. | ||
1531 | */ | ||
1532 | if (cachep->gfporder >= slab_break_gfp_order) | ||
1533 | break; | ||
1534 | |||
1535 | if ((left_over * 8) <= (PAGE_SIZE << cachep->gfporder)) | ||
1536 | /* Acceptable internal fragmentation */ | ||
1537 | break; | ||
1462 | } | 1538 | } |
1539 | return left_over; | ||
1463 | } | 1540 | } |
1464 | 1541 | ||
1465 | /** | 1542 | /** |
@@ -1508,16 +1585,15 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1508 | * Sanity checks... these are all serious usage bugs. | 1585 | * Sanity checks... these are all serious usage bugs. |
1509 | */ | 1586 | */ |
1510 | if ((!name) || | 1587 | if ((!name) || |
1511 | in_interrupt() || | 1588 | in_interrupt() || |
1512 | (size < BYTES_PER_WORD) || | 1589 | (size < BYTES_PER_WORD) || |
1513 | (size > (1<<MAX_OBJ_ORDER)*PAGE_SIZE) || | 1590 | (size > (1 << MAX_OBJ_ORDER) * PAGE_SIZE) || (dtor && !ctor)) { |
1514 | (dtor && !ctor)) { | 1591 | printk(KERN_ERR "%s: Early error in slab %s\n", |
1515 | printk(KERN_ERR "%s: Early error in slab %s\n", | 1592 | __FUNCTION__, name); |
1516 | __FUNCTION__, name); | 1593 | BUG(); |
1517 | BUG(); | 1594 | } |
1518 | } | ||
1519 | 1595 | ||
1520 | down(&cache_chain_sem); | 1596 | mutex_lock(&cache_chain_mutex); |
1521 | 1597 | ||
1522 | list_for_each(p, &cache_chain) { | 1598 | list_for_each(p, &cache_chain) { |
1523 | kmem_cache_t *pc = list_entry(p, kmem_cache_t, next); | 1599 | kmem_cache_t *pc = list_entry(p, kmem_cache_t, next); |
@@ -1535,11 +1611,11 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1535 | set_fs(old_fs); | 1611 | set_fs(old_fs); |
1536 | if (res) { | 1612 | if (res) { |
1537 | printk("SLAB: cache with size %d has lost its name\n", | 1613 | printk("SLAB: cache with size %d has lost its name\n", |
1538 | pc->objsize); | 1614 | pc->objsize); |
1539 | continue; | 1615 | continue; |
1540 | } | 1616 | } |
1541 | 1617 | ||
1542 | if (!strcmp(pc->name,name)) { | 1618 | if (!strcmp(pc->name, name)) { |
1543 | printk("kmem_cache_create: duplicate cache %s\n", name); | 1619 | printk("kmem_cache_create: duplicate cache %s\n", name); |
1544 | dump_stack(); | 1620 | dump_stack(); |
1545 | goto oops; | 1621 | goto oops; |
@@ -1551,10 +1627,9 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1551 | if ((flags & SLAB_DEBUG_INITIAL) && !ctor) { | 1627 | if ((flags & SLAB_DEBUG_INITIAL) && !ctor) { |
1552 | /* No constructor, but inital state check requested */ | 1628 | /* No constructor, but inital state check requested */ |
1553 | printk(KERN_ERR "%s: No con, but init state check " | 1629 | printk(KERN_ERR "%s: No con, but init state check " |
1554 | "requested - %s\n", __FUNCTION__, name); | 1630 | "requested - %s\n", __FUNCTION__, name); |
1555 | flags &= ~SLAB_DEBUG_INITIAL; | 1631 | flags &= ~SLAB_DEBUG_INITIAL; |
1556 | } | 1632 | } |
1557 | |||
1558 | #if FORCED_DEBUG | 1633 | #if FORCED_DEBUG |
1559 | /* | 1634 | /* |
1560 | * Enable redzoning and last user accounting, except for caches with | 1635 | * Enable redzoning and last user accounting, except for caches with |
@@ -1562,8 +1637,9 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1562 | * above the next power of two: caches with object sizes just above a | 1637 | * above the next power of two: caches with object sizes just above a |
1563 | * power of two have a significant amount of internal fragmentation. | 1638 | * power of two have a significant amount of internal fragmentation. |
1564 | */ | 1639 | */ |
1565 | if ((size < 4096 || fls(size-1) == fls(size-1+3*BYTES_PER_WORD))) | 1640 | if ((size < 4096 |
1566 | flags |= SLAB_RED_ZONE|SLAB_STORE_USER; | 1641 | || fls(size - 1) == fls(size - 1 + 3 * BYTES_PER_WORD))) |
1642 | flags |= SLAB_RED_ZONE | SLAB_STORE_USER; | ||
1567 | if (!(flags & SLAB_DESTROY_BY_RCU)) | 1643 | if (!(flags & SLAB_DESTROY_BY_RCU)) |
1568 | flags |= SLAB_POISON; | 1644 | flags |= SLAB_POISON; |
1569 | #endif | 1645 | #endif |
@@ -1584,9 +1660,9 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1584 | * unaligned accesses for some archs when redzoning is used, and makes | 1660 | * unaligned accesses for some archs when redzoning is used, and makes |
1585 | * sure any on-slab bufctl's are also correctly aligned. | 1661 | * sure any on-slab bufctl's are also correctly aligned. |
1586 | */ | 1662 | */ |
1587 | if (size & (BYTES_PER_WORD-1)) { | 1663 | if (size & (BYTES_PER_WORD - 1)) { |
1588 | size += (BYTES_PER_WORD-1); | 1664 | size += (BYTES_PER_WORD - 1); |
1589 | size &= ~(BYTES_PER_WORD-1); | 1665 | size &= ~(BYTES_PER_WORD - 1); |
1590 | } | 1666 | } |
1591 | 1667 | ||
1592 | /* calculate out the final buffer alignment: */ | 1668 | /* calculate out the final buffer alignment: */ |
@@ -1597,7 +1673,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1597 | * objects into one cacheline. | 1673 | * objects into one cacheline. |
1598 | */ | 1674 | */ |
1599 | ralign = cache_line_size(); | 1675 | ralign = cache_line_size(); |
1600 | while (size <= ralign/2) | 1676 | while (size <= ralign / 2) |
1601 | ralign /= 2; | 1677 | ralign /= 2; |
1602 | } else { | 1678 | } else { |
1603 | ralign = BYTES_PER_WORD; | 1679 | ralign = BYTES_PER_WORD; |
@@ -1606,13 +1682,13 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1606 | if (ralign < ARCH_SLAB_MINALIGN) { | 1682 | if (ralign < ARCH_SLAB_MINALIGN) { |
1607 | ralign = ARCH_SLAB_MINALIGN; | 1683 | ralign = ARCH_SLAB_MINALIGN; |
1608 | if (ralign > BYTES_PER_WORD) | 1684 | if (ralign > BYTES_PER_WORD) |
1609 | flags &= ~(SLAB_RED_ZONE|SLAB_STORE_USER); | 1685 | flags &= ~(SLAB_RED_ZONE | SLAB_STORE_USER); |
1610 | } | 1686 | } |
1611 | /* 3) caller mandated alignment: disables debug if necessary */ | 1687 | /* 3) caller mandated alignment: disables debug if necessary */ |
1612 | if (ralign < align) { | 1688 | if (ralign < align) { |
1613 | ralign = align; | 1689 | ralign = align; |
1614 | if (ralign > BYTES_PER_WORD) | 1690 | if (ralign > BYTES_PER_WORD) |
1615 | flags &= ~(SLAB_RED_ZONE|SLAB_STORE_USER); | 1691 | flags &= ~(SLAB_RED_ZONE | SLAB_STORE_USER); |
1616 | } | 1692 | } |
1617 | /* 4) Store it. Note that the debug code below can reduce | 1693 | /* 4) Store it. Note that the debug code below can reduce |
1618 | * the alignment to BYTES_PER_WORD. | 1694 | * the alignment to BYTES_PER_WORD. |
@@ -1634,7 +1710,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1634 | 1710 | ||
1635 | /* add space for red zone words */ | 1711 | /* add space for red zone words */ |
1636 | cachep->dbghead += BYTES_PER_WORD; | 1712 | cachep->dbghead += BYTES_PER_WORD; |
1637 | size += 2*BYTES_PER_WORD; | 1713 | size += 2 * BYTES_PER_WORD; |
1638 | } | 1714 | } |
1639 | if (flags & SLAB_STORE_USER) { | 1715 | if (flags & SLAB_STORE_USER) { |
1640 | /* user store requires word alignment and | 1716 | /* user store requires word alignment and |
@@ -1645,7 +1721,8 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1645 | size += BYTES_PER_WORD; | 1721 | size += BYTES_PER_WORD; |
1646 | } | 1722 | } |
1647 | #if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC) | 1723 | #if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC) |
1648 | if (size >= malloc_sizes[INDEX_L3+1].cs_size && cachep->reallen > cache_line_size() && size < PAGE_SIZE) { | 1724 | if (size >= malloc_sizes[INDEX_L3 + 1].cs_size |
1725 | && cachep->reallen > cache_line_size() && size < PAGE_SIZE) { | ||
1649 | cachep->dbghead += PAGE_SIZE - size; | 1726 | cachep->dbghead += PAGE_SIZE - size; |
1650 | size = PAGE_SIZE; | 1727 | size = PAGE_SIZE; |
1651 | } | 1728 | } |
@@ -1653,7 +1730,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1653 | #endif | 1730 | #endif |
1654 | 1731 | ||
1655 | /* Determine if the slab management is 'on' or 'off' slab. */ | 1732 | /* Determine if the slab management is 'on' or 'off' slab. */ |
1656 | if (size >= (PAGE_SIZE>>3)) | 1733 | if (size >= (PAGE_SIZE >> 3)) |
1657 | /* | 1734 | /* |
1658 | * Size is large, assume best to place the slab management obj | 1735 | * Size is large, assume best to place the slab management obj |
1659 | * off-slab (should allow better packing of objs). | 1736 | * off-slab (should allow better packing of objs). |
@@ -1670,47 +1747,9 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
1670 | */ | 1747 | */ |
1671 | cachep->gfporder = 0; | 1748 | cachep->gfporder = 0; |
1672 | cache_estimate(cachep->gfporder, size, align, flags, | 1749 | cache_estimate(cachep->gfporder, size, align, flags, |
1673 | &left_over, &cachep->num); | 1750 | &left_over, &cachep->num); |
1674 | } else { | 1751 | } else |
1675 | /* | 1752 | left_over = calculate_slab_order(cachep, size, align, flags); |
1676 | * Calculate size (in pages) of slabs, and the num of objs per | ||
1677 | * slab. This could be made much more intelligent. For now, | ||
1678 | * try to avoid using high page-orders for slabs. When the | ||
1679 | * gfp() funcs are more friendly towards high-order requests, | ||
1680 | * this should be changed. | ||
1681 | */ | ||
1682 | do { | ||
1683 | unsigned int break_flag = 0; | ||
1684 | cal_wastage: | ||
1685 | cache_estimate(cachep->gfporder, size, align, flags, | ||
1686 | &left_over, &cachep->num); | ||
1687 | if (break_flag) | ||
1688 | break; | ||
1689 | if (cachep->gfporder >= MAX_GFP_ORDER) | ||
1690 | break; | ||
1691 | if (!cachep->num) | ||
1692 | goto next; | ||
1693 | if (flags & CFLGS_OFF_SLAB && | ||
1694 | cachep->num > offslab_limit) { | ||
1695 | /* This num of objs will cause problems. */ | ||
1696 | cachep->gfporder--; | ||
1697 | break_flag++; | ||
1698 | goto cal_wastage; | ||
1699 | } | ||
1700 | |||
1701 | /* | ||
1702 | * Large num of objs is good, but v. large slabs are | ||
1703 | * currently bad for the gfp()s. | ||
1704 | */ | ||
1705 | if (cachep->gfporder >= slab_break_gfp_order) | ||
1706 | break; | ||
1707 | |||
1708 | if ((left_over*8) <= (PAGE_SIZE<<cachep->gfporder)) | ||
1709 | break; /* Acceptable internal fragmentation. */ | ||
1710 | next: | ||
1711 | cachep->gfporder++; | ||
1712 | } while (1); | ||
1713 | } | ||
1714 | 1753 | ||
1715 | if (!cachep->num) { | 1754 | if (!cachep->num) { |
1716 | printk("kmem_cache_create: couldn't create cache %s.\n", name); | 1755 | printk("kmem_cache_create: couldn't create cache %s.\n", name); |
@@ -1718,8 +1757,8 @@ next: | |||
1718 | cachep = NULL; | 1757 | cachep = NULL; |
1719 | goto oops; | 1758 | goto oops; |
1720 | } | 1759 | } |
1721 | slab_size = ALIGN(cachep->num*sizeof(kmem_bufctl_t) | 1760 | slab_size = ALIGN(cachep->num * sizeof(kmem_bufctl_t) |
1722 | + sizeof(struct slab), align); | 1761 | + sizeof(struct slab), align); |
1723 | 1762 | ||
1724 | /* | 1763 | /* |
1725 | * If the slab has been placed off-slab, and we have enough space then | 1764 | * If the slab has been placed off-slab, and we have enough space then |
@@ -1732,14 +1771,15 @@ next: | |||
1732 | 1771 | ||
1733 | if (flags & CFLGS_OFF_SLAB) { | 1772 | if (flags & CFLGS_OFF_SLAB) { |
1734 | /* really off slab. No need for manual alignment */ | 1773 | /* really off slab. No need for manual alignment */ |
1735 | slab_size = cachep->num*sizeof(kmem_bufctl_t)+sizeof(struct slab); | 1774 | slab_size = |
1775 | cachep->num * sizeof(kmem_bufctl_t) + sizeof(struct slab); | ||
1736 | } | 1776 | } |
1737 | 1777 | ||
1738 | cachep->colour_off = cache_line_size(); | 1778 | cachep->colour_off = cache_line_size(); |
1739 | /* Offset must be a multiple of the alignment. */ | 1779 | /* Offset must be a multiple of the alignment. */ |
1740 | if (cachep->colour_off < align) | 1780 | if (cachep->colour_off < align) |
1741 | cachep->colour_off = align; | 1781 | cachep->colour_off = align; |
1742 | cachep->colour = left_over/cachep->colour_off; | 1782 | cachep->colour = left_over / cachep->colour_off; |
1743 | cachep->slab_size = slab_size; | 1783 | cachep->slab_size = slab_size; |
1744 | cachep->flags = flags; | 1784 | cachep->flags = flags; |
1745 | cachep->gfpflags = 0; | 1785 | cachep->gfpflags = 0; |
@@ -1766,7 +1806,7 @@ next: | |||
1766 | * the creation of further caches will BUG(). | 1806 | * the creation of further caches will BUG(). |
1767 | */ | 1807 | */ |
1768 | cachep->array[smp_processor_id()] = | 1808 | cachep->array[smp_processor_id()] = |
1769 | &initarray_generic.cache; | 1809 | &initarray_generic.cache; |
1770 | 1810 | ||
1771 | /* If the cache that's used by | 1811 | /* If the cache that's used by |
1772 | * kmalloc(sizeof(kmem_list3)) is the first cache, | 1812 | * kmalloc(sizeof(kmem_list3)) is the first cache, |
@@ -1780,8 +1820,7 @@ next: | |||
1780 | g_cpucache_up = PARTIAL_AC; | 1820 | g_cpucache_up = PARTIAL_AC; |
1781 | } else { | 1821 | } else { |
1782 | cachep->array[smp_processor_id()] = | 1822 | cachep->array[smp_processor_id()] = |
1783 | kmalloc(sizeof(struct arraycache_init), | 1823 | kmalloc(sizeof(struct arraycache_init), GFP_KERNEL); |
1784 | GFP_KERNEL); | ||
1785 | 1824 | ||
1786 | if (g_cpucache_up == PARTIAL_AC) { | 1825 | if (g_cpucache_up == PARTIAL_AC) { |
1787 | set_up_list3s(cachep, SIZE_L3); | 1826 | set_up_list3s(cachep, SIZE_L3); |
@@ -1791,16 +1830,18 @@ next: | |||
1791 | for_each_online_node(node) { | 1830 | for_each_online_node(node) { |
1792 | 1831 | ||
1793 | cachep->nodelists[node] = | 1832 | cachep->nodelists[node] = |
1794 | kmalloc_node(sizeof(struct kmem_list3), | 1833 | kmalloc_node(sizeof |
1795 | GFP_KERNEL, node); | 1834 | (struct kmem_list3), |
1835 | GFP_KERNEL, node); | ||
1796 | BUG_ON(!cachep->nodelists[node]); | 1836 | BUG_ON(!cachep->nodelists[node]); |
1797 | kmem_list3_init(cachep->nodelists[node]); | 1837 | kmem_list3_init(cachep-> |
1838 | nodelists[node]); | ||
1798 | } | 1839 | } |
1799 | } | 1840 | } |
1800 | } | 1841 | } |
1801 | cachep->nodelists[numa_node_id()]->next_reap = | 1842 | cachep->nodelists[numa_node_id()]->next_reap = |
1802 | jiffies + REAPTIMEOUT_LIST3 + | 1843 | jiffies + REAPTIMEOUT_LIST3 + |
1803 | ((unsigned long)cachep)%REAPTIMEOUT_LIST3; | 1844 | ((unsigned long)cachep) % REAPTIMEOUT_LIST3; |
1804 | 1845 | ||
1805 | BUG_ON(!ac_data(cachep)); | 1846 | BUG_ON(!ac_data(cachep)); |
1806 | ac_data(cachep)->avail = 0; | 1847 | ac_data(cachep)->avail = 0; |
@@ -1809,16 +1850,16 @@ next: | |||
1809 | ac_data(cachep)->touched = 0; | 1850 | ac_data(cachep)->touched = 0; |
1810 | cachep->batchcount = 1; | 1851 | cachep->batchcount = 1; |
1811 | cachep->limit = BOOT_CPUCACHE_ENTRIES; | 1852 | cachep->limit = BOOT_CPUCACHE_ENTRIES; |
1812 | } | 1853 | } |
1813 | 1854 | ||
1814 | /* cache setup completed, link it into the list */ | 1855 | /* cache setup completed, link it into the list */ |
1815 | list_add(&cachep->next, &cache_chain); | 1856 | list_add(&cachep->next, &cache_chain); |
1816 | unlock_cpu_hotplug(); | 1857 | unlock_cpu_hotplug(); |
1817 | oops: | 1858 | oops: |
1818 | if (!cachep && (flags & SLAB_PANIC)) | 1859 | if (!cachep && (flags & SLAB_PANIC)) |
1819 | panic("kmem_cache_create(): failed to create slab `%s'\n", | 1860 | panic("kmem_cache_create(): failed to create slab `%s'\n", |
1820 | name); | 1861 | name); |
1821 | up(&cache_chain_sem); | 1862 | mutex_unlock(&cache_chain_mutex); |
1822 | return cachep; | 1863 | return cachep; |
1823 | } | 1864 | } |
1824 | EXPORT_SYMBOL(kmem_cache_create); | 1865 | EXPORT_SYMBOL(kmem_cache_create); |
@@ -1860,7 +1901,7 @@ static inline void check_spinlock_acquired_node(kmem_cache_t *cachep, int node) | |||
1860 | /* | 1901 | /* |
1861 | * Waits for all CPUs to execute func(). | 1902 | * Waits for all CPUs to execute func(). |
1862 | */ | 1903 | */ |
1863 | static void smp_call_function_all_cpus(void (*func) (void *arg), void *arg) | 1904 | static void smp_call_function_all_cpus(void (*func)(void *arg), void *arg) |
1864 | { | 1905 | { |
1865 | check_irq_on(); | 1906 | check_irq_on(); |
1866 | preempt_disable(); | 1907 | preempt_disable(); |
@@ -1875,12 +1916,12 @@ static void smp_call_function_all_cpus(void (*func) (void *arg), void *arg) | |||
1875 | preempt_enable(); | 1916 | preempt_enable(); |
1876 | } | 1917 | } |
1877 | 1918 | ||
1878 | static void drain_array_locked(kmem_cache_t* cachep, | 1919 | static void drain_array_locked(kmem_cache_t *cachep, struct array_cache *ac, |
1879 | struct array_cache *ac, int force, int node); | 1920 | int force, int node); |
1880 | 1921 | ||
1881 | static void do_drain(void *arg) | 1922 | static void do_drain(void *arg) |
1882 | { | 1923 | { |
1883 | kmem_cache_t *cachep = (kmem_cache_t*)arg; | 1924 | kmem_cache_t *cachep = (kmem_cache_t *) arg; |
1884 | struct array_cache *ac; | 1925 | struct array_cache *ac; |
1885 | int node = numa_node_id(); | 1926 | int node = numa_node_id(); |
1886 | 1927 | ||
@@ -1900,7 +1941,7 @@ static void drain_cpu_caches(kmem_cache_t *cachep) | |||
1900 | smp_call_function_all_cpus(do_drain, cachep); | 1941 | smp_call_function_all_cpus(do_drain, cachep); |
1901 | check_irq_on(); | 1942 | check_irq_on(); |
1902 | spin_lock_irq(&cachep->spinlock); | 1943 | spin_lock_irq(&cachep->spinlock); |
1903 | for_each_online_node(node) { | 1944 | for_each_online_node(node) { |
1904 | l3 = cachep->nodelists[node]; | 1945 | l3 = cachep->nodelists[node]; |
1905 | if (l3) { | 1946 | if (l3) { |
1906 | spin_lock(&l3->list_lock); | 1947 | spin_lock(&l3->list_lock); |
@@ -1938,8 +1979,7 @@ static int __node_shrink(kmem_cache_t *cachep, int node) | |||
1938 | slab_destroy(cachep, slabp); | 1979 | slab_destroy(cachep, slabp); |
1939 | spin_lock_irq(&l3->list_lock); | 1980 | spin_lock_irq(&l3->list_lock); |
1940 | } | 1981 | } |
1941 | ret = !list_empty(&l3->slabs_full) || | 1982 | ret = !list_empty(&l3->slabs_full) || !list_empty(&l3->slabs_partial); |
1942 | !list_empty(&l3->slabs_partial); | ||
1943 | return ret; | 1983 | return ret; |
1944 | } | 1984 | } |
1945 | 1985 | ||
@@ -1995,7 +2035,7 @@ EXPORT_SYMBOL(kmem_cache_shrink); | |||
1995 | * The caller must guarantee that noone will allocate memory from the cache | 2035 | * The caller must guarantee that noone will allocate memory from the cache |
1996 | * during the kmem_cache_destroy(). | 2036 | * during the kmem_cache_destroy(). |
1997 | */ | 2037 | */ |
1998 | int kmem_cache_destroy(kmem_cache_t * cachep) | 2038 | int kmem_cache_destroy(kmem_cache_t *cachep) |
1999 | { | 2039 | { |
2000 | int i; | 2040 | int i; |
2001 | struct kmem_list3 *l3; | 2041 | struct kmem_list3 *l3; |
@@ -2007,18 +2047,18 @@ int kmem_cache_destroy(kmem_cache_t * cachep) | |||
2007 | lock_cpu_hotplug(); | 2047 | lock_cpu_hotplug(); |
2008 | 2048 | ||
2009 | /* Find the cache in the chain of caches. */ | 2049 | /* Find the cache in the chain of caches. */ |
2010 | down(&cache_chain_sem); | 2050 | mutex_lock(&cache_chain_mutex); |
2011 | /* | 2051 | /* |
2012 | * the chain is never empty, cache_cache is never destroyed | 2052 | * the chain is never empty, cache_cache is never destroyed |
2013 | */ | 2053 | */ |
2014 | list_del(&cachep->next); | 2054 | list_del(&cachep->next); |
2015 | up(&cache_chain_sem); | 2055 | mutex_unlock(&cache_chain_mutex); |
2016 | 2056 | ||
2017 | if (__cache_shrink(cachep)) { | 2057 | if (__cache_shrink(cachep)) { |
2018 | slab_error(cachep, "Can't free all objects"); | 2058 | slab_error(cachep, "Can't free all objects"); |
2019 | down(&cache_chain_sem); | 2059 | mutex_lock(&cache_chain_mutex); |
2020 | list_add(&cachep->next,&cache_chain); | 2060 | list_add(&cachep->next, &cache_chain); |
2021 | up(&cache_chain_sem); | 2061 | mutex_unlock(&cache_chain_mutex); |
2022 | unlock_cpu_hotplug(); | 2062 | unlock_cpu_hotplug(); |
2023 | return 1; | 2063 | return 1; |
2024 | } | 2064 | } |
@@ -2027,7 +2067,7 @@ int kmem_cache_destroy(kmem_cache_t * cachep) | |||
2027 | synchronize_rcu(); | 2067 | synchronize_rcu(); |
2028 | 2068 | ||
2029 | for_each_online_cpu(i) | 2069 | for_each_online_cpu(i) |
2030 | kfree(cachep->array[i]); | 2070 | kfree(cachep->array[i]); |
2031 | 2071 | ||
2032 | /* NUMA: free the list3 structures */ | 2072 | /* NUMA: free the list3 structures */ |
2033 | for_each_online_node(i) { | 2073 | for_each_online_node(i) { |
@@ -2046,39 +2086,39 @@ int kmem_cache_destroy(kmem_cache_t * cachep) | |||
2046 | EXPORT_SYMBOL(kmem_cache_destroy); | 2086 | EXPORT_SYMBOL(kmem_cache_destroy); |
2047 | 2087 | ||
2048 | /* Get the memory for a slab management obj. */ | 2088 | /* Get the memory for a slab management obj. */ |
2049 | static struct slab* alloc_slabmgmt(kmem_cache_t *cachep, void *objp, | 2089 | static struct slab *alloc_slabmgmt(kmem_cache_t *cachep, void *objp, |
2050 | int colour_off, gfp_t local_flags) | 2090 | int colour_off, gfp_t local_flags) |
2051 | { | 2091 | { |
2052 | struct slab *slabp; | 2092 | struct slab *slabp; |
2053 | 2093 | ||
2054 | if (OFF_SLAB(cachep)) { | 2094 | if (OFF_SLAB(cachep)) { |
2055 | /* Slab management obj is off-slab. */ | 2095 | /* Slab management obj is off-slab. */ |
2056 | slabp = kmem_cache_alloc(cachep->slabp_cache, local_flags); | 2096 | slabp = kmem_cache_alloc(cachep->slabp_cache, local_flags); |
2057 | if (!slabp) | 2097 | if (!slabp) |
2058 | return NULL; | 2098 | return NULL; |
2059 | } else { | 2099 | } else { |
2060 | slabp = objp+colour_off; | 2100 | slabp = objp + colour_off; |
2061 | colour_off += cachep->slab_size; | 2101 | colour_off += cachep->slab_size; |
2062 | } | 2102 | } |
2063 | slabp->inuse = 0; | 2103 | slabp->inuse = 0; |
2064 | slabp->colouroff = colour_off; | 2104 | slabp->colouroff = colour_off; |
2065 | slabp->s_mem = objp+colour_off; | 2105 | slabp->s_mem = objp + colour_off; |
2066 | 2106 | ||
2067 | return slabp; | 2107 | return slabp; |
2068 | } | 2108 | } |
2069 | 2109 | ||
2070 | static inline kmem_bufctl_t *slab_bufctl(struct slab *slabp) | 2110 | static inline kmem_bufctl_t *slab_bufctl(struct slab *slabp) |
2071 | { | 2111 | { |
2072 | return (kmem_bufctl_t *)(slabp+1); | 2112 | return (kmem_bufctl_t *) (slabp + 1); |
2073 | } | 2113 | } |
2074 | 2114 | ||
2075 | static void cache_init_objs(kmem_cache_t *cachep, | 2115 | static void cache_init_objs(kmem_cache_t *cachep, |
2076 | struct slab *slabp, unsigned long ctor_flags) | 2116 | struct slab *slabp, unsigned long ctor_flags) |
2077 | { | 2117 | { |
2078 | int i; | 2118 | int i; |
2079 | 2119 | ||
2080 | for (i = 0; i < cachep->num; i++) { | 2120 | for (i = 0; i < cachep->num; i++) { |
2081 | void *objp = slabp->s_mem+cachep->objsize*i; | 2121 | void *objp = slabp->s_mem + cachep->objsize * i; |
2082 | #if DEBUG | 2122 | #if DEBUG |
2083 | /* need to poison the objs? */ | 2123 | /* need to poison the objs? */ |
2084 | if (cachep->flags & SLAB_POISON) | 2124 | if (cachep->flags & SLAB_POISON) |
@@ -2096,25 +2136,28 @@ static void cache_init_objs(kmem_cache_t *cachep, | |||
2096 | * Otherwise, deadlock. They must also be threaded. | 2136 | * Otherwise, deadlock. They must also be threaded. |
2097 | */ | 2137 | */ |
2098 | if (cachep->ctor && !(cachep->flags & SLAB_POISON)) | 2138 | if (cachep->ctor && !(cachep->flags & SLAB_POISON)) |
2099 | cachep->ctor(objp+obj_dbghead(cachep), cachep, ctor_flags); | 2139 | cachep->ctor(objp + obj_dbghead(cachep), cachep, |
2140 | ctor_flags); | ||
2100 | 2141 | ||
2101 | if (cachep->flags & SLAB_RED_ZONE) { | 2142 | if (cachep->flags & SLAB_RED_ZONE) { |
2102 | if (*dbg_redzone2(cachep, objp) != RED_INACTIVE) | 2143 | if (*dbg_redzone2(cachep, objp) != RED_INACTIVE) |
2103 | slab_error(cachep, "constructor overwrote the" | 2144 | slab_error(cachep, "constructor overwrote the" |
2104 | " end of an object"); | 2145 | " end of an object"); |
2105 | if (*dbg_redzone1(cachep, objp) != RED_INACTIVE) | 2146 | if (*dbg_redzone1(cachep, objp) != RED_INACTIVE) |
2106 | slab_error(cachep, "constructor overwrote the" | 2147 | slab_error(cachep, "constructor overwrote the" |
2107 | " start of an object"); | 2148 | " start of an object"); |
2108 | } | 2149 | } |
2109 | if ((cachep->objsize % PAGE_SIZE) == 0 && OFF_SLAB(cachep) && cachep->flags & SLAB_POISON) | 2150 | if ((cachep->objsize % PAGE_SIZE) == 0 && OFF_SLAB(cachep) |
2110 | kernel_map_pages(virt_to_page(objp), cachep->objsize/PAGE_SIZE, 0); | 2151 | && cachep->flags & SLAB_POISON) |
2152 | kernel_map_pages(virt_to_page(objp), | ||
2153 | cachep->objsize / PAGE_SIZE, 0); | ||
2111 | #else | 2154 | #else |
2112 | if (cachep->ctor) | 2155 | if (cachep->ctor) |
2113 | cachep->ctor(objp, cachep, ctor_flags); | 2156 | cachep->ctor(objp, cachep, ctor_flags); |
2114 | #endif | 2157 | #endif |
2115 | slab_bufctl(slabp)[i] = i+1; | 2158 | slab_bufctl(slabp)[i] = i + 1; |
2116 | } | 2159 | } |
2117 | slab_bufctl(slabp)[i-1] = BUFCTL_END; | 2160 | slab_bufctl(slabp)[i - 1] = BUFCTL_END; |
2118 | slabp->free = 0; | 2161 | slabp->free = 0; |
2119 | } | 2162 | } |
2120 | 2163 | ||
@@ -2138,8 +2181,8 @@ static void set_slab_attr(kmem_cache_t *cachep, struct slab *slabp, void *objp) | |||
2138 | i = 1 << cachep->gfporder; | 2181 | i = 1 << cachep->gfporder; |
2139 | page = virt_to_page(objp); | 2182 | page = virt_to_page(objp); |
2140 | do { | 2183 | do { |
2141 | SET_PAGE_CACHE(page, cachep); | 2184 | page_set_cache(page, cachep); |
2142 | SET_PAGE_SLAB(page, slabp); | 2185 | page_set_slab(page, slabp); |
2143 | page++; | 2186 | page++; |
2144 | } while (--i); | 2187 | } while (--i); |
2145 | } | 2188 | } |
@@ -2150,17 +2193,17 @@ static void set_slab_attr(kmem_cache_t *cachep, struct slab *slabp, void *objp) | |||
2150 | */ | 2193 | */ |
2151 | static int cache_grow(kmem_cache_t *cachep, gfp_t flags, int nodeid) | 2194 | static int cache_grow(kmem_cache_t *cachep, gfp_t flags, int nodeid) |
2152 | { | 2195 | { |
2153 | struct slab *slabp; | 2196 | struct slab *slabp; |
2154 | void *objp; | 2197 | void *objp; |
2155 | size_t offset; | 2198 | size_t offset; |
2156 | gfp_t local_flags; | 2199 | gfp_t local_flags; |
2157 | unsigned long ctor_flags; | 2200 | unsigned long ctor_flags; |
2158 | struct kmem_list3 *l3; | 2201 | struct kmem_list3 *l3; |
2159 | 2202 | ||
2160 | /* Be lazy and only check for valid flags here, | 2203 | /* Be lazy and only check for valid flags here, |
2161 | * keeping it out of the critical path in kmem_cache_alloc(). | 2204 | * keeping it out of the critical path in kmem_cache_alloc(). |
2162 | */ | 2205 | */ |
2163 | if (flags & ~(SLAB_DMA|SLAB_LEVEL_MASK|SLAB_NO_GROW)) | 2206 | if (flags & ~(SLAB_DMA | SLAB_LEVEL_MASK | SLAB_NO_GROW)) |
2164 | BUG(); | 2207 | BUG(); |
2165 | if (flags & SLAB_NO_GROW) | 2208 | if (flags & SLAB_NO_GROW) |
2166 | return 0; | 2209 | return 0; |
@@ -2226,9 +2269,9 @@ static int cache_grow(kmem_cache_t *cachep, gfp_t flags, int nodeid) | |||
2226 | l3->free_objects += cachep->num; | 2269 | l3->free_objects += cachep->num; |
2227 | spin_unlock(&l3->list_lock); | 2270 | spin_unlock(&l3->list_lock); |
2228 | return 1; | 2271 | return 1; |
2229 | opps1: | 2272 | opps1: |
2230 | kmem_freepages(cachep, objp); | 2273 | kmem_freepages(cachep, objp); |
2231 | failed: | 2274 | failed: |
2232 | if (local_flags & __GFP_WAIT) | 2275 | if (local_flags & __GFP_WAIT) |
2233 | local_irq_disable(); | 2276 | local_irq_disable(); |
2234 | return 0; | 2277 | return 0; |
@@ -2248,18 +2291,19 @@ static void kfree_debugcheck(const void *objp) | |||
2248 | 2291 | ||
2249 | if (!virt_addr_valid(objp)) { | 2292 | if (!virt_addr_valid(objp)) { |
2250 | printk(KERN_ERR "kfree_debugcheck: out of range ptr %lxh.\n", | 2293 | printk(KERN_ERR "kfree_debugcheck: out of range ptr %lxh.\n", |
2251 | (unsigned long)objp); | 2294 | (unsigned long)objp); |
2252 | BUG(); | 2295 | BUG(); |
2253 | } | 2296 | } |
2254 | page = virt_to_page(objp); | 2297 | page = virt_to_page(objp); |
2255 | if (!PageSlab(page)) { | 2298 | if (!PageSlab(page)) { |
2256 | printk(KERN_ERR "kfree_debugcheck: bad ptr %lxh.\n", (unsigned long)objp); | 2299 | printk(KERN_ERR "kfree_debugcheck: bad ptr %lxh.\n", |
2300 | (unsigned long)objp); | ||
2257 | BUG(); | 2301 | BUG(); |
2258 | } | 2302 | } |
2259 | } | 2303 | } |
2260 | 2304 | ||
2261 | static void *cache_free_debugcheck(kmem_cache_t *cachep, void *objp, | 2305 | static void *cache_free_debugcheck(kmem_cache_t *cachep, void *objp, |
2262 | void *caller) | 2306 | void *caller) |
2263 | { | 2307 | { |
2264 | struct page *page; | 2308 | struct page *page; |
2265 | unsigned int objnr; | 2309 | unsigned int objnr; |
@@ -2269,21 +2313,27 @@ static void *cache_free_debugcheck(kmem_cache_t *cachep, void *objp, | |||
2269 | kfree_debugcheck(objp); | 2313 | kfree_debugcheck(objp); |
2270 | page = virt_to_page(objp); | 2314 | page = virt_to_page(objp); |
2271 | 2315 | ||
2272 | if (GET_PAGE_CACHE(page) != cachep) { | 2316 | if (page_get_cache(page) != cachep) { |
2273 | printk(KERN_ERR "mismatch in kmem_cache_free: expected cache %p, got %p\n", | 2317 | printk(KERN_ERR |
2274 | GET_PAGE_CACHE(page),cachep); | 2318 | "mismatch in kmem_cache_free: expected cache %p, got %p\n", |
2319 | page_get_cache(page), cachep); | ||
2275 | printk(KERN_ERR "%p is %s.\n", cachep, cachep->name); | 2320 | printk(KERN_ERR "%p is %s.\n", cachep, cachep->name); |
2276 | printk(KERN_ERR "%p is %s.\n", GET_PAGE_CACHE(page), GET_PAGE_CACHE(page)->name); | 2321 | printk(KERN_ERR "%p is %s.\n", page_get_cache(page), |
2322 | page_get_cache(page)->name); | ||
2277 | WARN_ON(1); | 2323 | WARN_ON(1); |
2278 | } | 2324 | } |
2279 | slabp = GET_PAGE_SLAB(page); | 2325 | slabp = page_get_slab(page); |
2280 | 2326 | ||
2281 | if (cachep->flags & SLAB_RED_ZONE) { | 2327 | if (cachep->flags & SLAB_RED_ZONE) { |
2282 | if (*dbg_redzone1(cachep, objp) != RED_ACTIVE || *dbg_redzone2(cachep, objp) != RED_ACTIVE) { | 2328 | if (*dbg_redzone1(cachep, objp) != RED_ACTIVE |
2283 | slab_error(cachep, "double free, or memory outside" | 2329 | || *dbg_redzone2(cachep, objp) != RED_ACTIVE) { |
2284 | " object was overwritten"); | 2330 | slab_error(cachep, |
2285 | printk(KERN_ERR "%p: redzone 1: 0x%lx, redzone 2: 0x%lx.\n", | 2331 | "double free, or memory outside" |
2286 | objp, *dbg_redzone1(cachep, objp), *dbg_redzone2(cachep, objp)); | 2332 | " object was overwritten"); |
2333 | printk(KERN_ERR | ||
2334 | "%p: redzone 1: 0x%lx, redzone 2: 0x%lx.\n", | ||
2335 | objp, *dbg_redzone1(cachep, objp), | ||
2336 | *dbg_redzone2(cachep, objp)); | ||
2287 | } | 2337 | } |
2288 | *dbg_redzone1(cachep, objp) = RED_INACTIVE; | 2338 | *dbg_redzone1(cachep, objp) = RED_INACTIVE; |
2289 | *dbg_redzone2(cachep, objp) = RED_INACTIVE; | 2339 | *dbg_redzone2(cachep, objp) = RED_INACTIVE; |
@@ -2291,30 +2341,31 @@ static void *cache_free_debugcheck(kmem_cache_t *cachep, void *objp, | |||
2291 | if (cachep->flags & SLAB_STORE_USER) | 2341 | if (cachep->flags & SLAB_STORE_USER) |
2292 | *dbg_userword(cachep, objp) = caller; | 2342 | *dbg_userword(cachep, objp) = caller; |
2293 | 2343 | ||
2294 | objnr = (objp-slabp->s_mem)/cachep->objsize; | 2344 | objnr = (objp - slabp->s_mem) / cachep->objsize; |
2295 | 2345 | ||
2296 | BUG_ON(objnr >= cachep->num); | 2346 | BUG_ON(objnr >= cachep->num); |
2297 | BUG_ON(objp != slabp->s_mem + objnr*cachep->objsize); | 2347 | BUG_ON(objp != slabp->s_mem + objnr * cachep->objsize); |
2298 | 2348 | ||
2299 | if (cachep->flags & SLAB_DEBUG_INITIAL) { | 2349 | if (cachep->flags & SLAB_DEBUG_INITIAL) { |
2300 | /* Need to call the slab's constructor so the | 2350 | /* Need to call the slab's constructor so the |
2301 | * caller can perform a verify of its state (debugging). | 2351 | * caller can perform a verify of its state (debugging). |
2302 | * Called without the cache-lock held. | 2352 | * Called without the cache-lock held. |
2303 | */ | 2353 | */ |
2304 | cachep->ctor(objp+obj_dbghead(cachep), | 2354 | cachep->ctor(objp + obj_dbghead(cachep), |
2305 | cachep, SLAB_CTOR_CONSTRUCTOR|SLAB_CTOR_VERIFY); | 2355 | cachep, SLAB_CTOR_CONSTRUCTOR | SLAB_CTOR_VERIFY); |
2306 | } | 2356 | } |
2307 | if (cachep->flags & SLAB_POISON && cachep->dtor) { | 2357 | if (cachep->flags & SLAB_POISON && cachep->dtor) { |
2308 | /* we want to cache poison the object, | 2358 | /* we want to cache poison the object, |
2309 | * call the destruction callback | 2359 | * call the destruction callback |
2310 | */ | 2360 | */ |
2311 | cachep->dtor(objp+obj_dbghead(cachep), cachep, 0); | 2361 | cachep->dtor(objp + obj_dbghead(cachep), cachep, 0); |
2312 | } | 2362 | } |
2313 | if (cachep->flags & SLAB_POISON) { | 2363 | if (cachep->flags & SLAB_POISON) { |
2314 | #ifdef CONFIG_DEBUG_PAGEALLOC | 2364 | #ifdef CONFIG_DEBUG_PAGEALLOC |
2315 | if ((cachep->objsize % PAGE_SIZE) == 0 && OFF_SLAB(cachep)) { | 2365 | if ((cachep->objsize % PAGE_SIZE) == 0 && OFF_SLAB(cachep)) { |
2316 | store_stackinfo(cachep, objp, (unsigned long)caller); | 2366 | store_stackinfo(cachep, objp, (unsigned long)caller); |
2317 | kernel_map_pages(virt_to_page(objp), cachep->objsize/PAGE_SIZE, 0); | 2367 | kernel_map_pages(virt_to_page(objp), |
2368 | cachep->objsize / PAGE_SIZE, 0); | ||
2318 | } else { | 2369 | } else { |
2319 | poison_obj(cachep, objp, POISON_FREE); | 2370 | poison_obj(cachep, objp, POISON_FREE); |
2320 | } | 2371 | } |
@@ -2329,7 +2380,7 @@ static void check_slabp(kmem_cache_t *cachep, struct slab *slabp) | |||
2329 | { | 2380 | { |
2330 | kmem_bufctl_t i; | 2381 | kmem_bufctl_t i; |
2331 | int entries = 0; | 2382 | int entries = 0; |
2332 | 2383 | ||
2333 | /* Check slab's freelist to see if this obj is there. */ | 2384 | /* Check slab's freelist to see if this obj is there. */ |
2334 | for (i = slabp->free; i != BUFCTL_END; i = slab_bufctl(slabp)[i]) { | 2385 | for (i = slabp->free; i != BUFCTL_END; i = slab_bufctl(slabp)[i]) { |
2335 | entries++; | 2386 | entries++; |
@@ -2337,13 +2388,16 @@ static void check_slabp(kmem_cache_t *cachep, struct slab *slabp) | |||
2337 | goto bad; | 2388 | goto bad; |
2338 | } | 2389 | } |
2339 | if (entries != cachep->num - slabp->inuse) { | 2390 | if (entries != cachep->num - slabp->inuse) { |
2340 | bad: | 2391 | bad: |
2341 | printk(KERN_ERR "slab: Internal list corruption detected in cache '%s'(%d), slabp %p(%d). Hexdump:\n", | 2392 | printk(KERN_ERR |
2342 | cachep->name, cachep->num, slabp, slabp->inuse); | 2393 | "slab: Internal list corruption detected in cache '%s'(%d), slabp %p(%d). Hexdump:\n", |
2343 | for (i=0;i<sizeof(slabp)+cachep->num*sizeof(kmem_bufctl_t);i++) { | 2394 | cachep->name, cachep->num, slabp, slabp->inuse); |
2344 | if ((i%16)==0) | 2395 | for (i = 0; |
2396 | i < sizeof(slabp) + cachep->num * sizeof(kmem_bufctl_t); | ||
2397 | i++) { | ||
2398 | if ((i % 16) == 0) | ||
2345 | printk("\n%03x:", i); | 2399 | printk("\n%03x:", i); |
2346 | printk(" %02x", ((unsigned char*)slabp)[i]); | 2400 | printk(" %02x", ((unsigned char *)slabp)[i]); |
2347 | } | 2401 | } |
2348 | printk("\n"); | 2402 | printk("\n"); |
2349 | BUG(); | 2403 | BUG(); |
@@ -2363,7 +2417,7 @@ static void *cache_alloc_refill(kmem_cache_t *cachep, gfp_t flags) | |||
2363 | 2417 | ||
2364 | check_irq_off(); | 2418 | check_irq_off(); |
2365 | ac = ac_data(cachep); | 2419 | ac = ac_data(cachep); |
2366 | retry: | 2420 | retry: |
2367 | batchcount = ac->batchcount; | 2421 | batchcount = ac->batchcount; |
2368 | if (!ac->touched && batchcount > BATCHREFILL_LIMIT) { | 2422 | if (!ac->touched && batchcount > BATCHREFILL_LIMIT) { |
2369 | /* if there was little recent activity on this | 2423 | /* if there was little recent activity on this |
@@ -2385,8 +2439,8 @@ retry: | |||
2385 | shared_array->avail -= batchcount; | 2439 | shared_array->avail -= batchcount; |
2386 | ac->avail = batchcount; | 2440 | ac->avail = batchcount; |
2387 | memcpy(ac->entry, | 2441 | memcpy(ac->entry, |
2388 | &(shared_array->entry[shared_array->avail]), | 2442 | &(shared_array->entry[shared_array->avail]), |
2389 | sizeof(void*)*batchcount); | 2443 | sizeof(void *) * batchcount); |
2390 | shared_array->touched = 1; | 2444 | shared_array->touched = 1; |
2391 | goto alloc_done; | 2445 | goto alloc_done; |
2392 | } | 2446 | } |
@@ -2414,7 +2468,7 @@ retry: | |||
2414 | 2468 | ||
2415 | /* get obj pointer */ | 2469 | /* get obj pointer */ |
2416 | ac->entry[ac->avail++] = slabp->s_mem + | 2470 | ac->entry[ac->avail++] = slabp->s_mem + |
2417 | slabp->free*cachep->objsize; | 2471 | slabp->free * cachep->objsize; |
2418 | 2472 | ||
2419 | slabp->inuse++; | 2473 | slabp->inuse++; |
2420 | next = slab_bufctl(slabp)[slabp->free]; | 2474 | next = slab_bufctl(slabp)[slabp->free]; |
@@ -2422,7 +2476,7 @@ retry: | |||
2422 | slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE; | 2476 | slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE; |
2423 | WARN_ON(numa_node_id() != slabp->nodeid); | 2477 | WARN_ON(numa_node_id() != slabp->nodeid); |
2424 | #endif | 2478 | #endif |
2425 | slabp->free = next; | 2479 | slabp->free = next; |
2426 | } | 2480 | } |
2427 | check_slabp(cachep, slabp); | 2481 | check_slabp(cachep, slabp); |
2428 | 2482 | ||
@@ -2434,9 +2488,9 @@ retry: | |||
2434 | list_add(&slabp->list, &l3->slabs_partial); | 2488 | list_add(&slabp->list, &l3->slabs_partial); |
2435 | } | 2489 | } |
2436 | 2490 | ||
2437 | must_grow: | 2491 | must_grow: |
2438 | l3->free_objects -= ac->avail; | 2492 | l3->free_objects -= ac->avail; |
2439 | alloc_done: | 2493 | alloc_done: |
2440 | spin_unlock(&l3->list_lock); | 2494 | spin_unlock(&l3->list_lock); |
2441 | 2495 | ||
2442 | if (unlikely(!ac->avail)) { | 2496 | if (unlikely(!ac->avail)) { |
@@ -2448,7 +2502,7 @@ alloc_done: | |||
2448 | if (!x && ac->avail == 0) // no objects in sight? abort | 2502 | if (!x && ac->avail == 0) // no objects in sight? abort |
2449 | return NULL; | 2503 | return NULL; |
2450 | 2504 | ||
2451 | if (!ac->avail) // objects refilled by interrupt? | 2505 | if (!ac->avail) // objects refilled by interrupt? |
2452 | goto retry; | 2506 | goto retry; |
2453 | } | 2507 | } |
2454 | ac->touched = 1; | 2508 | ac->touched = 1; |
@@ -2465,16 +2519,16 @@ cache_alloc_debugcheck_before(kmem_cache_t *cachep, gfp_t flags) | |||
2465 | } | 2519 | } |
2466 | 2520 | ||
2467 | #if DEBUG | 2521 | #if DEBUG |
2468 | static void * | 2522 | static void *cache_alloc_debugcheck_after(kmem_cache_t *cachep, gfp_t flags, |
2469 | cache_alloc_debugcheck_after(kmem_cache_t *cachep, | 2523 | void *objp, void *caller) |
2470 | gfp_t flags, void *objp, void *caller) | ||
2471 | { | 2524 | { |
2472 | if (!objp) | 2525 | if (!objp) |
2473 | return objp; | 2526 | return objp; |
2474 | if (cachep->flags & SLAB_POISON) { | 2527 | if (cachep->flags & SLAB_POISON) { |
2475 | #ifdef CONFIG_DEBUG_PAGEALLOC | 2528 | #ifdef CONFIG_DEBUG_PAGEALLOC |
2476 | if ((cachep->objsize % PAGE_SIZE) == 0 && OFF_SLAB(cachep)) | 2529 | if ((cachep->objsize % PAGE_SIZE) == 0 && OFF_SLAB(cachep)) |
2477 | kernel_map_pages(virt_to_page(objp), cachep->objsize/PAGE_SIZE, 1); | 2530 | kernel_map_pages(virt_to_page(objp), |
2531 | cachep->objsize / PAGE_SIZE, 1); | ||
2478 | else | 2532 | else |
2479 | check_poison_obj(cachep, objp); | 2533 | check_poison_obj(cachep, objp); |
2480 | #else | 2534 | #else |
@@ -2486,24 +2540,28 @@ cache_alloc_debugcheck_after(kmem_cache_t *cachep, | |||
2486 | *dbg_userword(cachep, objp) = caller; | 2540 | *dbg_userword(cachep, objp) = caller; |
2487 | 2541 | ||
2488 | if (cachep->flags & SLAB_RED_ZONE) { | 2542 | if (cachep->flags & SLAB_RED_ZONE) { |
2489 | if (*dbg_redzone1(cachep, objp) != RED_INACTIVE || *dbg_redzone2(cachep, objp) != RED_INACTIVE) { | 2543 | if (*dbg_redzone1(cachep, objp) != RED_INACTIVE |
2490 | slab_error(cachep, "double free, or memory outside" | 2544 | || *dbg_redzone2(cachep, objp) != RED_INACTIVE) { |
2491 | " object was overwritten"); | 2545 | slab_error(cachep, |
2492 | printk(KERN_ERR "%p: redzone 1: 0x%lx, redzone 2: 0x%lx.\n", | 2546 | "double free, or memory outside" |
2493 | objp, *dbg_redzone1(cachep, objp), *dbg_redzone2(cachep, objp)); | 2547 | " object was overwritten"); |
2548 | printk(KERN_ERR | ||
2549 | "%p: redzone 1: 0x%lx, redzone 2: 0x%lx.\n", | ||
2550 | objp, *dbg_redzone1(cachep, objp), | ||
2551 | *dbg_redzone2(cachep, objp)); | ||
2494 | } | 2552 | } |
2495 | *dbg_redzone1(cachep, objp) = RED_ACTIVE; | 2553 | *dbg_redzone1(cachep, objp) = RED_ACTIVE; |
2496 | *dbg_redzone2(cachep, objp) = RED_ACTIVE; | 2554 | *dbg_redzone2(cachep, objp) = RED_ACTIVE; |
2497 | } | 2555 | } |
2498 | objp += obj_dbghead(cachep); | 2556 | objp += obj_dbghead(cachep); |
2499 | if (cachep->ctor && cachep->flags & SLAB_POISON) { | 2557 | if (cachep->ctor && cachep->flags & SLAB_POISON) { |
2500 | unsigned long ctor_flags = SLAB_CTOR_CONSTRUCTOR; | 2558 | unsigned long ctor_flags = SLAB_CTOR_CONSTRUCTOR; |
2501 | 2559 | ||
2502 | if (!(flags & __GFP_WAIT)) | 2560 | if (!(flags & __GFP_WAIT)) |
2503 | ctor_flags |= SLAB_CTOR_ATOMIC; | 2561 | ctor_flags |= SLAB_CTOR_ATOMIC; |
2504 | 2562 | ||
2505 | cachep->ctor(objp, cachep, ctor_flags); | 2563 | cachep->ctor(objp, cachep, ctor_flags); |
2506 | } | 2564 | } |
2507 | return objp; | 2565 | return objp; |
2508 | } | 2566 | } |
2509 | #else | 2567 | #else |
@@ -2512,9 +2570,18 @@ cache_alloc_debugcheck_after(kmem_cache_t *cachep, | |||
2512 | 2570 | ||
2513 | static inline void *____cache_alloc(kmem_cache_t *cachep, gfp_t flags) | 2571 | static inline void *____cache_alloc(kmem_cache_t *cachep, gfp_t flags) |
2514 | { | 2572 | { |
2515 | void* objp; | 2573 | void *objp; |
2516 | struct array_cache *ac; | 2574 | struct array_cache *ac; |
2517 | 2575 | ||
2576 | #ifdef CONFIG_NUMA | ||
2577 | if (unlikely(current->mempolicy && !in_interrupt())) { | ||
2578 | int nid = slab_node(current->mempolicy); | ||
2579 | |||
2580 | if (nid != numa_node_id()) | ||
2581 | return __cache_alloc_node(cachep, flags, nid); | ||
2582 | } | ||
2583 | #endif | ||
2584 | |||
2518 | check_irq_off(); | 2585 | check_irq_off(); |
2519 | ac = ac_data(cachep); | 2586 | ac = ac_data(cachep); |
2520 | if (likely(ac->avail)) { | 2587 | if (likely(ac->avail)) { |
@@ -2531,7 +2598,7 @@ static inline void *____cache_alloc(kmem_cache_t *cachep, gfp_t flags) | |||
2531 | static inline void *__cache_alloc(kmem_cache_t *cachep, gfp_t flags) | 2598 | static inline void *__cache_alloc(kmem_cache_t *cachep, gfp_t flags) |
2532 | { | 2599 | { |
2533 | unsigned long save_flags; | 2600 | unsigned long save_flags; |
2534 | void* objp; | 2601 | void *objp; |
2535 | 2602 | ||
2536 | cache_alloc_debugcheck_before(cachep, flags); | 2603 | cache_alloc_debugcheck_before(cachep, flags); |
2537 | 2604 | ||
@@ -2539,7 +2606,7 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, gfp_t flags) | |||
2539 | objp = ____cache_alloc(cachep, flags); | 2606 | objp = ____cache_alloc(cachep, flags); |
2540 | local_irq_restore(save_flags); | 2607 | local_irq_restore(save_flags); |
2541 | objp = cache_alloc_debugcheck_after(cachep, flags, objp, | 2608 | objp = cache_alloc_debugcheck_after(cachep, flags, objp, |
2542 | __builtin_return_address(0)); | 2609 | __builtin_return_address(0)); |
2543 | prefetchw(objp); | 2610 | prefetchw(objp); |
2544 | return objp; | 2611 | return objp; |
2545 | } | 2612 | } |
@@ -2551,74 +2618,75 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, gfp_t flags) | |||
2551 | static void *__cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int nodeid) | 2618 | static void *__cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int nodeid) |
2552 | { | 2619 | { |
2553 | struct list_head *entry; | 2620 | struct list_head *entry; |
2554 | struct slab *slabp; | 2621 | struct slab *slabp; |
2555 | struct kmem_list3 *l3; | 2622 | struct kmem_list3 *l3; |
2556 | void *obj; | 2623 | void *obj; |
2557 | kmem_bufctl_t next; | 2624 | kmem_bufctl_t next; |
2558 | int x; | 2625 | int x; |
2559 | 2626 | ||
2560 | l3 = cachep->nodelists[nodeid]; | 2627 | l3 = cachep->nodelists[nodeid]; |
2561 | BUG_ON(!l3); | 2628 | BUG_ON(!l3); |
2562 | 2629 | ||
2563 | retry: | 2630 | retry: |
2564 | spin_lock(&l3->list_lock); | 2631 | spin_lock(&l3->list_lock); |
2565 | entry = l3->slabs_partial.next; | 2632 | entry = l3->slabs_partial.next; |
2566 | if (entry == &l3->slabs_partial) { | 2633 | if (entry == &l3->slabs_partial) { |
2567 | l3->free_touched = 1; | 2634 | l3->free_touched = 1; |
2568 | entry = l3->slabs_free.next; | 2635 | entry = l3->slabs_free.next; |
2569 | if (entry == &l3->slabs_free) | 2636 | if (entry == &l3->slabs_free) |
2570 | goto must_grow; | 2637 | goto must_grow; |
2571 | } | 2638 | } |
2572 | 2639 | ||
2573 | slabp = list_entry(entry, struct slab, list); | 2640 | slabp = list_entry(entry, struct slab, list); |
2574 | check_spinlock_acquired_node(cachep, nodeid); | 2641 | check_spinlock_acquired_node(cachep, nodeid); |
2575 | check_slabp(cachep, slabp); | 2642 | check_slabp(cachep, slabp); |
2576 | 2643 | ||
2577 | STATS_INC_NODEALLOCS(cachep); | 2644 | STATS_INC_NODEALLOCS(cachep); |
2578 | STATS_INC_ACTIVE(cachep); | 2645 | STATS_INC_ACTIVE(cachep); |
2579 | STATS_SET_HIGH(cachep); | 2646 | STATS_SET_HIGH(cachep); |
2580 | 2647 | ||
2581 | BUG_ON(slabp->inuse == cachep->num); | 2648 | BUG_ON(slabp->inuse == cachep->num); |
2582 | 2649 | ||
2583 | /* get obj pointer */ | 2650 | /* get obj pointer */ |
2584 | obj = slabp->s_mem + slabp->free*cachep->objsize; | 2651 | obj = slabp->s_mem + slabp->free * cachep->objsize; |
2585 | slabp->inuse++; | 2652 | slabp->inuse++; |
2586 | next = slab_bufctl(slabp)[slabp->free]; | 2653 | next = slab_bufctl(slabp)[slabp->free]; |
2587 | #if DEBUG | 2654 | #if DEBUG |
2588 | slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE; | 2655 | slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE; |
2589 | #endif | 2656 | #endif |
2590 | slabp->free = next; | 2657 | slabp->free = next; |
2591 | check_slabp(cachep, slabp); | 2658 | check_slabp(cachep, slabp); |
2592 | l3->free_objects--; | 2659 | l3->free_objects--; |
2593 | /* move slabp to correct slabp list: */ | 2660 | /* move slabp to correct slabp list: */ |
2594 | list_del(&slabp->list); | 2661 | list_del(&slabp->list); |
2595 | 2662 | ||
2596 | if (slabp->free == BUFCTL_END) { | 2663 | if (slabp->free == BUFCTL_END) { |
2597 | list_add(&slabp->list, &l3->slabs_full); | 2664 | list_add(&slabp->list, &l3->slabs_full); |
2598 | } else { | 2665 | } else { |
2599 | list_add(&slabp->list, &l3->slabs_partial); | 2666 | list_add(&slabp->list, &l3->slabs_partial); |
2600 | } | 2667 | } |
2601 | 2668 | ||
2602 | spin_unlock(&l3->list_lock); | 2669 | spin_unlock(&l3->list_lock); |
2603 | goto done; | 2670 | goto done; |
2604 | 2671 | ||
2605 | must_grow: | 2672 | must_grow: |
2606 | spin_unlock(&l3->list_lock); | 2673 | spin_unlock(&l3->list_lock); |
2607 | x = cache_grow(cachep, flags, nodeid); | 2674 | x = cache_grow(cachep, flags, nodeid); |
2608 | 2675 | ||
2609 | if (!x) | 2676 | if (!x) |
2610 | return NULL; | 2677 | return NULL; |
2611 | 2678 | ||
2612 | goto retry; | 2679 | goto retry; |
2613 | done: | 2680 | done: |
2614 | return obj; | 2681 | return obj; |
2615 | } | 2682 | } |
2616 | #endif | 2683 | #endif |
2617 | 2684 | ||
2618 | /* | 2685 | /* |
2619 | * Caller needs to acquire correct kmem_list's list_lock | 2686 | * Caller needs to acquire correct kmem_list's list_lock |
2620 | */ | 2687 | */ |
2621 | static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects, int node) | 2688 | static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects, |
2689 | int node) | ||
2622 | { | 2690 | { |
2623 | int i; | 2691 | int i; |
2624 | struct kmem_list3 *l3; | 2692 | struct kmem_list3 *l3; |
@@ -2628,7 +2696,7 @@ static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects, int n | |||
2628 | struct slab *slabp; | 2696 | struct slab *slabp; |
2629 | unsigned int objnr; | 2697 | unsigned int objnr; |
2630 | 2698 | ||
2631 | slabp = GET_PAGE_SLAB(virt_to_page(objp)); | 2699 | slabp = page_get_slab(virt_to_page(objp)); |
2632 | l3 = cachep->nodelists[node]; | 2700 | l3 = cachep->nodelists[node]; |
2633 | list_del(&slabp->list); | 2701 | list_del(&slabp->list); |
2634 | objnr = (objp - slabp->s_mem) / cachep->objsize; | 2702 | objnr = (objp - slabp->s_mem) / cachep->objsize; |
@@ -2641,7 +2709,7 @@ static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects, int n | |||
2641 | 2709 | ||
2642 | if (slab_bufctl(slabp)[objnr] != BUFCTL_FREE) { | 2710 | if (slab_bufctl(slabp)[objnr] != BUFCTL_FREE) { |
2643 | printk(KERN_ERR "slab: double free detected in cache " | 2711 | printk(KERN_ERR "slab: double free detected in cache " |
2644 | "'%s', objp %p\n", cachep->name, objp); | 2712 | "'%s', objp %p\n", cachep->name, objp); |
2645 | BUG(); | 2713 | BUG(); |
2646 | } | 2714 | } |
2647 | #endif | 2715 | #endif |
@@ -2685,20 +2753,19 @@ static void cache_flusharray(kmem_cache_t *cachep, struct array_cache *ac) | |||
2685 | spin_lock(&l3->list_lock); | 2753 | spin_lock(&l3->list_lock); |
2686 | if (l3->shared) { | 2754 | if (l3->shared) { |
2687 | struct array_cache *shared_array = l3->shared; | 2755 | struct array_cache *shared_array = l3->shared; |
2688 | int max = shared_array->limit-shared_array->avail; | 2756 | int max = shared_array->limit - shared_array->avail; |
2689 | if (max) { | 2757 | if (max) { |
2690 | if (batchcount > max) | 2758 | if (batchcount > max) |
2691 | batchcount = max; | 2759 | batchcount = max; |
2692 | memcpy(&(shared_array->entry[shared_array->avail]), | 2760 | memcpy(&(shared_array->entry[shared_array->avail]), |
2693 | ac->entry, | 2761 | ac->entry, sizeof(void *) * batchcount); |
2694 | sizeof(void*)*batchcount); | ||
2695 | shared_array->avail += batchcount; | 2762 | shared_array->avail += batchcount; |
2696 | goto free_done; | 2763 | goto free_done; |
2697 | } | 2764 | } |
2698 | } | 2765 | } |
2699 | 2766 | ||
2700 | free_block(cachep, ac->entry, batchcount, node); | 2767 | free_block(cachep, ac->entry, batchcount, node); |
2701 | free_done: | 2768 | free_done: |
2702 | #if STATS | 2769 | #if STATS |
2703 | { | 2770 | { |
2704 | int i = 0; | 2771 | int i = 0; |
@@ -2720,10 +2787,9 @@ free_done: | |||
2720 | spin_unlock(&l3->list_lock); | 2787 | spin_unlock(&l3->list_lock); |
2721 | ac->avail -= batchcount; | 2788 | ac->avail -= batchcount; |
2722 | memmove(ac->entry, &(ac->entry[batchcount]), | 2789 | memmove(ac->entry, &(ac->entry[batchcount]), |
2723 | sizeof(void*)*ac->avail); | 2790 | sizeof(void *) * ac->avail); |
2724 | } | 2791 | } |
2725 | 2792 | ||
2726 | |||
2727 | /* | 2793 | /* |
2728 | * __cache_free | 2794 | * __cache_free |
2729 | * Release an obj back to its cache. If the obj has a constructed | 2795 | * Release an obj back to its cache. If the obj has a constructed |
@@ -2744,11 +2810,12 @@ static inline void __cache_free(kmem_cache_t *cachep, void *objp) | |||
2744 | #ifdef CONFIG_NUMA | 2810 | #ifdef CONFIG_NUMA |
2745 | { | 2811 | { |
2746 | struct slab *slabp; | 2812 | struct slab *slabp; |
2747 | slabp = GET_PAGE_SLAB(virt_to_page(objp)); | 2813 | slabp = page_get_slab(virt_to_page(objp)); |
2748 | if (unlikely(slabp->nodeid != numa_node_id())) { | 2814 | if (unlikely(slabp->nodeid != numa_node_id())) { |
2749 | struct array_cache *alien = NULL; | 2815 | struct array_cache *alien = NULL; |
2750 | int nodeid = slabp->nodeid; | 2816 | int nodeid = slabp->nodeid; |
2751 | struct kmem_list3 *l3 = cachep->nodelists[numa_node_id()]; | 2817 | struct kmem_list3 *l3 = |
2818 | cachep->nodelists[numa_node_id()]; | ||
2752 | 2819 | ||
2753 | STATS_INC_NODEFREES(cachep); | 2820 | STATS_INC_NODEFREES(cachep); |
2754 | if (l3->alien && l3->alien[nodeid]) { | 2821 | if (l3->alien && l3->alien[nodeid]) { |
@@ -2756,15 +2823,15 @@ static inline void __cache_free(kmem_cache_t *cachep, void *objp) | |||
2756 | spin_lock(&alien->lock); | 2823 | spin_lock(&alien->lock); |
2757 | if (unlikely(alien->avail == alien->limit)) | 2824 | if (unlikely(alien->avail == alien->limit)) |
2758 | __drain_alien_cache(cachep, | 2825 | __drain_alien_cache(cachep, |
2759 | alien, nodeid); | 2826 | alien, nodeid); |
2760 | alien->entry[alien->avail++] = objp; | 2827 | alien->entry[alien->avail++] = objp; |
2761 | spin_unlock(&alien->lock); | 2828 | spin_unlock(&alien->lock); |
2762 | } else { | 2829 | } else { |
2763 | spin_lock(&(cachep->nodelists[nodeid])-> | 2830 | spin_lock(&(cachep->nodelists[nodeid])-> |
2764 | list_lock); | 2831 | list_lock); |
2765 | free_block(cachep, &objp, 1, nodeid); | 2832 | free_block(cachep, &objp, 1, nodeid); |
2766 | spin_unlock(&(cachep->nodelists[nodeid])-> | 2833 | spin_unlock(&(cachep->nodelists[nodeid])-> |
2767 | list_lock); | 2834 | list_lock); |
2768 | } | 2835 | } |
2769 | return; | 2836 | return; |
2770 | } | 2837 | } |
@@ -2811,9 +2878,9 @@ EXPORT_SYMBOL(kmem_cache_alloc); | |||
2811 | */ | 2878 | */ |
2812 | int fastcall kmem_ptr_validate(kmem_cache_t *cachep, void *ptr) | 2879 | int fastcall kmem_ptr_validate(kmem_cache_t *cachep, void *ptr) |
2813 | { | 2880 | { |
2814 | unsigned long addr = (unsigned long) ptr; | 2881 | unsigned long addr = (unsigned long)ptr; |
2815 | unsigned long min_addr = PAGE_OFFSET; | 2882 | unsigned long min_addr = PAGE_OFFSET; |
2816 | unsigned long align_mask = BYTES_PER_WORD-1; | 2883 | unsigned long align_mask = BYTES_PER_WORD - 1; |
2817 | unsigned long size = cachep->objsize; | 2884 | unsigned long size = cachep->objsize; |
2818 | struct page *page; | 2885 | struct page *page; |
2819 | 2886 | ||
@@ -2830,10 +2897,10 @@ int fastcall kmem_ptr_validate(kmem_cache_t *cachep, void *ptr) | |||
2830 | page = virt_to_page(ptr); | 2897 | page = virt_to_page(ptr); |
2831 | if (unlikely(!PageSlab(page))) | 2898 | if (unlikely(!PageSlab(page))) |
2832 | goto out; | 2899 | goto out; |
2833 | if (unlikely(GET_PAGE_CACHE(page) != cachep)) | 2900 | if (unlikely(page_get_cache(page) != cachep)) |
2834 | goto out; | 2901 | goto out; |
2835 | return 1; | 2902 | return 1; |
2836 | out: | 2903 | out: |
2837 | return 0; | 2904 | return 0; |
2838 | } | 2905 | } |
2839 | 2906 | ||
@@ -2860,8 +2927,10 @@ void *kmem_cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int nodeid) | |||
2860 | 2927 | ||
2861 | if (unlikely(!cachep->nodelists[nodeid])) { | 2928 | if (unlikely(!cachep->nodelists[nodeid])) { |
2862 | /* Fall back to __cache_alloc if we run into trouble */ | 2929 | /* Fall back to __cache_alloc if we run into trouble */ |
2863 | printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name); | 2930 | printk(KERN_WARNING |
2864 | return __cache_alloc(cachep,flags); | 2931 | "slab: not allocating in inactive node %d for cache %s\n", |
2932 | nodeid, cachep->name); | ||
2933 | return __cache_alloc(cachep, flags); | ||
2865 | } | 2934 | } |
2866 | 2935 | ||
2867 | cache_alloc_debugcheck_before(cachep, flags); | 2936 | cache_alloc_debugcheck_before(cachep, flags); |
@@ -2871,7 +2940,9 @@ void *kmem_cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int nodeid) | |||
2871 | else | 2940 | else |
2872 | ptr = __cache_alloc_node(cachep, flags, nodeid); | 2941 | ptr = __cache_alloc_node(cachep, flags, nodeid); |
2873 | local_irq_restore(save_flags); | 2942 | local_irq_restore(save_flags); |
2874 | ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0)); | 2943 | ptr = |
2944 | cache_alloc_debugcheck_after(cachep, flags, ptr, | ||
2945 | __builtin_return_address(0)); | ||
2875 | 2946 | ||
2876 | return ptr; | 2947 | return ptr; |
2877 | } | 2948 | } |
@@ -2933,12 +3004,11 @@ EXPORT_SYMBOL(__kmalloc); | |||
2933 | * Objects should be dereferenced using the per_cpu_ptr macro only. | 3004 | * Objects should be dereferenced using the per_cpu_ptr macro only. |
2934 | * | 3005 | * |
2935 | * @size: how many bytes of memory are required. | 3006 | * @size: how many bytes of memory are required. |
2936 | * @align: the alignment, which can't be greater than SMP_CACHE_BYTES. | ||
2937 | */ | 3007 | */ |
2938 | void *__alloc_percpu(size_t size, size_t align) | 3008 | void *__alloc_percpu(size_t size) |
2939 | { | 3009 | { |
2940 | int i; | 3010 | int i; |
2941 | struct percpu_data *pdata = kmalloc(sizeof (*pdata), GFP_KERNEL); | 3011 | struct percpu_data *pdata = kmalloc(sizeof(*pdata), GFP_KERNEL); |
2942 | 3012 | ||
2943 | if (!pdata) | 3013 | if (!pdata) |
2944 | return NULL; | 3014 | return NULL; |
@@ -2962,9 +3032,9 @@ void *__alloc_percpu(size_t size, size_t align) | |||
2962 | } | 3032 | } |
2963 | 3033 | ||
2964 | /* Catch derefs w/o wrappers */ | 3034 | /* Catch derefs w/o wrappers */ |
2965 | return (void *) (~(unsigned long) pdata); | 3035 | return (void *)(~(unsigned long)pdata); |
2966 | 3036 | ||
2967 | unwind_oom: | 3037 | unwind_oom: |
2968 | while (--i >= 0) { | 3038 | while (--i >= 0) { |
2969 | if (!cpu_possible(i)) | 3039 | if (!cpu_possible(i)) |
2970 | continue; | 3040 | continue; |
@@ -2995,20 +3065,6 @@ void kmem_cache_free(kmem_cache_t *cachep, void *objp) | |||
2995 | EXPORT_SYMBOL(kmem_cache_free); | 3065 | EXPORT_SYMBOL(kmem_cache_free); |
2996 | 3066 | ||
2997 | /** | 3067 | /** |
2998 | * kzalloc - allocate memory. The memory is set to zero. | ||
2999 | * @size: how many bytes of memory are required. | ||
3000 | * @flags: the type of memory to allocate. | ||
3001 | */ | ||
3002 | void *kzalloc(size_t size, gfp_t flags) | ||
3003 | { | ||
3004 | void *ret = kmalloc(size, flags); | ||
3005 | if (ret) | ||
3006 | memset(ret, 0, size); | ||
3007 | return ret; | ||
3008 | } | ||
3009 | EXPORT_SYMBOL(kzalloc); | ||
3010 | |||
3011 | /** | ||
3012 | * kfree - free previously allocated memory | 3068 | * kfree - free previously allocated memory |
3013 | * @objp: pointer returned by kmalloc. | 3069 | * @objp: pointer returned by kmalloc. |
3014 | * | 3070 | * |
@@ -3026,8 +3082,9 @@ void kfree(const void *objp) | |||
3026 | return; | 3082 | return; |
3027 | local_irq_save(flags); | 3083 | local_irq_save(flags); |
3028 | kfree_debugcheck(objp); | 3084 | kfree_debugcheck(objp); |
3029 | c = GET_PAGE_CACHE(virt_to_page(objp)); | 3085 | c = page_get_cache(virt_to_page(objp)); |
3030 | __cache_free(c, (void*)objp); | 3086 | mutex_debug_check_no_locks_freed(objp, obj_reallen(c)); |
3087 | __cache_free(c, (void *)objp); | ||
3031 | local_irq_restore(flags); | 3088 | local_irq_restore(flags); |
3032 | } | 3089 | } |
3033 | EXPORT_SYMBOL(kfree); | 3090 | EXPORT_SYMBOL(kfree); |
@@ -3040,17 +3097,16 @@ EXPORT_SYMBOL(kfree); | |||
3040 | * Don't free memory not originally allocated by alloc_percpu() | 3097 | * Don't free memory not originally allocated by alloc_percpu() |
3041 | * The complemented objp is to check for that. | 3098 | * The complemented objp is to check for that. |
3042 | */ | 3099 | */ |
3043 | void | 3100 | void free_percpu(const void *objp) |
3044 | free_percpu(const void *objp) | ||
3045 | { | 3101 | { |
3046 | int i; | 3102 | int i; |
3047 | struct percpu_data *p = (struct percpu_data *) (~(unsigned long) objp); | 3103 | struct percpu_data *p = (struct percpu_data *)(~(unsigned long)objp); |
3048 | 3104 | ||
3049 | /* | 3105 | /* |
3050 | * We allocate for all cpus so we cannot use for online cpu here. | 3106 | * We allocate for all cpus so we cannot use for online cpu here. |
3051 | */ | 3107 | */ |
3052 | for_each_cpu(i) | 3108 | for_each_cpu(i) |
3053 | kfree(p->ptrs[i]); | 3109 | kfree(p->ptrs[i]); |
3054 | kfree(p); | 3110 | kfree(p); |
3055 | } | 3111 | } |
3056 | EXPORT_SYMBOL(free_percpu); | 3112 | EXPORT_SYMBOL(free_percpu); |
@@ -3084,44 +3140,44 @@ static int alloc_kmemlist(kmem_cache_t *cachep) | |||
3084 | if (!(new_alien = alloc_alien_cache(node, cachep->limit))) | 3140 | if (!(new_alien = alloc_alien_cache(node, cachep->limit))) |
3085 | goto fail; | 3141 | goto fail; |
3086 | #endif | 3142 | #endif |
3087 | if (!(new = alloc_arraycache(node, (cachep->shared* | 3143 | if (!(new = alloc_arraycache(node, (cachep->shared * |
3088 | cachep->batchcount), 0xbaadf00d))) | 3144 | cachep->batchcount), |
3145 | 0xbaadf00d))) | ||
3089 | goto fail; | 3146 | goto fail; |
3090 | if ((l3 = cachep->nodelists[node])) { | 3147 | if ((l3 = cachep->nodelists[node])) { |
3091 | 3148 | ||
3092 | spin_lock_irq(&l3->list_lock); | 3149 | spin_lock_irq(&l3->list_lock); |
3093 | 3150 | ||
3094 | if ((nc = cachep->nodelists[node]->shared)) | 3151 | if ((nc = cachep->nodelists[node]->shared)) |
3095 | free_block(cachep, nc->entry, | 3152 | free_block(cachep, nc->entry, nc->avail, node); |
3096 | nc->avail, node); | ||
3097 | 3153 | ||
3098 | l3->shared = new; | 3154 | l3->shared = new; |
3099 | if (!cachep->nodelists[node]->alien) { | 3155 | if (!cachep->nodelists[node]->alien) { |
3100 | l3->alien = new_alien; | 3156 | l3->alien = new_alien; |
3101 | new_alien = NULL; | 3157 | new_alien = NULL; |
3102 | } | 3158 | } |
3103 | l3->free_limit = (1 + nr_cpus_node(node))* | 3159 | l3->free_limit = (1 + nr_cpus_node(node)) * |
3104 | cachep->batchcount + cachep->num; | 3160 | cachep->batchcount + cachep->num; |
3105 | spin_unlock_irq(&l3->list_lock); | 3161 | spin_unlock_irq(&l3->list_lock); |
3106 | kfree(nc); | 3162 | kfree(nc); |
3107 | free_alien_cache(new_alien); | 3163 | free_alien_cache(new_alien); |
3108 | continue; | 3164 | continue; |
3109 | } | 3165 | } |
3110 | if (!(l3 = kmalloc_node(sizeof(struct kmem_list3), | 3166 | if (!(l3 = kmalloc_node(sizeof(struct kmem_list3), |
3111 | GFP_KERNEL, node))) | 3167 | GFP_KERNEL, node))) |
3112 | goto fail; | 3168 | goto fail; |
3113 | 3169 | ||
3114 | kmem_list3_init(l3); | 3170 | kmem_list3_init(l3); |
3115 | l3->next_reap = jiffies + REAPTIMEOUT_LIST3 + | 3171 | l3->next_reap = jiffies + REAPTIMEOUT_LIST3 + |
3116 | ((unsigned long)cachep)%REAPTIMEOUT_LIST3; | 3172 | ((unsigned long)cachep) % REAPTIMEOUT_LIST3; |
3117 | l3->shared = new; | 3173 | l3->shared = new; |
3118 | l3->alien = new_alien; | 3174 | l3->alien = new_alien; |
3119 | l3->free_limit = (1 + nr_cpus_node(node))* | 3175 | l3->free_limit = (1 + nr_cpus_node(node)) * |
3120 | cachep->batchcount + cachep->num; | 3176 | cachep->batchcount + cachep->num; |
3121 | cachep->nodelists[node] = l3; | 3177 | cachep->nodelists[node] = l3; |
3122 | } | 3178 | } |
3123 | return err; | 3179 | return err; |
3124 | fail: | 3180 | fail: |
3125 | err = -ENOMEM; | 3181 | err = -ENOMEM; |
3126 | return err; | 3182 | return err; |
3127 | } | 3183 | } |
@@ -3143,18 +3199,19 @@ static void do_ccupdate_local(void *info) | |||
3143 | new->new[smp_processor_id()] = old; | 3199 | new->new[smp_processor_id()] = old; |
3144 | } | 3200 | } |
3145 | 3201 | ||
3146 | |||
3147 | static int do_tune_cpucache(kmem_cache_t *cachep, int limit, int batchcount, | 3202 | static int do_tune_cpucache(kmem_cache_t *cachep, int limit, int batchcount, |
3148 | int shared) | 3203 | int shared) |
3149 | { | 3204 | { |
3150 | struct ccupdate_struct new; | 3205 | struct ccupdate_struct new; |
3151 | int i, err; | 3206 | int i, err; |
3152 | 3207 | ||
3153 | memset(&new.new,0,sizeof(new.new)); | 3208 | memset(&new.new, 0, sizeof(new.new)); |
3154 | for_each_online_cpu(i) { | 3209 | for_each_online_cpu(i) { |
3155 | new.new[i] = alloc_arraycache(cpu_to_node(i), limit, batchcount); | 3210 | new.new[i] = |
3211 | alloc_arraycache(cpu_to_node(i), limit, batchcount); | ||
3156 | if (!new.new[i]) { | 3212 | if (!new.new[i]) { |
3157 | for (i--; i >= 0; i--) kfree(new.new[i]); | 3213 | for (i--; i >= 0; i--) |
3214 | kfree(new.new[i]); | ||
3158 | return -ENOMEM; | 3215 | return -ENOMEM; |
3159 | } | 3216 | } |
3160 | } | 3217 | } |
@@ -3182,13 +3239,12 @@ static int do_tune_cpucache(kmem_cache_t *cachep, int limit, int batchcount, | |||
3182 | err = alloc_kmemlist(cachep); | 3239 | err = alloc_kmemlist(cachep); |
3183 | if (err) { | 3240 | if (err) { |
3184 | printk(KERN_ERR "alloc_kmemlist failed for %s, error %d.\n", | 3241 | printk(KERN_ERR "alloc_kmemlist failed for %s, error %d.\n", |
3185 | cachep->name, -err); | 3242 | cachep->name, -err); |
3186 | BUG(); | 3243 | BUG(); |
3187 | } | 3244 | } |
3188 | return 0; | 3245 | return 0; |
3189 | } | 3246 | } |
3190 | 3247 | ||
3191 | |||
3192 | static void enable_cpucache(kmem_cache_t *cachep) | 3248 | static void enable_cpucache(kmem_cache_t *cachep) |
3193 | { | 3249 | { |
3194 | int err; | 3250 | int err; |
@@ -3235,14 +3291,14 @@ static void enable_cpucache(kmem_cache_t *cachep) | |||
3235 | if (limit > 32) | 3291 | if (limit > 32) |
3236 | limit = 32; | 3292 | limit = 32; |
3237 | #endif | 3293 | #endif |
3238 | err = do_tune_cpucache(cachep, limit, (limit+1)/2, shared); | 3294 | err = do_tune_cpucache(cachep, limit, (limit + 1) / 2, shared); |
3239 | if (err) | 3295 | if (err) |
3240 | printk(KERN_ERR "enable_cpucache failed for %s, error %d.\n", | 3296 | printk(KERN_ERR "enable_cpucache failed for %s, error %d.\n", |
3241 | cachep->name, -err); | 3297 | cachep->name, -err); |
3242 | } | 3298 | } |
3243 | 3299 | ||
3244 | static void drain_array_locked(kmem_cache_t *cachep, | 3300 | static void drain_array_locked(kmem_cache_t *cachep, struct array_cache *ac, |
3245 | struct array_cache *ac, int force, int node) | 3301 | int force, int node) |
3246 | { | 3302 | { |
3247 | int tofree; | 3303 | int tofree; |
3248 | 3304 | ||
@@ -3250,14 +3306,14 @@ static void drain_array_locked(kmem_cache_t *cachep, | |||
3250 | if (ac->touched && !force) { | 3306 | if (ac->touched && !force) { |
3251 | ac->touched = 0; | 3307 | ac->touched = 0; |
3252 | } else if (ac->avail) { | 3308 | } else if (ac->avail) { |
3253 | tofree = force ? ac->avail : (ac->limit+4)/5; | 3309 | tofree = force ? ac->avail : (ac->limit + 4) / 5; |
3254 | if (tofree > ac->avail) { | 3310 | if (tofree > ac->avail) { |
3255 | tofree = (ac->avail+1)/2; | 3311 | tofree = (ac->avail + 1) / 2; |
3256 | } | 3312 | } |
3257 | free_block(cachep, ac->entry, tofree, node); | 3313 | free_block(cachep, ac->entry, tofree, node); |
3258 | ac->avail -= tofree; | 3314 | ac->avail -= tofree; |
3259 | memmove(ac->entry, &(ac->entry[tofree]), | 3315 | memmove(ac->entry, &(ac->entry[tofree]), |
3260 | sizeof(void*)*ac->avail); | 3316 | sizeof(void *) * ac->avail); |
3261 | } | 3317 | } |
3262 | } | 3318 | } |
3263 | 3319 | ||
@@ -3270,7 +3326,7 @@ static void drain_array_locked(kmem_cache_t *cachep, | |||
3270 | * - clear the per-cpu caches for this CPU. | 3326 | * - clear the per-cpu caches for this CPU. |
3271 | * - return freeable pages to the main free memory pool. | 3327 | * - return freeable pages to the main free memory pool. |
3272 | * | 3328 | * |
3273 | * If we cannot acquire the cache chain semaphore then just give up - we'll | 3329 | * If we cannot acquire the cache chain mutex then just give up - we'll |
3274 | * try again on the next iteration. | 3330 | * try again on the next iteration. |
3275 | */ | 3331 | */ |
3276 | static void cache_reap(void *unused) | 3332 | static void cache_reap(void *unused) |
@@ -3278,15 +3334,16 @@ static void cache_reap(void *unused) | |||
3278 | struct list_head *walk; | 3334 | struct list_head *walk; |
3279 | struct kmem_list3 *l3; | 3335 | struct kmem_list3 *l3; |
3280 | 3336 | ||
3281 | if (down_trylock(&cache_chain_sem)) { | 3337 | if (!mutex_trylock(&cache_chain_mutex)) { |
3282 | /* Give up. Setup the next iteration. */ | 3338 | /* Give up. Setup the next iteration. */ |
3283 | schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC); | 3339 | schedule_delayed_work(&__get_cpu_var(reap_work), |
3340 | REAPTIMEOUT_CPUC); | ||
3284 | return; | 3341 | return; |
3285 | } | 3342 | } |
3286 | 3343 | ||
3287 | list_for_each(walk, &cache_chain) { | 3344 | list_for_each(walk, &cache_chain) { |
3288 | kmem_cache_t *searchp; | 3345 | kmem_cache_t *searchp; |
3289 | struct list_head* p; | 3346 | struct list_head *p; |
3290 | int tofree; | 3347 | int tofree; |
3291 | struct slab *slabp; | 3348 | struct slab *slabp; |
3292 | 3349 | ||
@@ -3303,7 +3360,7 @@ static void cache_reap(void *unused) | |||
3303 | spin_lock_irq(&l3->list_lock); | 3360 | spin_lock_irq(&l3->list_lock); |
3304 | 3361 | ||
3305 | drain_array_locked(searchp, ac_data(searchp), 0, | 3362 | drain_array_locked(searchp, ac_data(searchp), 0, |
3306 | numa_node_id()); | 3363 | numa_node_id()); |
3307 | 3364 | ||
3308 | if (time_after(l3->next_reap, jiffies)) | 3365 | if (time_after(l3->next_reap, jiffies)) |
3309 | goto next_unlock; | 3366 | goto next_unlock; |
@@ -3312,14 +3369,16 @@ static void cache_reap(void *unused) | |||
3312 | 3369 | ||
3313 | if (l3->shared) | 3370 | if (l3->shared) |
3314 | drain_array_locked(searchp, l3->shared, 0, | 3371 | drain_array_locked(searchp, l3->shared, 0, |
3315 | numa_node_id()); | 3372 | numa_node_id()); |
3316 | 3373 | ||
3317 | if (l3->free_touched) { | 3374 | if (l3->free_touched) { |
3318 | l3->free_touched = 0; | 3375 | l3->free_touched = 0; |
3319 | goto next_unlock; | 3376 | goto next_unlock; |
3320 | } | 3377 | } |
3321 | 3378 | ||
3322 | tofree = (l3->free_limit+5*searchp->num-1)/(5*searchp->num); | 3379 | tofree = |
3380 | (l3->free_limit + 5 * searchp->num - | ||
3381 | 1) / (5 * searchp->num); | ||
3323 | do { | 3382 | do { |
3324 | p = l3->slabs_free.next; | 3383 | p = l3->slabs_free.next; |
3325 | if (p == &(l3->slabs_free)) | 3384 | if (p == &(l3->slabs_free)) |
@@ -3339,14 +3398,14 @@ static void cache_reap(void *unused) | |||
3339 | spin_unlock_irq(&l3->list_lock); | 3398 | spin_unlock_irq(&l3->list_lock); |
3340 | slab_destroy(searchp, slabp); | 3399 | slab_destroy(searchp, slabp); |
3341 | spin_lock_irq(&l3->list_lock); | 3400 | spin_lock_irq(&l3->list_lock); |
3342 | } while(--tofree > 0); | 3401 | } while (--tofree > 0); |
3343 | next_unlock: | 3402 | next_unlock: |
3344 | spin_unlock_irq(&l3->list_lock); | 3403 | spin_unlock_irq(&l3->list_lock); |
3345 | next: | 3404 | next: |
3346 | cond_resched(); | 3405 | cond_resched(); |
3347 | } | 3406 | } |
3348 | check_irq_on(); | 3407 | check_irq_on(); |
3349 | up(&cache_chain_sem); | 3408 | mutex_unlock(&cache_chain_mutex); |
3350 | drain_remote_pages(); | 3409 | drain_remote_pages(); |
3351 | /* Setup the next iteration */ | 3410 | /* Setup the next iteration */ |
3352 | schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC); | 3411 | schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC); |
@@ -3354,32 +3413,37 @@ next: | |||
3354 | 3413 | ||
3355 | #ifdef CONFIG_PROC_FS | 3414 | #ifdef CONFIG_PROC_FS |
3356 | 3415 | ||
3357 | static void *s_start(struct seq_file *m, loff_t *pos) | 3416 | static void print_slabinfo_header(struct seq_file *m) |
3358 | { | 3417 | { |
3359 | loff_t n = *pos; | 3418 | /* |
3360 | struct list_head *p; | 3419 | * Output format version, so at least we can change it |
3361 | 3420 | * without _too_ many complaints. | |
3362 | down(&cache_chain_sem); | 3421 | */ |
3363 | if (!n) { | ||
3364 | /* | ||
3365 | * Output format version, so at least we can change it | ||
3366 | * without _too_ many complaints. | ||
3367 | */ | ||
3368 | #if STATS | 3422 | #if STATS |
3369 | seq_puts(m, "slabinfo - version: 2.1 (statistics)\n"); | 3423 | seq_puts(m, "slabinfo - version: 2.1 (statistics)\n"); |
3370 | #else | 3424 | #else |
3371 | seq_puts(m, "slabinfo - version: 2.1\n"); | 3425 | seq_puts(m, "slabinfo - version: 2.1\n"); |
3372 | #endif | 3426 | #endif |
3373 | seq_puts(m, "# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>"); | 3427 | seq_puts(m, "# name <active_objs> <num_objs> <objsize> " |
3374 | seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>"); | 3428 | "<objperslab> <pagesperslab>"); |
3375 | seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>"); | 3429 | seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>"); |
3430 | seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>"); | ||
3376 | #if STATS | 3431 | #if STATS |
3377 | seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped>" | 3432 | seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> " |
3378 | " <error> <maxfreeable> <nodeallocs> <remotefrees>"); | 3433 | "<error> <maxfreeable> <nodeallocs> <remotefrees>"); |
3379 | seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>"); | 3434 | seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>"); |
3380 | #endif | 3435 | #endif |
3381 | seq_putc(m, '\n'); | 3436 | seq_putc(m, '\n'); |
3382 | } | 3437 | } |
3438 | |||
3439 | static void *s_start(struct seq_file *m, loff_t *pos) | ||
3440 | { | ||
3441 | loff_t n = *pos; | ||
3442 | struct list_head *p; | ||
3443 | |||
3444 | mutex_lock(&cache_chain_mutex); | ||
3445 | if (!n) | ||
3446 | print_slabinfo_header(m); | ||
3383 | p = cache_chain.next; | 3447 | p = cache_chain.next; |
3384 | while (n--) { | 3448 | while (n--) { |
3385 | p = p->next; | 3449 | p = p->next; |
@@ -3394,23 +3458,23 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos) | |||
3394 | kmem_cache_t *cachep = p; | 3458 | kmem_cache_t *cachep = p; |
3395 | ++*pos; | 3459 | ++*pos; |
3396 | return cachep->next.next == &cache_chain ? NULL | 3460 | return cachep->next.next == &cache_chain ? NULL |
3397 | : list_entry(cachep->next.next, kmem_cache_t, next); | 3461 | : list_entry(cachep->next.next, kmem_cache_t, next); |
3398 | } | 3462 | } |
3399 | 3463 | ||
3400 | static void s_stop(struct seq_file *m, void *p) | 3464 | static void s_stop(struct seq_file *m, void *p) |
3401 | { | 3465 | { |
3402 | up(&cache_chain_sem); | 3466 | mutex_unlock(&cache_chain_mutex); |
3403 | } | 3467 | } |
3404 | 3468 | ||
3405 | static int s_show(struct seq_file *m, void *p) | 3469 | static int s_show(struct seq_file *m, void *p) |
3406 | { | 3470 | { |
3407 | kmem_cache_t *cachep = p; | 3471 | kmem_cache_t *cachep = p; |
3408 | struct list_head *q; | 3472 | struct list_head *q; |
3409 | struct slab *slabp; | 3473 | struct slab *slabp; |
3410 | unsigned long active_objs; | 3474 | unsigned long active_objs; |
3411 | unsigned long num_objs; | 3475 | unsigned long num_objs; |
3412 | unsigned long active_slabs = 0; | 3476 | unsigned long active_slabs = 0; |
3413 | unsigned long num_slabs, free_objects = 0, shared_avail = 0; | 3477 | unsigned long num_slabs, free_objects = 0, shared_avail = 0; |
3414 | const char *name; | 3478 | const char *name; |
3415 | char *error = NULL; | 3479 | char *error = NULL; |
3416 | int node; | 3480 | int node; |
@@ -3427,14 +3491,14 @@ static int s_show(struct seq_file *m, void *p) | |||
3427 | 3491 | ||
3428 | spin_lock(&l3->list_lock); | 3492 | spin_lock(&l3->list_lock); |
3429 | 3493 | ||
3430 | list_for_each(q,&l3->slabs_full) { | 3494 | list_for_each(q, &l3->slabs_full) { |
3431 | slabp = list_entry(q, struct slab, list); | 3495 | slabp = list_entry(q, struct slab, list); |
3432 | if (slabp->inuse != cachep->num && !error) | 3496 | if (slabp->inuse != cachep->num && !error) |
3433 | error = "slabs_full accounting error"; | 3497 | error = "slabs_full accounting error"; |
3434 | active_objs += cachep->num; | 3498 | active_objs += cachep->num; |
3435 | active_slabs++; | 3499 | active_slabs++; |
3436 | } | 3500 | } |
3437 | list_for_each(q,&l3->slabs_partial) { | 3501 | list_for_each(q, &l3->slabs_partial) { |
3438 | slabp = list_entry(q, struct slab, list); | 3502 | slabp = list_entry(q, struct slab, list); |
3439 | if (slabp->inuse == cachep->num && !error) | 3503 | if (slabp->inuse == cachep->num && !error) |
3440 | error = "slabs_partial inuse accounting error"; | 3504 | error = "slabs_partial inuse accounting error"; |
@@ -3443,7 +3507,7 @@ static int s_show(struct seq_file *m, void *p) | |||
3443 | active_objs += slabp->inuse; | 3507 | active_objs += slabp->inuse; |
3444 | active_slabs++; | 3508 | active_slabs++; |
3445 | } | 3509 | } |
3446 | list_for_each(q,&l3->slabs_free) { | 3510 | list_for_each(q, &l3->slabs_free) { |
3447 | slabp = list_entry(q, struct slab, list); | 3511 | slabp = list_entry(q, struct slab, list); |
3448 | if (slabp->inuse && !error) | 3512 | if (slabp->inuse && !error) |
3449 | error = "slabs_free/inuse accounting error"; | 3513 | error = "slabs_free/inuse accounting error"; |
@@ -3454,25 +3518,24 @@ static int s_show(struct seq_file *m, void *p) | |||
3454 | 3518 | ||
3455 | spin_unlock(&l3->list_lock); | 3519 | spin_unlock(&l3->list_lock); |
3456 | } | 3520 | } |
3457 | num_slabs+=active_slabs; | 3521 | num_slabs += active_slabs; |
3458 | num_objs = num_slabs*cachep->num; | 3522 | num_objs = num_slabs * cachep->num; |
3459 | if (num_objs - active_objs != free_objects && !error) | 3523 | if (num_objs - active_objs != free_objects && !error) |
3460 | error = "free_objects accounting error"; | 3524 | error = "free_objects accounting error"; |
3461 | 3525 | ||
3462 | name = cachep->name; | 3526 | name = cachep->name; |
3463 | if (error) | 3527 | if (error) |
3464 | printk(KERN_ERR "slab: cache %s error: %s\n", name, error); | 3528 | printk(KERN_ERR "slab: cache %s error: %s\n", name, error); |
3465 | 3529 | ||
3466 | seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d", | 3530 | seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d", |
3467 | name, active_objs, num_objs, cachep->objsize, | 3531 | name, active_objs, num_objs, cachep->objsize, |
3468 | cachep->num, (1<<cachep->gfporder)); | 3532 | cachep->num, (1 << cachep->gfporder)); |
3469 | seq_printf(m, " : tunables %4u %4u %4u", | 3533 | seq_printf(m, " : tunables %4u %4u %4u", |
3470 | cachep->limit, cachep->batchcount, | 3534 | cachep->limit, cachep->batchcount, cachep->shared); |
3471 | cachep->shared); | ||
3472 | seq_printf(m, " : slabdata %6lu %6lu %6lu", | 3535 | seq_printf(m, " : slabdata %6lu %6lu %6lu", |
3473 | active_slabs, num_slabs, shared_avail); | 3536 | active_slabs, num_slabs, shared_avail); |
3474 | #if STATS | 3537 | #if STATS |
3475 | { /* list3 stats */ | 3538 | { /* list3 stats */ |
3476 | unsigned long high = cachep->high_mark; | 3539 | unsigned long high = cachep->high_mark; |
3477 | unsigned long allocs = cachep->num_allocations; | 3540 | unsigned long allocs = cachep->num_allocations; |
3478 | unsigned long grown = cachep->grown; | 3541 | unsigned long grown = cachep->grown; |
@@ -3483,9 +3546,7 @@ static int s_show(struct seq_file *m, void *p) | |||
3483 | unsigned long node_frees = cachep->node_frees; | 3546 | unsigned long node_frees = cachep->node_frees; |
3484 | 3547 | ||
3485 | seq_printf(m, " : globalstat %7lu %6lu %5lu %4lu \ | 3548 | seq_printf(m, " : globalstat %7lu %6lu %5lu %4lu \ |
3486 | %4lu %4lu %4lu %4lu", | 3549 | %4lu %4lu %4lu %4lu", allocs, high, grown, reaped, errors, max_freeable, node_allocs, node_frees); |
3487 | allocs, high, grown, reaped, errors, | ||
3488 | max_freeable, node_allocs, node_frees); | ||
3489 | } | 3550 | } |
3490 | /* cpu stats */ | 3551 | /* cpu stats */ |
3491 | { | 3552 | { |
@@ -3495,7 +3556,7 @@ static int s_show(struct seq_file *m, void *p) | |||
3495 | unsigned long freemiss = atomic_read(&cachep->freemiss); | 3556 | unsigned long freemiss = atomic_read(&cachep->freemiss); |
3496 | 3557 | ||
3497 | seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu", | 3558 | seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu", |
3498 | allochit, allocmiss, freehit, freemiss); | 3559 | allochit, allocmiss, freehit, freemiss); |
3499 | } | 3560 | } |
3500 | #endif | 3561 | #endif |
3501 | seq_putc(m, '\n'); | 3562 | seq_putc(m, '\n'); |
@@ -3518,10 +3579,10 @@ static int s_show(struct seq_file *m, void *p) | |||
3518 | */ | 3579 | */ |
3519 | 3580 | ||
3520 | struct seq_operations slabinfo_op = { | 3581 | struct seq_operations slabinfo_op = { |
3521 | .start = s_start, | 3582 | .start = s_start, |
3522 | .next = s_next, | 3583 | .next = s_next, |
3523 | .stop = s_stop, | 3584 | .stop = s_stop, |
3524 | .show = s_show, | 3585 | .show = s_show, |
3525 | }; | 3586 | }; |
3526 | 3587 | ||
3527 | #define MAX_SLABINFO_WRITE 128 | 3588 | #define MAX_SLABINFO_WRITE 128 |
@@ -3532,18 +3593,18 @@ struct seq_operations slabinfo_op = { | |||
3532 | * @count: data length | 3593 | * @count: data length |
3533 | * @ppos: unused | 3594 | * @ppos: unused |
3534 | */ | 3595 | */ |
3535 | ssize_t slabinfo_write(struct file *file, const char __user *buffer, | 3596 | ssize_t slabinfo_write(struct file *file, const char __user * buffer, |
3536 | size_t count, loff_t *ppos) | 3597 | size_t count, loff_t *ppos) |
3537 | { | 3598 | { |
3538 | char kbuf[MAX_SLABINFO_WRITE+1], *tmp; | 3599 | char kbuf[MAX_SLABINFO_WRITE + 1], *tmp; |
3539 | int limit, batchcount, shared, res; | 3600 | int limit, batchcount, shared, res; |
3540 | struct list_head *p; | 3601 | struct list_head *p; |
3541 | 3602 | ||
3542 | if (count > MAX_SLABINFO_WRITE) | 3603 | if (count > MAX_SLABINFO_WRITE) |
3543 | return -EINVAL; | 3604 | return -EINVAL; |
3544 | if (copy_from_user(&kbuf, buffer, count)) | 3605 | if (copy_from_user(&kbuf, buffer, count)) |
3545 | return -EFAULT; | 3606 | return -EFAULT; |
3546 | kbuf[MAX_SLABINFO_WRITE] = '\0'; | 3607 | kbuf[MAX_SLABINFO_WRITE] = '\0'; |
3547 | 3608 | ||
3548 | tmp = strchr(kbuf, ' '); | 3609 | tmp = strchr(kbuf, ' '); |
3549 | if (!tmp) | 3610 | if (!tmp) |
@@ -3554,25 +3615,24 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer, | |||
3554 | return -EINVAL; | 3615 | return -EINVAL; |
3555 | 3616 | ||
3556 | /* Find the cache in the chain of caches. */ | 3617 | /* Find the cache in the chain of caches. */ |
3557 | down(&cache_chain_sem); | 3618 | mutex_lock(&cache_chain_mutex); |
3558 | res = -EINVAL; | 3619 | res = -EINVAL; |
3559 | list_for_each(p,&cache_chain) { | 3620 | list_for_each(p, &cache_chain) { |
3560 | kmem_cache_t *cachep = list_entry(p, kmem_cache_t, next); | 3621 | kmem_cache_t *cachep = list_entry(p, kmem_cache_t, next); |
3561 | 3622 | ||
3562 | if (!strcmp(cachep->name, kbuf)) { | 3623 | if (!strcmp(cachep->name, kbuf)) { |
3563 | if (limit < 1 || | 3624 | if (limit < 1 || |
3564 | batchcount < 1 || | 3625 | batchcount < 1 || |
3565 | batchcount > limit || | 3626 | batchcount > limit || shared < 0) { |
3566 | shared < 0) { | ||
3567 | res = 0; | 3627 | res = 0; |
3568 | } else { | 3628 | } else { |
3569 | res = do_tune_cpucache(cachep, limit, | 3629 | res = do_tune_cpucache(cachep, limit, |
3570 | batchcount, shared); | 3630 | batchcount, shared); |
3571 | } | 3631 | } |
3572 | break; | 3632 | break; |
3573 | } | 3633 | } |
3574 | } | 3634 | } |
3575 | up(&cache_chain_sem); | 3635 | mutex_unlock(&cache_chain_mutex); |
3576 | if (res >= 0) | 3636 | if (res >= 0) |
3577 | res = count; | 3637 | res = count; |
3578 | return res; | 3638 | return res; |
@@ -3596,28 +3656,5 @@ unsigned int ksize(const void *objp) | |||
3596 | if (unlikely(objp == NULL)) | 3656 | if (unlikely(objp == NULL)) |
3597 | return 0; | 3657 | return 0; |
3598 | 3658 | ||
3599 | return obj_reallen(GET_PAGE_CACHE(virt_to_page(objp))); | 3659 | return obj_reallen(page_get_cache(virt_to_page(objp))); |
3600 | } | ||
3601 | |||
3602 | |||
3603 | /* | ||
3604 | * kstrdup - allocate space for and copy an existing string | ||
3605 | * | ||
3606 | * @s: the string to duplicate | ||
3607 | * @gfp: the GFP mask used in the kmalloc() call when allocating memory | ||
3608 | */ | ||
3609 | char *kstrdup(const char *s, gfp_t gfp) | ||
3610 | { | ||
3611 | size_t len; | ||
3612 | char *buf; | ||
3613 | |||
3614 | if (!s) | ||
3615 | return NULL; | ||
3616 | |||
3617 | len = strlen(s) + 1; | ||
3618 | buf = kmalloc(len, gfp); | ||
3619 | if (buf) | ||
3620 | memcpy(buf, s, len); | ||
3621 | return buf; | ||
3622 | } | 3660 | } |
3623 | EXPORT_SYMBOL(kstrdup); | ||