Skip to content

Commit bb193c9

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/slab-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/slab-2.6: slub: fix slab_pad_check() slub: release kobject if sysfs_create_group failed in sysfs_slab_add SLUB: fix ARCH_KMALLOC_MINALIGN cases 64 and 256 SLUB: Fix some coding style issues SLUB: Drop write permission to /proc/slabinfo slab: remove duplicate kmem_cache_init_late() declarations slub: change kmem_cache->align to record the real alignment slub: use size and objsize orders to disable debug flags slub: add option to disable higher order debugging slabs
2 parents f65ac45 + aceda77 commit bb193c9

5 files changed

Lines changed: 85 additions & 25 deletions

File tree

‎Documentation/vm/slub.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Possible debug options are
4141
P Poisoning (object and padding)
4242
U User tracking (free and alloc)
4343
T Trace (please only use on single slabs)
44+
O Switch debugging off for caches that would have
45+
caused higher minimum slab orders
4446
- Switch all debugging off (useful if the kernel is
4547
configured with CONFIG_SLUB_DEBUG_ON)
4648

@@ -59,6 +61,14 @@ to the dentry cache with
5961

6062
slub_debug=F,dentry
6163

64+
Debugging options may require the minimum possible slab order to increase as
65+
a result of storing the metadata (for example, caches with PAGE_SIZE object
66+
sizes). This has a higher liklihood of resulting in slab allocation errors
67+
in low memory situations or if there's high fragmentation of memory. To
68+
switch off debugging for such caches by default, use
69+
70+
slub_debug=O
71+
6272
In case you forgot to enable debugging on the kernel command line: It is
6373
possible to enable debugging manually when the kernel is up. Look at the
6474
contents of:

‎include/linux/slob_def.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@ static __always_inline void *__kmalloc(size_t size, gfp_t flags)
3434
return kmalloc(size, flags);
3535
}
3636

37-
static inline void kmem_cache_init_late(void)
38-
{
39-
/* Nothing to do */
40-
}
41-
4237
#endif /* __LINUX_SLOB_DEF_H */

‎include/linux/slub_def.h‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,10 @@ static __always_inline int kmalloc_index(size_t size)
153153
if (size <= KMALLOC_MIN_SIZE)
154154
return KMALLOC_SHIFT_LOW;
155155

156-
#if KMALLOC_MIN_SIZE <= 64
157-
if (size > 64 && size <= 96)
156+
if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
158157
return 1;
159-
if (size > 128 && size <= 192)
158+
if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
160159
return 2;
161-
#endif
162160
if (size <= 8) return 3;
163161
if (size <= 16) return 4;
164162
if (size <= 32) return 5;
@@ -304,6 +302,4 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
304302
}
305303
#endif
306304

307-
void __init kmem_cache_init_late(void);
308-
309305
#endif /* _LINUX_SLUB_DEF_H */

‎mm/slob.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,3 +692,8 @@ void __init kmem_cache_init(void)
692692
{
693693
slob_ready = 1;
694694
}
695+
696+
void __init kmem_cache_init_late(void)
697+
{
698+
/* Nothing to do */
699+
}

‎mm/slub.c‎

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
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

327334
static 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+
27932831
static 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

47274781
static 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
}
47324786
module_init(slab_proc_init);

0 commit comments

Comments
 (0)