140140#define DEBUG_DEFAULT_FLAGS (SLAB_DEBUG_FREE | SLAB_RED_ZONE | \
141141 SLAB_POISON | SLAB_STORE_USER)
142142
143+ /*
144+ * Debugging flags that require metadata to be stored in the slab. These get
145+ * disabled when slub_debug=O is used and a cache's min order increases with
146+ * metadata.
147+ */
148+ #define DEBUG_METADATA_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
149+
143150/*
144151 * Set of flags that will prevent slab merging
145152 */
@@ -325,6 +332,7 @@ static int slub_debug;
325332#endif
326333
327334static char * slub_debug_slabs ;
335+ static int disable_higher_order_debug ;
328336
329337/*
330338 * Object debugging
@@ -646,7 +654,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
646654 slab_err (s , page , "Padding overwritten. 0x%p-0x%p" , fault , end - 1 );
647655 print_section ("Padding" , end - remainder , remainder );
648656
649- restore_bytes (s , "slab padding" , POISON_INUSE , start , end );
657+ restore_bytes (s , "slab padding" , POISON_INUSE , end - remainder , end );
650658 return 0 ;
651659}
652660
@@ -976,6 +984,15 @@ static int __init setup_slub_debug(char *str)
976984 */
977985 goto check_slabs ;
978986
987+ if (tolower (* str ) == 'o' ) {
988+ /*
989+ * Avoid enabling debugging on caches if its minimum order
990+ * would increase as a result.
991+ */
992+ disable_higher_order_debug = 1 ;
993+ goto out ;
994+ }
995+
979996 slub_debug = 0 ;
980997 if (* str == '-' )
981998 /*
@@ -1026,8 +1043,8 @@ static unsigned long kmem_cache_flags(unsigned long objsize,
10261043 * Enable debugging if selected on the kernel commandline.
10271044 */
10281045 if (slub_debug && (!slub_debug_slabs ||
1029- strncmp (slub_debug_slabs , name , strlen (slub_debug_slabs )) == 0 ))
1030- flags |= slub_debug ;
1046+ ! strncmp (slub_debug_slabs , name , strlen (slub_debug_slabs ))))
1047+ flags |= slub_debug ;
10311048
10321049 return flags ;
10331050}
@@ -1109,8 +1126,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
11091126 }
11101127
11111128 if (kmemcheck_enabled
1112- && !(s -> flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS )))
1113- {
1129+ && !(s -> flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS ))) {
11141130 int pages = 1 << oo_order (oo );
11151131
11161132 kmemcheck_alloc_shadow (page , oo_order (oo ), flags , node );
@@ -1560,6 +1576,10 @@ slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
15601576 "default order: %d, min order: %d\n" , s -> name , s -> objsize ,
15611577 s -> size , oo_order (s -> oo ), oo_order (s -> min ));
15621578
1579+ if (oo_order (s -> min ) > get_order (s -> objsize ))
1580+ printk (KERN_WARNING " %s debugging increased min order, use "
1581+ "slub_debug=O to disable.\n" , s -> name );
1582+
15631583 for_each_online_node (node ) {
15641584 struct kmem_cache_node * n = get_node (s , node );
15651585 unsigned long nr_slabs ;
@@ -2001,7 +2021,7 @@ static inline int calculate_order(int size)
20012021 return order ;
20022022 fraction /= 2 ;
20032023 }
2004- min_objects -- ;
2024+ min_objects -- ;
20052025 }
20062026
20072027 /*
@@ -2400,6 +2420,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
24002420 * on bootup.
24012421 */
24022422 align = calculate_alignment (flags , align , s -> objsize );
2423+ s -> align = align ;
24032424
24042425 /*
24052426 * SLUB stores one object immediately after another beginning from
@@ -2452,6 +2473,18 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
24522473
24532474 if (!calculate_sizes (s , -1 ))
24542475 goto error ;
2476+ if (disable_higher_order_debug ) {
2477+ /*
2478+ * Disable debugging flags that store metadata if the min slab
2479+ * order increased.
2480+ */
2481+ if (get_order (s -> size ) > get_order (s -> objsize )) {
2482+ s -> flags &= ~DEBUG_METADATA_FLAGS ;
2483+ s -> offset = 0 ;
2484+ if (!calculate_sizes (s , -1 ))
2485+ goto error ;
2486+ }
2487+ }
24552488
24562489 /*
24572490 * The larger the object size is, the more pages we want on the partial
@@ -2790,6 +2823,11 @@ static s8 size_index[24] = {
27902823 2 /* 192 */
27912824};
27922825
2826+ static inline int size_index_elem (size_t bytes )
2827+ {
2828+ return (bytes - 1 ) / 8 ;
2829+ }
2830+
27932831static struct kmem_cache * get_slab (size_t size , gfp_t flags )
27942832{
27952833 int index ;
@@ -2798,7 +2836,7 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
27982836 if (!size )
27992837 return ZERO_SIZE_PTR ;
28002838
2801- index = size_index [(size - 1 ) / 8 ];
2839+ index = size_index [size_index_elem (size ) ];
28022840 } else
28032841 index = fls (size - 1 );
28042842
@@ -3156,10 +3194,12 @@ void __init kmem_cache_init(void)
31563194 slab_state = PARTIAL ;
31573195
31583196 /* Caches that are not of the two-to-the-power-of size */
3159- if (KMALLOC_MIN_SIZE <= 64 ) {
3197+ if (KMALLOC_MIN_SIZE <= 32 ) {
31603198 create_kmalloc_cache (& kmalloc_caches [1 ],
31613199 "kmalloc-96" , 96 , GFP_NOWAIT );
31623200 caches ++ ;
3201+ }
3202+ if (KMALLOC_MIN_SIZE <= 64 ) {
31633203 create_kmalloc_cache (& kmalloc_caches [2 ],
31643204 "kmalloc-192" , 192 , GFP_NOWAIT );
31653205 caches ++ ;
@@ -3186,17 +3226,28 @@ void __init kmem_cache_init(void)
31863226 BUILD_BUG_ON (KMALLOC_MIN_SIZE > 256 ||
31873227 (KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1 )));
31883228
3189- for (i = 8 ; i < KMALLOC_MIN_SIZE ; i += 8 )
3190- size_index [(i - 1 ) / 8 ] = KMALLOC_SHIFT_LOW ;
3229+ for (i = 8 ; i < KMALLOC_MIN_SIZE ; i += 8 ) {
3230+ int elem = size_index_elem (i );
3231+ if (elem >= ARRAY_SIZE (size_index ))
3232+ break ;
3233+ size_index [elem ] = KMALLOC_SHIFT_LOW ;
3234+ }
31913235
3192- if (KMALLOC_MIN_SIZE == 128 ) {
3236+ if (KMALLOC_MIN_SIZE == 64 ) {
3237+ /*
3238+ * The 96 byte size cache is not used if the alignment
3239+ * is 64 byte.
3240+ */
3241+ for (i = 64 + 8 ; i <= 96 ; i += 8 )
3242+ size_index [size_index_elem (i )] = 7 ;
3243+ } else if (KMALLOC_MIN_SIZE == 128 ) {
31933244 /*
31943245 * The 192 byte sized cache is not used if the alignment
31953246 * is 128 byte. Redirect kmalloc to use the 256 byte cache
31963247 * instead.
31973248 */
31983249 for (i = 128 + 8 ; i <= 192 ; i += 8 )
3199- size_index [( i - 1 ) / 8 ] = 8 ;
3250+ size_index [size_index_elem ( i ) ] = 8 ;
32003251 }
32013252
32023253 slab_state = UP ;
@@ -4543,8 +4594,11 @@ static int sysfs_slab_add(struct kmem_cache *s)
45434594 }
45444595
45454596 err = sysfs_create_group (& s -> kobj , & slab_attr_group );
4546- if (err )
4597+ if (err ) {
4598+ kobject_del (& s -> kobj );
4599+ kobject_put (& s -> kobj );
45474600 return err ;
4601+ }
45484602 kobject_uevent (& s -> kobj , KOBJ_ADD );
45494603 if (!unmergeable ) {
45504604 /* Setup first alias */
@@ -4726,7 +4780,7 @@ static const struct file_operations proc_slabinfo_operations = {
47264780
47274781static int __init slab_proc_init (void )
47284782{
4729- proc_create ("slabinfo" ,S_IWUSR | S_IRUGO ,NULL ,& proc_slabinfo_operations );
4783+ proc_create ("slabinfo" , S_IRUGO , NULL , & proc_slabinfo_operations );
47304784 return 0 ;
47314785}
47324786module_init (slab_proc_init );
0 commit comments