No point in having a separate data structure. Reuse struct obj_pool and tidy up the code.
Showing the changes to lib/debugobjects.c (1 of 1 file). Show all
Unified · Split
| @@ -43,21 +43,12 @@ struct debug_bucket { · 42 unmodified lines | ||
| 43 | 43 | raw_spinlock_t lock; |
| 44 | 44 | }; |
| 45 | 45 | |
| 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 | − | |
| 55 | 46 | struct obj_pool { |
| 56 | 47 | struct hlist_head objects; |
| 57 | 48 | unsigned int cnt; |
| 58 | 49 | } ____cacheline_aligned; |
| 59 | 50 | |
| 60 | −static DEFINE_PER_CPU(struct debug_percpu_free, percpu_obj_pool); | |
| 51 | +static DEFINE_PER_CPU(struct obj_pool, pool_pcpu); | |
| 61 | 52 | |
| 62 | 53 | static 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 | ||
| 271 | 262 | static struct debug_obj * |
| 272 | 263 | alloc_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 | 266 | struct debug_obj *obj; |
| 276 | 267 | |
| 277 | 268 | if (likely(obj_cache)) { |
| 278 | − obj = __alloc_object(&percpu_pool->free_objs); | |
| 269 | + obj = __alloc_object(&percpu_pool->objects); | |
| 279 | 270 | if (obj) { |
| 280 | − percpu_pool->obj_free--; | |
| 271 | + percpu_pool->cnt--; | |
| 281 | 272 | goto init_obj; |
| 282 | 273 | } |
| 283 | 274 | } else { |
| @@ -304,8 +295,8 @@ alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *d · 20 unmodified lines | ||
| 304 | 295 | obj2 = __alloc_object(&pool_global.objects); |
| 305 | 296 | if (!obj2) |
| 306 | 297 | 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++; | |
| 309 | 300 | obj_pool_used++; |
| 310 | 301 | WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1); |
| 311 | 302 | } |
| @@ -384,7 +375,7 @@ free_objs: · 72 unmodified lines | ||
| 384 | 375 | static void __free_object(struct debug_obj *obj) |
| 385 | 376 | { |
| 386 | 377 | struct debug_obj *objs[ODEBUG_BATCH_SIZE]; |
| 387 | − struct debug_percpu_free *percpu_pool; | |
| 378 | + struct obj_pool *percpu_pool; | |
| 388 | 379 | int lookahead_count = 0; |
| 389 | 380 | bool work; |
| 390 | 381 | |
| @@ -398,10 +389,10 @@ static void __free_object(struct debug_obj *obj) · 7 unmodified lines | ||
| 398 | 389 | /* |
| 399 | 390 | * Try to free it into the percpu pool first. |
| 400 | 391 | */ |
| 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++; | |
| 405 | 396 | return; |
| 406 | 397 | } |
| 407 | 398 | |
| @@ -410,10 +401,10 @@ static void __free_object(struct debug_obj *obj) · 2 unmodified lines | ||
| 410 | 401 | * of objects from the percpu pool and free them as well. |
| 411 | 402 | */ |
| 412 | 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 | 405 | if (!objs[lookahead_count]) |
| 415 | 406 | break; |
| 416 | − percpu_pool->obj_free--; | |
| 407 | + percpu_pool->cnt--; | |
| 417 | 408 | } |
| 418 | 409 | |
| 419 | 410 | raw_spin_lock(&pool_lock); |
| @@ -494,10 +485,10 @@ static void put_objects(struct hlist_head *list) · 74 unmodified lines | ||
| 494 | 485 | static int object_cpu_offline(unsigned int cpu) |
| 495 | 486 | { |
| 496 | 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); | |
| 500 | − pcp->obj_free = 0; | |
| 490 | + put_objects(&pcp->objects); | |
| 491 | + pcp->cnt = 0; | |
| 501 | 492 | return 0; |
| 502 | 493 | } |
| 503 | 494 | #endif |
| @@ -1076,7 +1067,7 @@ static int debug_stats_show(struct seq_file *m, void *v) · 572 unmodified lines | ||
| 1076 | 1067 | int cpu, obj_percpu_free = 0; |
| 1077 | 1068 | |
| 1078 | 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 | 1072 | seq_printf(m, "max_chain :%d\n", debug_objects_maxchain); |
| 1082 | 1073 | seq_printf(m, "max_checked :%d\n", debug_objects_maxchecked); |