Skip to content

Commit 18b8afc

Browse files
committed
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. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Zhen Lei <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent cb58d19 commit 18b8afc

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

lib/debugobjects.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,12 @@ struct debug_bucket {
4343
raw_spinlock_t lock;
4444
};
4545

46-
/*
47-
* Debug object percpu free list
48-
* Access is protected by disabling irq
49-
*/
50-
struct debug_percpu_free {
51-
struct hlist_head free_objs;
52-
int obj_free;
53-
};
54-
5546
struct obj_pool {
5647
struct hlist_head objects;
5748
unsigned int cnt;
5849
} ____cacheline_aligned;
5950

60-
static DEFINE_PER_CPU(struct debug_percpu_free, percpu_obj_pool);
51+
static DEFINE_PER_CPU(struct obj_pool, pool_pcpu);
6152

6253
static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE];
6354

@@ -271,13 +262,13 @@ static struct debug_obj *__alloc_object(struct hlist_head *list)
271262
static struct debug_obj *
272263
alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr)
273264
{
274-
struct debug_percpu_free *percpu_pool = this_cpu_ptr(&percpu_obj_pool);
265+
struct obj_pool *percpu_pool = this_cpu_ptr(&pool_pcpu);
275266
struct debug_obj *obj;
276267

277268
if (likely(obj_cache)) {
278-
obj = __alloc_object(&percpu_pool->free_objs);
269+
obj = __alloc_object(&percpu_pool->objects);
279270
if (obj) {
280-
percpu_pool->obj_free--;
271+
percpu_pool->cnt--;
281272
goto init_obj;
282273
}
283274
} else {
@@ -304,8 +295,8 @@ alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *d
304295
obj2 = __alloc_object(&pool_global.objects);
305296
if (!obj2)
306297
break;
307-
hlist_add_head(&obj2->node, &percpu_pool->free_objs);
308-
percpu_pool->obj_free++;
298+
hlist_add_head(&obj2->node, &percpu_pool->objects);
299+
percpu_pool->cnt++;
309300
obj_pool_used++;
310301
WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1);
311302
}
@@ -384,7 +375,7 @@ static void free_obj_work(struct work_struct *work)
384375
static void __free_object(struct debug_obj *obj)
385376
{
386377
struct debug_obj *objs[ODEBUG_BATCH_SIZE];
387-
struct debug_percpu_free *percpu_pool;
378+
struct obj_pool *percpu_pool;
388379
int lookahead_count = 0;
389380
bool work;
390381

@@ -398,10 +389,10 @@ static void __free_object(struct debug_obj *obj)
398389
/*
399390
* Try to free it into the percpu pool first.
400391
*/
401-
percpu_pool = this_cpu_ptr(&percpu_obj_pool);
402-
if (percpu_pool->obj_free < ODEBUG_POOL_PERCPU_SIZE) {
403-
hlist_add_head(&obj->node, &percpu_pool->free_objs);
404-
percpu_pool->obj_free++;
392+
percpu_pool = this_cpu_ptr(&pool_pcpu);
393+
if (percpu_pool->cnt < ODEBUG_POOL_PERCPU_SIZE) {
394+
hlist_add_head(&obj->node, &percpu_pool->objects);
395+
percpu_pool->cnt++;
405396
return;
406397
}
407398

@@ -410,10 +401,10 @@ static void __free_object(struct debug_obj *obj)
410401
* of objects from the percpu pool and free them as well.
411402
*/
412403
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);
414405
if (!objs[lookahead_count])
415406
break;
416-
percpu_pool->obj_free--;
407+
percpu_pool->cnt--;
417408
}
418409

419410
raw_spin_lock(&pool_lock);
@@ -494,10 +485,10 @@ static void put_objects(struct hlist_head *list)
494485
static int object_cpu_offline(unsigned int cpu)
495486
{
496487
/* 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);
498489

499-
put_objects(&pcp->free_objs);
500-
pcp->obj_free = 0;
490+
put_objects(&pcp->objects);
491+
pcp->cnt = 0;
501492
return 0;
502493
}
503494
#endif
@@ -1076,7 +1067,7 @@ static int debug_stats_show(struct seq_file *m, void *v)
10761067
int cpu, obj_percpu_free = 0;
10771068

10781069
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);
10801071

10811072
seq_printf(m, "max_chain :%d\n", debug_objects_maxchain);
10821073
seq_printf(m, "max_checked :%d\n", debug_objects_maxchecked);

0 commit comments

Comments
 (0)