Skip to content

Commit

Permalink
lib/debugobjects: fix stat count and optimize debug_objects_mem_init
Browse files Browse the repository at this point in the history
[ Upstream commit eabb7f1 ]

1. Var debug_objects_allocated tracks valid kmem_cache_alloc calls, so
   track it in debug_objects_replace_static_objects.  Do similar things in
   object_cpu_offline.

2. In debug_objects_mem_init, there is no need to call function
   cpuhp_setup_state_nocalls when debug_objects_enabled = 0 (out of
   memory).

Link: https://lkml.kernel.org/r/20220611130634.99741-1-wuchi.zero@gmail.com
Fixes: 634d61f ("debugobjects: Percpu pool lookahead freeing/allocation")
Fixes: c4b73aa ("debugobjects: Track number of kmem_cache_alloc/kmem_cache_free done")
Signed-off-by: wuchi <wuchi.zero@gmail.com>
Reviewed-by: Waiman Long <longman@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ChiWu-Zero authored and gregkh committed Dec 31, 2022
1 parent e9b4dc1 commit 51b2ea9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/debugobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,20 @@ static int object_cpu_offline(unsigned int cpu)
struct debug_percpu_free *percpu_pool;
struct hlist_node *tmp;
struct debug_obj *obj;
unsigned long flags;

/* Remote access is safe as the CPU is dead already */
percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
hlist_del(&obj->node);
kmem_cache_free(obj_cache, obj);
}

raw_spin_lock_irqsave(&pool_lock, flags);
obj_pool_used -= percpu_pool->obj_free;
debug_objects_freed += percpu_pool->obj_free;
raw_spin_unlock_irqrestore(&pool_lock, flags);

percpu_pool->obj_free = 0;

return 0;
Expand Down Expand Up @@ -1318,6 +1325,8 @@ static int __init debug_objects_replace_static_objects(void)
hlist_add_head(&obj->node, &objects);
}

debug_objects_allocated += i;

/*
* debug_objects_mem_init() is now called early that only one CPU is up
* and interrupts have been disabled, so it is safe to replace the
Expand Down Expand Up @@ -1386,6 +1395,7 @@ void __init debug_objects_mem_init(void)
debug_objects_enabled = 0;
kmem_cache_destroy(obj_cache);
pr_warn("out of memory.\n");
return;
} else
debug_objects_selftest();

Expand Down

0 comments on commit 51b2ea9

Please sign in to comment.