Commit ba0268a8 authored by Christoph Lameter's avatar Christoph Lameter Committed by Linus Torvalds

SLUB: accurately compare debug flags during slab cache merge

This was posted on Aug 28 and fixes an issue that could cause troubles
when slab caches >=128k are created.

http://marc.info/?l=linux-mm&m=118798149918424&w=2

Currently we simply add the debug flags unconditional when checking for a
matching slab.  This creates issues for sysfs processing when slabs exist
that are exempt from debugging due to their huge size or because only a
subset of slabs was selected for debugging.

We need to only add the flags if kmem_cache_open() would also add them.

Create a function to calculate the flags that would be set
if the cache would be opened and use that function to determine
the flags before looking for a compatible slab.

[akpm@linux-foundation.org: fixlets]
Signed-off-by: default avatarChristoph Lameter <clameter@sgi.com>
Cc: Chuck Ebbert <cebbert@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4150d3f5
...@@ -986,7 +986,9 @@ static int __init setup_slub_debug(char *str) ...@@ -986,7 +986,9 @@ static int __init setup_slub_debug(char *str)
__setup("slub_debug", setup_slub_debug); __setup("slub_debug", setup_slub_debug);
static void kmem_cache_open_debug_check(struct kmem_cache *s) static unsigned long kmem_cache_flags(unsigned long objsize,
unsigned long flags, const char *name,
void (*ctor)(void *, struct kmem_cache *, unsigned long))
{ {
/* /*
* The page->offset field is only 16 bit wide. This is an offset * The page->offset field is only 16 bit wide. This is an offset
...@@ -1000,19 +1002,21 @@ static void kmem_cache_open_debug_check(struct kmem_cache *s) ...@@ -1000,19 +1002,21 @@ static void kmem_cache_open_debug_check(struct kmem_cache *s)
* Debugging or ctor may create a need to move the free * Debugging or ctor may create a need to move the free
* pointer. Fail if this happens. * pointer. Fail if this happens.
*/ */
if (s->objsize >= 65535 * sizeof(void *)) { if (objsize >= 65535 * sizeof(void *)) {
BUG_ON(s->flags & (SLAB_RED_ZONE | SLAB_POISON | BUG_ON(flags & (SLAB_RED_ZONE | SLAB_POISON |
SLAB_STORE_USER | SLAB_DESTROY_BY_RCU)); SLAB_STORE_USER | SLAB_DESTROY_BY_RCU));
BUG_ON(s->ctor); BUG_ON(ctor);
} } else {
else
/* /*
* Enable debugging if selected on the kernel commandline. * Enable debugging if selected on the kernel commandline.
*/ */
if (slub_debug && (!slub_debug_slabs || if (slub_debug && (!slub_debug_slabs ||
strncmp(slub_debug_slabs, s->name, strncmp(slub_debug_slabs, name,
strlen(slub_debug_slabs)) == 0)) strlen(slub_debug_slabs)) == 0))
s->flags |= slub_debug; flags |= slub_debug;
}
return flags;
} }
#else #else
static inline void setup_object_debug(struct kmem_cache *s, static inline void setup_object_debug(struct kmem_cache *s,
...@@ -1029,7 +1033,12 @@ static inline int slab_pad_check(struct kmem_cache *s, struct page *page) ...@@ -1029,7 +1033,12 @@ static inline int slab_pad_check(struct kmem_cache *s, struct page *page)
static inline int check_object(struct kmem_cache *s, struct page *page, static inline int check_object(struct kmem_cache *s, struct page *page,
void *object, int active) { return 1; } void *object, int active) { return 1; }
static inline void add_full(struct kmem_cache_node *n, struct page *page) {} static inline void add_full(struct kmem_cache_node *n, struct page *page) {}
static inline void kmem_cache_open_debug_check(struct kmem_cache *s) {} static inline unsigned long kmem_cache_flags(unsigned long objsize,
unsigned long flags, const char *name,
void (*ctor)(void *, struct kmem_cache *, unsigned long))
{
return flags;
}
#define slub_debug 0 #define slub_debug 0
#endif #endif
/* /*
...@@ -2088,9 +2097,8 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags, ...@@ -2088,9 +2097,8 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
s->name = name; s->name = name;
s->ctor = ctor; s->ctor = ctor;
s->objsize = size; s->objsize = size;
s->flags = flags;
s->align = align; s->align = align;
kmem_cache_open_debug_check(s); s->flags = kmem_cache_flags(size, flags, name, ctor);
if (!calculate_sizes(s)) if (!calculate_sizes(s))
goto error; goto error;
...@@ -2660,7 +2668,7 @@ static int slab_unmergeable(struct kmem_cache *s) ...@@ -2660,7 +2668,7 @@ static int slab_unmergeable(struct kmem_cache *s)
} }
static struct kmem_cache *find_mergeable(size_t size, static struct kmem_cache *find_mergeable(size_t size,
size_t align, unsigned long flags, size_t align, unsigned long flags, const char *name,
void (*ctor)(void *, struct kmem_cache *, unsigned long)) void (*ctor)(void *, struct kmem_cache *, unsigned long))
{ {
struct kmem_cache *s; struct kmem_cache *s;
...@@ -2674,6 +2682,7 @@ static struct kmem_cache *find_mergeable(size_t size, ...@@ -2674,6 +2682,7 @@ static struct kmem_cache *find_mergeable(size_t size,
size = ALIGN(size, sizeof(void *)); size = ALIGN(size, sizeof(void *));
align = calculate_alignment(flags, align, size); align = calculate_alignment(flags, align, size);
size = ALIGN(size, align); size = ALIGN(size, align);
flags = kmem_cache_flags(size, flags, name, NULL);
list_for_each_entry(s, &slab_caches, list) { list_for_each_entry(s, &slab_caches, list) {
if (slab_unmergeable(s)) if (slab_unmergeable(s))
...@@ -2682,8 +2691,7 @@ static struct kmem_cache *find_mergeable(size_t size, ...@@ -2682,8 +2691,7 @@ static struct kmem_cache *find_mergeable(size_t size,
if (size > s->size) if (size > s->size)
continue; continue;
if (((flags | slub_debug) & SLUB_MERGE_SAME) != if ((flags & SLUB_MERGE_SAME) != (s->flags & SLUB_MERGE_SAME))
(s->flags & SLUB_MERGE_SAME))
continue; continue;
/* /*
* Check if alignment is compatible. * Check if alignment is compatible.
...@@ -2707,7 +2715,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, ...@@ -2707,7 +2715,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
struct kmem_cache *s; struct kmem_cache *s;
down_write(&slub_lock); down_write(&slub_lock);
s = find_mergeable(size, align, flags, ctor); s = find_mergeable(size, align, flags, name, ctor);
if (s) { if (s) {
s->refcount++; s->refcount++;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment