History

debugobjects: Rename and tidy up per CPU pools

No point in having a separate data structure. Reuse struct obj_pool and tidy up the code.

Thomas Gleixner committed 2 years ago

Commit 18b8afc1 parent cb58d191 file · +17 −26Browse files

Unified · Split

lib/debugobjects.c+17−26
@@ -43,21 +43,12 @@ struct debug_bucket { · 42 unmodified lines
43 raw_spinlock_t lock;43 raw_spinlock_t lock;
44};44};
45 45
46/*
47 * Debug object percpu free list
48 * Access is protected by disabling irq
49 */
50struct debug_percpu_free {
51 struct hlist_head free_objs;
52 int obj_free;
53};
54
55struct obj_pool {46struct obj_pool {
56 struct hlist_head objects;47 struct hlist_head objects;
57 unsigned int cnt;48 unsigned int cnt;
58} ____cacheline_aligned;49} ____cacheline_aligned;
59 50
60static DEFINE_PER_CPU(struct debug_percpu_free, percpu_obj_pool);51static DEFINE_PER_CPU(struct obj_pool, pool_pcpu);
61 52
62static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE];53static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE];
63 54
@@ -271,13 +262,13 @@ static struct debug_obj *__alloc_object(struct hlist_head *list) · 207 unmodified lines
271static struct debug_obj *262static struct debug_obj *
272alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr)263alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr)
273{264{
274 struct debug_percpu_free *percpu_pool = this_cpu_ptr(&percpu_obj_pool);265 struct obj_pool *percpu_pool = this_cpu_ptr(&pool_pcpu);
275 struct debug_obj *obj;266 struct debug_obj *obj;
276 267
277 if (likely(obj_cache)) {268 if (likely(obj_cache)) {
278 obj = __alloc_object(&percpu_pool->free_objs);269 obj = __alloc_object(&percpu_pool->objects);
279 if (obj) {270 if (obj) {
280 percpu_pool->obj_free--;271 percpu_pool->cnt--;
281 goto init_obj;272 goto init_obj;
282 }273 }
283 } else {274 } else {
@@ -304,8 +295,8 @@ alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *d · 20 unmodified lines
304 obj2 = __alloc_object(&pool_global.objects);295 obj2 = __alloc_object(&pool_global.objects);
305 if (!obj2)296 if (!obj2)
306 break;297 break;
307 hlist_add_head(&obj2->node, &percpu_pool->free_objs);298 hlist_add_head(&obj2->node, &percpu_pool->objects);
308 percpu_pool->obj_free++;299 percpu_pool->cnt++;
309 obj_pool_used++;300 obj_pool_used++;
310 WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1);301 WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1);
311 }302 }
@@ -384,7 +375,7 @@ free_objs: · 72 unmodified lines
384static void __free_object(struct debug_obj *obj)375static void __free_object(struct debug_obj *obj)
385{376{
386 struct debug_obj *objs[ODEBUG_BATCH_SIZE];377 struct debug_obj *objs[ODEBUG_BATCH_SIZE];
387 struct debug_percpu_free *percpu_pool;378 struct obj_pool *percpu_pool;
388 int lookahead_count = 0;379 int lookahead_count = 0;
389 bool work;380 bool work;
390 381
@@ -398,10 +389,10 @@ static void __free_object(struct debug_obj *obj) · 7 unmodified lines
398 /*389 /*
399 * Try to free it into the percpu pool first.390 * Try to free it into the percpu pool first.
400 */391 */
401 percpu_pool = this_cpu_ptr(&percpu_obj_pool);392 percpu_pool = this_cpu_ptr(&pool_pcpu);
402 if (percpu_pool->obj_free < ODEBUG_POOL_PERCPU_SIZE) {393 if (percpu_pool->cnt < ODEBUG_POOL_PERCPU_SIZE) {
403 hlist_add_head(&obj->node, &percpu_pool->free_objs);394 hlist_add_head(&obj->node, &percpu_pool->objects);
404 percpu_pool->obj_free++;395 percpu_pool->cnt++;
405 return;396 return;
406 }397 }
407 398
@@ -410,10 +401,10 @@ static void __free_object(struct debug_obj *obj) · 2 unmodified lines
410 * of objects from the percpu pool and free them as well.401 * of objects from the percpu pool and free them as well.
411 */402 */
412 for (; lookahead_count < ODEBUG_BATCH_SIZE; lookahead_count++) {403 for (; lookahead_count < ODEBUG_BATCH_SIZE; lookahead_count++) {
413 objs[lookahead_count] = __alloc_object(&percpu_pool->free_objs);404 objs[lookahead_count] = __alloc_object(&percpu_pool->objects);
414 if (!objs[lookahead_count])405 if (!objs[lookahead_count])
415 break;406 break;
416 percpu_pool->obj_free--;407 percpu_pool->cnt--;
417 }408 }
418 409
419 raw_spin_lock(&pool_lock);410 raw_spin_lock(&pool_lock);
@@ -494,10 +485,10 @@ static void put_objects(struct hlist_head *list) · 74 unmodified lines
494static int object_cpu_offline(unsigned int cpu)485static int object_cpu_offline(unsigned int cpu)
495{486{
496 /* Remote access is safe as the CPU is dead already */487 /* Remote access is safe as the CPU is dead already */
497 struct debug_percpu_free *pcp = per_cpu_ptr(&percpu_obj_pool, cpu);488 struct obj_pool *pcp = per_cpu_ptr(&pool_pcpu, cpu);
498 489
499 put_objects(&pcp->free_objs);490 put_objects(&pcp->objects);
500 pcp->obj_free = 0;491 pcp->cnt = 0;
501 return 0;492 return 0;
502}493}
503#endif494#endif
@@ -1076,7 +1067,7 @@ static int debug_stats_show(struct seq_file *m, void *v) · 572 unmodified lines
1076 int cpu, obj_percpu_free = 0;1067 int cpu, obj_percpu_free = 0;
1077 1068
1078 for_each_possible_cpu(cpu)1069 for_each_possible_cpu(cpu)
1079 obj_percpu_free += per_cpu(percpu_obj_pool.obj_free, cpu);1070 obj_percpu_free += per_cpu(pool_pcpu.cnt, cpu);
1080 1071
1081 seq_printf(m, "max_chain :%d\n", debug_objects_maxchain);1072 seq_printf(m, "max_chain :%d\n", debug_objects_maxchain);
1082 seq_printf(m, "max_checked :%d\n", debug_objects_maxchecked);1073 seq_printf(m, "max_checked :%d\n", debug_objects_maxchecked);