Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 140511
b: refs/heads/master
c: 1be1cb7
h: refs/heads/master
i:
  140509: d18af08
  140507: dad9cb5
  140503: 3463168
  140495: bcaeadf
  140479: 91a9e13
v: v3
  • Loading branch information
Thomas Gleixner committed Mar 17, 2009
1 parent 5b32edd commit 56ddcb7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3e8ebb5c433f016dff5824587436642d87fc2e6c
refs/heads/master: 1be1cb7b47f0744141ed61cdb25648819ae1a56f
66 changes: 63 additions & 3 deletions trunk/lib/debugobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct debug_bucket {

static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE];

static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE];
static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE] __initdata;

static DEFINE_SPINLOCK(pool_lock);

Expand Down Expand Up @@ -883,6 +883,63 @@ void __init debug_objects_early_init(void)
hlist_add_head(&obj_static_pool[i].node, &obj_pool);
}

/*
* Convert the statically allocated objects to dynamic ones:
*/
static int debug_objects_replace_static_objects(void)
{
struct debug_bucket *db = obj_hash;
struct hlist_node *node, *tmp;
struct debug_obj *obj, *new;
HLIST_HEAD(objects);
int i, cnt = 0;

for (i = 0; i < ODEBUG_POOL_SIZE; i++) {
obj = kmem_cache_zalloc(obj_cache, GFP_KERNEL);
if (!obj)
goto free;
hlist_add_head(&obj->node, &objects);
}

/*
* When debug_objects_mem_init() is called we know that only
* one CPU is up, so disabling interrupts is enough
* protection. This avoids the lockdep hell of lock ordering.
*/
local_irq_disable();

/* Remove the statically allocated objects from the pool */
hlist_for_each_entry_safe(obj, node, tmp, &obj_pool, node)
hlist_del(&obj->node);
/* Move the allocated objects to the pool */
hlist_move_list(&objects, &obj_pool);

/* Replace the active object references */
for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) {
hlist_move_list(&db->list, &objects);

hlist_for_each_entry(obj, node, &objects, node) {
new = hlist_entry(obj_pool.first, typeof(*obj), node);
hlist_del(&new->node);
/* copy object data */
*new = *obj;
hlist_add_head(&new->node, &db->list);
cnt++;
}
}

printk(KERN_DEBUG "ODEBUG: %d of %d active objects replaced\n", cnt,
obj_pool_used);
local_irq_enable();
return 0;
free:
hlist_for_each_entry_safe(obj, node, tmp, &objects, node) {
hlist_del(&obj->node);
kmem_cache_free(obj_cache, obj);
}
return -ENOMEM;
}

/*
* Called after the kmem_caches are functional to setup a dedicated
* cache pool, which has the SLAB_DEBUG_OBJECTS flag set. This flag
Expand All @@ -898,8 +955,11 @@ void __init debug_objects_mem_init(void)
sizeof (struct debug_obj), 0,
SLAB_DEBUG_OBJECTS, NULL);

if (!obj_cache)
if (!obj_cache || debug_objects_replace_static_objects()) {
debug_objects_enabled = 0;
else
if (obj_cache)
kmem_cache_destroy(obj_cache);
printk(KERN_WARNING "ODEBUG: out of memory.\n");
} else
debug_objects_selftest();
}

0 comments on commit 56ddcb7

Please sign in to comment.