Skip to content

Commit

Permalink
debugobjects: Free per CPU pool after CPU unplug
Browse files Browse the repository at this point in the history
If a CPU is offlined the debug objects per CPU pool is not cleaned up. If
the CPU is never onlined again then the objects in the pool are wasted.

Add a CPU hotplug callback which is invoked after the CPU is dead to free
the pool.

[ tglx: Massaged changelog and added comment about remote access safety ]

Signed-off-by: Zqiang <qiang.zhang@windriver.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <longman@redhat.com>
Link: https://lore.kernel.org/r/20200908062709.11441-1-qiang.zhang@windriver.com
  • Loading branch information
Zqiang authored and Thomas Gleixner committed Oct 1, 2020
1 parent f9e62f3 commit 88451f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/cpuhotplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum cpuhp_state {
CPUHP_X86_MCE_DEAD,
CPUHP_VIRT_NET_DEAD,
CPUHP_SLUB_DEAD,
CPUHP_DEBUG_OBJ_DEAD,
CPUHP_MM_WRITEBACK_DEAD,
CPUHP_MM_VMSTAT_DEAD,
CPUHP_SOFTIRQ_DEAD,
Expand Down
25 changes: 25 additions & 0 deletions lib/debugobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/slab.h>
#include <linux/hash.h>
#include <linux/kmemleak.h>
#include <linux/cpu.h>

#define ODEBUG_HASH_BITS 14
#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
Expand Down Expand Up @@ -433,6 +434,25 @@ static void free_object(struct debug_obj *obj)
}
}

#ifdef CONFIG_HOTPLUG_CPU
static int object_cpu_offline(unsigned int cpu)
{
struct debug_percpu_free *percpu_pool;
struct hlist_node *tmp;
struct debug_obj *obj;

/* 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);
}
percpu_pool->obj_free = 0;

return 0;
}
#endif

/*
* We run out of memory. That means we probably have tons of objects
* allocated.
Expand Down Expand Up @@ -1367,6 +1387,11 @@ void __init debug_objects_mem_init(void)
} else
debug_objects_selftest();

#ifdef CONFIG_HOTPLUG_CPU
cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
object_cpu_offline);
#endif

/*
* Increase the thresholds for allocating and freeing objects
* according to the number of possible CPUs available in the system.
Expand Down

0 comments on commit 88451f2

Please sign in to comment.