SLUB: Simplify debugging Consolidate functionality into the #ifdef section. Signed-off-by: Christoph Lameter --- mm/slub.c | 87 +++++++++++++++++++++++++++----------------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) Index: slub/mm/slub.c =================================================================== --- slub.orig/mm/slub.c 2007-05-09 17:24:40.000000000 -0700 +++ slub/mm/slub.c 2007-05-09 17:33:54.000000000 -0700 @@ -746,6 +746,22 @@ static int on_freelist(struct kmem_cache return search == NULL; } +static void trace(struct kmem_cache *s, struct page *page, void *object, int alloc) +{ + if (s->flags & SLAB_TRACE) { + printk(KERN_INFO "TRACE %s %s 0x%p inuse=%d fp=0x%p\n", + s->name, + alloc ? "alloc" : "free", + object, page->inuse, + page->freelist); + + if (!alloc) + print_section("Object", (void *)object, s->objsize); + + dump_stack(); + } +} + /* * Tracking of fully allocated slabs for debugging purposes. */ @@ -771,7 +787,7 @@ static void remove_full(struct kmem_cach } static int alloc_object_checks(struct kmem_cache *s, struct page *page, - void *object) + void *object, void *addr) { if (!check_slab(s, page)) goto bad; @@ -786,13 +802,16 @@ static int alloc_object_checks(struct km goto bad; } - if (!object) - return 1; - - if (!check_object(s, page, object, 0)) + if (object && !check_object(s, page, object, 0)) goto bad; + /* Success perform special debug activities for allocs */ + if (s->flags & SLAB_STORE_USER) + set_track(s, object, TRACK_ALLOC, addr); + trace(s, page, object, 1); + init_object(s, object, 1); return 1; + bad: if (PageSlab(page)) { /* @@ -811,7 +830,7 @@ bad: } static int free_object_checks(struct kmem_cache *s, struct page *page, - void *object) + void *object, void *addr) { if (!check_slab(s, page)) goto fail; @@ -845,29 +864,22 @@ static int free_object_checks(struct kme "to slab %s", object, page->slab->name); goto fail; } + + /* Special debug activities for freeing objects */ + if (!SlabFrozen(page) && !page->freelist) + remove_full(s, page); + if (s->flags & SLAB_STORE_USER) + set_track(s, object, TRACK_FREE, addr); + trace(s, page, object, 0); + init_object(s, object, 0); return 1; + fail: printk(KERN_ERR "@@@ SLUB: %s slab 0x%p object at 0x%p not freed.\n", s->name, page, object); return 0; } -static void trace(struct kmem_cache *s, struct page *page, void *object, int alloc) -{ - if (s->flags & SLAB_TRACE) { - printk(KERN_INFO "TRACE %s %s 0x%p inuse=%d fp=0x%p\n", - s->name, - alloc ? "alloc" : "free", - object, page->inuse, - page->freelist); - - if (!alloc) - print_section("Object", (void *)object, s->objsize); - - dump_stack(); - } -} - static int __init setup_slub_debug(char *str) { if (!str || *str != '=') @@ -938,24 +950,15 @@ static void kmem_cache_open_debug_check( #else static inline int alloc_object_checks(struct kmem_cache *s, - struct page *page, void *object) { return 0; } + struct page *page, void *object, void *addr) { return 0; } static inline int free_object_checks(struct kmem_cache *s, - struct page *page, void *object) { return 0; } + struct page *page, void *object, void *addr) { return 0; } -static inline void add_full(struct kmem_cache_node *n, struct page *page) {} -static inline void remove_full(struct kmem_cache *s, struct page *page) {} -static inline void trace(struct kmem_cache *s, struct page *page, - void *object, int alloc) {} -static inline void init_object(struct kmem_cache *s, - void *object, int active) {} -static inline void init_tracking(struct kmem_cache *s, void *object) {} static inline int slab_pad_check(struct kmem_cache *s, struct page *page) { return 1; } static inline int check_object(struct kmem_cache *s, struct page *page, void *object, int active) { return 1; } -static inline void set_track(struct kmem_cache *s, void *object, - enum track_item alloc, void *addr) {} static inline void kmem_cache_open_debug_check(struct kmem_cache *s) {} #define slub_debug 0 #endif @@ -1456,12 +1457,8 @@ new_slab: return NULL; debug: object = page->freelist; - if (!alloc_object_checks(s, page, object)) + if (!alloc_object_checks(s, page, object, addr)) goto another_slab; - if (s->flags & SLAB_STORE_USER) - set_track(s, object, TRACK_ALLOC, addr); - trace(s, page, object, 1); - init_object(s, object, 1); page->inuse++; page->freelist = object[page->offset]; @@ -1568,14 +1565,8 @@ slab_empty: return; debug: - if (!free_object_checks(s, page, x)) + if (!free_object_checks(s, page, x, addr)) goto out_unlock; - if (!SlabFrozen(page) && !page->freelist) - remove_full(s, page); - if (s->flags & SLAB_STORE_USER) - set_track(s, x, TRACK_FREE, addr); - trace(s, page, object, 0); - init_object(s, object, 0); goto checks_ok; }