History

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 ]

Zqiang committed 6 years ago

Commit 88451f21 parent f9e62f32 files · +26 −0Browse files

Showing the changes to lib/debugobjects.c (1 of 2 files). Show all

Unified · Split

lib/debugobjects.c+25−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
19#include <linux/slab.h>19#include <linux/slab.h>
20#include <linux/hash.h>20#include <linux/hash.h>
21#include <linux/kmemleak.h>21#include <linux/kmemleak.h>
22#include <linux/cpu.h>
22 23
23#define ODEBUG_HASH_BITS 1424#define ODEBUG_HASH_BITS 14
24#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)25#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
@@ -433,6 +434,25 @@ static void free_object(struct debug_obj *obj) · 408 unmodified lines
433 }434 }
434}435}
435 436
437#ifdef CONFIG_HOTPLUG_CPU
438static 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
436/*456/*
437 * We run out of memory. That means we probably have tons of objects457 * We run out of memory. That means we probably have tons of objects
438 * allocated.458 * allocated.
@@ -1367,6 +1387,11 @@ void __init debug_objects_mem_init(void) · 928 unmodified lines
1367 } else1387 } else
1368 debug_objects_selftest();1388 debug_objects_selftest();
1369 1389
1390#ifdef CONFIG_HOTPLUG_CPU
1391 cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
1392 object_cpu_offline);
1393#endif
1394
1370 /*1395 /*
1371 * Increase the thresholds for allocating and freeing objects1396 * Increase the thresholds for allocating and freeing objects
1372 * according to the number of possible CPUs available in the system.1397 * according to the number of possible CPUs available in the system.