aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/mm/slub.c b/mm/slub.c
index d2f343a54bad..217b5b5338a2 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -797,10 +797,34 @@ static inline int slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags)
797 return should_failslab(s->objsize, flags, s->flags); 797 return should_failslab(s->objsize, flags, s->flags);
798} 798}
799 799
800static inline size_t slab_ksize(const struct kmem_cache *s)
801{
802#ifdef CONFIG_SLUB_DEBUG
803 /*
804 * Debugging requires use of the padding between object
805 * and whatever may come after it.
806 */
807 if (s->flags & (SLAB_RED_ZONE | SLAB_POISON))
808 return s->objsize;
809
810#endif
811 /*
812 * If we have the need to store the freelist pointer
813 * back there or track user information then we can
814 * only use the space before that information.
815 */
816 if (s->flags & (SLAB_DESTROY_BY_RCU | SLAB_STORE_USER))
817 return s->inuse;
818 /*
819 * Else we can use all the padding etc for the allocation
820 */
821 return s->size;
822}
823
800static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, void *object) 824static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, void *object)
801{ 825{
802 flags &= gfp_allowed_mask; 826 flags &= gfp_allowed_mask;
803 kmemcheck_slab_alloc(s, flags, object, s->objsize); 827 kmemcheck_slab_alloc(s, flags, object, slab_ksize(s));
804 kmemleak_alloc_recursive(object, s->objsize, 1, s->flags, flags); 828 kmemleak_alloc_recursive(object, s->objsize, 1, s->flags, flags);
805} 829}
806 830
@@ -2690,7 +2714,6 @@ EXPORT_SYMBOL(__kmalloc_node);
2690size_t ksize(const void *object) 2714size_t ksize(const void *object)
2691{ 2715{
2692 struct page *page; 2716 struct page *page;
2693 struct kmem_cache *s;
2694 2717
2695 if (unlikely(object == ZERO_SIZE_PTR)) 2718 if (unlikely(object == ZERO_SIZE_PTR))
2696 return 0; 2719 return 0;
@@ -2701,28 +2724,8 @@ size_t ksize(const void *object)
2701 WARN_ON(!PageCompound(page)); 2724 WARN_ON(!PageCompound(page));
2702 return PAGE_SIZE << compound_order(page); 2725 return PAGE_SIZE << compound_order(page);
2703 } 2726 }
2704 s = page->slab;
2705 2727
2706#ifdef CONFIG_SLUB_DEBUG 2728 return slab_ksize(page->slab);
2707 /*
2708 * Debugging requires use of the padding between object
2709 * and whatever may come after it.
2710 */
2711 if (s->flags & (SLAB_RED_ZONE | SLAB_POISON))
2712 return s->objsize;
2713
2714#endif
2715 /*
2716 * If we have the need to store the freelist pointer
2717 * back there or track user information then we can
2718 * only use the space before that information.
2719 */
2720 if (s->flags & (SLAB_DESTROY_BY_RCU | SLAB_STORE_USER))
2721 return s->inuse;
2722 /*
2723 * Else we can use all the padding etc for the allocation
2724 */
2725 return s->size;
2726} 2729}
2727EXPORT_SYMBOL(ksize); 2730EXPORT_SYMBOL(ksize);
2728 2731