Skip to content

Commit 88451f2

Browse files
Zqiang1211KAGA-KOKO
authored andcommitted
debugobjects: Free per CPU pool after CPU unplug
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
1 parent f9e62f3 commit 88451f2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

include/linux/cpuhotplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum cpuhp_state {
3636
CPUHP_X86_MCE_DEAD,
3737
CPUHP_VIRT_NET_DEAD,
3838
CPUHP_SLUB_DEAD,
39+
CPUHP_DEBUG_OBJ_DEAD,
3940
CPUHP_MM_WRITEBACK_DEAD,
4041
CPUHP_MM_VMSTAT_DEAD,
4142
CPUHP_SOFTIRQ_DEAD,

lib/debugobjects.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/slab.h>
2020
#include <linux/hash.h>
2121
#include <linux/kmemleak.h>
22+
#include <linux/cpu.h>
2223

2324
#define ODEBUG_HASH_BITS 14
2425
#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
@@ -433,6 +434,25 @@ static void free_object(struct debug_obj *obj)
433434
}
434435
}
435436

437+
#ifdef CONFIG_HOTPLUG_CPU
438+
static int object_cpu_offline(unsigned int cpu)
439+
{
440+
struct debug_percpu_free *percpu_pool;
441+
struct hlist_node *tmp;
442+
struct debug_obj *obj;
443+
444+
/* Remote access is safe as the CPU is dead already */
445+
percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
446+
hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
447+
hlist_del(&obj->node);
448+
kmem_cache_free(obj_cache, obj);
449+
}
450+
percpu_pool->obj_free = 0;
451+
452+
return 0;
453+
}
454+
#endif
455+
436456
/*
437457
* We run out of memory. That means we probably have tons of objects
438458
* allocated.
@@ -1367,6 +1387,11 @@ void __init debug_objects_mem_init(void)
13671387
} else
13681388
debug_objects_selftest();
13691389

1390+
#ifdef CONFIG_HOTPLUG_CPU
1391+
cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
1392+
object_cpu_offline);
1393+
#endif
1394+
13701395
/*
13711396
* Increase the thresholds for allocating and freeing objects
13721397
* according to the number of possible CPUs available in the system.

0 commit comments

Comments
 (0)