Skip to content

Commit 63a4a9b

Browse files
Zhen LeiKAGA-KOKO
authored andcommitted
debugobjects: Remove redundant checks in fill_pool()
fill_pool() checks locklessly at the beginning whether the pool has to be refilled. After that it checks locklessly in a loop whether the free list contains objects and repeats the refill check. If both conditions are true, it acquires the pool lock and tries to move objects from the free list to the pool repeating the same checks again. There are two redundant issues with that: 1) The repeated check for the fill condition 2) The loop processing The repeated check is pointless as it was just established that fill is required. The condition has to be re-evaluated under the lock anyway. The loop processing is not required either because there is practically zero chance that a repeated attempt will succeed if the checks under the lock terminate the moving of objects. Remove the redundant check and replace the loop with a simple if condition. [ tglx: Massaged change log ] Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20240904133944.2124-4-thunder.leizhen@huawei.com
1 parent 684d28f commit 63a4a9b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/debugobjects.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,13 @@ static void fill_pool(void)
135135
return;
136136

137137
/*
138-
* Reuse objs from the global free list; they will be reinitialized
139-
* when allocating.
138+
* Reuse objs from the global obj_to_free list; they will be
139+
* reinitialized when allocating.
140140
*
141-
* Both obj_nr_tofree and obj_pool_free are checked locklessly; the
142-
* READ_ONCE()s pair with the WRITE_ONCE()s in pool_lock critical
143-
* sections.
141+
* obj_nr_tofree is checked locklessly; the READ_ONCE() pairs with
142+
* the WRITE_ONCE() in pool_lock critical sections.
144143
*/
145-
while (READ_ONCE(obj_nr_tofree) &&
146-
READ_ONCE(obj_pool_free) < debug_objects_pool_min_level) {
144+
if (READ_ONCE(obj_nr_tofree)) {
147145
raw_spin_lock_irqsave(&pool_lock, flags);
148146
/*
149147
* Recheck with the lock held as the worker thread might have

0 commit comments

Comments
 (0)