When the pool list is already full, just put the free objects on the global free list, then schedule a work to move them to pool list or free the memory later.
If the pool list is not full, just put the objects back to the pool list. Signed-off-by: Yang Shi <[email protected]> Suggested-by: Thomas Gleixner <[email protected]> Cc: Waiman Long <[email protected]> --- lib/debugobjects.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index c15fb5f..09f2469 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -266,27 +266,34 @@ static void free_obj_work(struct work_struct *work) } } -/* - * Put the object back into the pool and schedule work to free objects - * if necessary. - */ -static void free_object(struct debug_obj *obj) +static bool __free_object(struct debug_obj *obj) { unsigned long flags; - int sched = 0; + bool work; raw_spin_lock_irqsave(&pool_lock, flags); - /* - * schedule work when the pool is filled and the cache is - * initialized: - */ - if (obj_pool_free > debug_objects_pool_size && obj_cache) - sched = 1; - hlist_add_head(&obj->node, &obj_pool); - obj_pool_free++; + work = (obj_pool_free > debug_objects_pool_size) && obj_cache ? + true : false; obj_pool_used--; + + if (work) { + obj_nr_tofree++; + hlist_add_head(&obj->node, &obj_to_free); + } else { + obj_pool_free++; + hlist_add_head(&obj->node, &obj_pool); + } raw_spin_unlock_irqrestore(&pool_lock, flags); - if (sched) + return work; +} + +/* + * Put the object back into the pool and schedule work to free objects + * if necessary. + */ +static void free_object(struct debug_obj *obj) +{ + if (__free_object(obj)) schedule_work(&debug_obj_work); } -- 1.8.3.1

