Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

debugobjects: Rework object freeing

__free_object() is uncomprehensibly complex. The same can be achieved by:

1) Adding the object to the per CPU pool

2) If that pool is full, move a batch of objects into the global pool
or if the global pool is full into the to free pool

This also prepares for batch processing.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/all/20241007164913.955542307@linutronix.de

+24 -75
+24 -75
lib/debugobjects.c
··· 199 199 } 200 200 } 201 201 202 + static void pcpu_free(struct debug_obj *obj) 203 + { 204 + struct obj_pool *pcp = this_cpu_ptr(&pool_pcpu); 205 + 206 + lockdep_assert_irqs_disabled(); 207 + 208 + hlist_add_head(&obj->node, &pcp->objects); 209 + pcp->cnt++; 210 + 211 + /* Pool full ? */ 212 + if (pcp->cnt < ODEBUG_POOL_PERCPU_SIZE) 213 + return; 214 + 215 + /* Remove a batch from the per CPU pool */ 216 + guard(raw_spinlock)(&pool_lock); 217 + /* Try to fit the batch into the pool_global first */ 218 + if (!pool_move_batch(&pool_global, pcp)) 219 + pool_move_batch(&pool_to_free, pcp); 220 + obj_pool_used -= ODEBUG_BATCH_SIZE; 221 + } 222 + 202 223 static void free_object_list(struct hlist_head *head) 203 224 { 204 225 struct hlist_node *tmp; ··· 396 375 397 376 static void __free_object(struct debug_obj *obj) 398 377 { 399 - struct debug_obj *objs[ODEBUG_BATCH_SIZE]; 400 - struct obj_pool *percpu_pool; 401 - int lookahead_count = 0; 402 - bool work; 403 - 404 378 guard(irqsave)(); 405 - 406 - if (unlikely(!obj_cache)) { 379 + if (likely(obj_cache)) 380 + pcpu_free(obj); 381 + else 407 382 hlist_add_head(&obj->node, &pool_boot); 408 - return; 409 - } 410 - 411 - /* 412 - * Try to free it into the percpu pool first. 413 - */ 414 - percpu_pool = this_cpu_ptr(&pool_pcpu); 415 - if (percpu_pool->cnt < ODEBUG_POOL_PERCPU_SIZE) { 416 - hlist_add_head(&obj->node, &percpu_pool->objects); 417 - percpu_pool->cnt++; 418 - return; 419 - } 420 - 421 - /* 422 - * As the percpu pool is full, look ahead and pull out a batch 423 - * of objects from the percpu pool and free them as well. 424 - */ 425 - for (; lookahead_count < ODEBUG_BATCH_SIZE; lookahead_count++) { 426 - objs[lookahead_count] = __alloc_object(&percpu_pool->objects); 427 - if (!objs[lookahead_count]) 428 - break; 429 - percpu_pool->cnt--; 430 - } 431 - 432 - raw_spin_lock(&pool_lock); 433 - work = (pool_global.cnt > pool_global.max_cnt) && obj_cache && 434 - (pool_to_free.cnt < ODEBUG_FREE_WORK_MAX); 435 - obj_pool_used--; 436 - 437 - if (work) { 438 - WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt + 1); 439 - hlist_add_head(&obj->node, &pool_to_free.objects); 440 - if (lookahead_count) { 441 - WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt + lookahead_count); 442 - obj_pool_used -= lookahead_count; 443 - while (lookahead_count) { 444 - hlist_add_head(&objs[--lookahead_count]->node, 445 - &pool_to_free.objects); 446 - } 447 - } 448 - 449 - if ((pool_global.cnt > pool_global.max_cnt) && 450 - (pool_to_free.cnt < ODEBUG_FREE_WORK_MAX)) { 451 - int i; 452 - 453 - /* 454 - * Free one more batch of objects from obj_pool. 455 - */ 456 - for (i = 0; i < ODEBUG_BATCH_SIZE; i++) { 457 - obj = __alloc_object(&pool_global.objects); 458 - hlist_add_head(&obj->node, &pool_to_free.objects); 459 - WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1); 460 - WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt + 1); 461 - } 462 - } 463 - } else { 464 - WRITE_ONCE(pool_global.cnt, pool_global.cnt + 1); 465 - hlist_add_head(&obj->node, &pool_global.objects); 466 - if (lookahead_count) { 467 - WRITE_ONCE(pool_global.cnt, pool_global.cnt + lookahead_count); 468 - obj_pool_used -= lookahead_count; 469 - while (lookahead_count) { 470 - hlist_add_head(&objs[--lookahead_count]->node, 471 - &pool_global.objects); 472 - } 473 - } 474 - } 475 - raw_spin_unlock(&pool_lock); 476 383 } 477 384 478 385 /*