Skip to content

Commit 813fd07

Browse files
Zhen LeiKAGA-KOKO
authored andcommitted
debugobjects: Collect newly allocated objects in a list to reduce lock contention
Collect the newly allocated debug objects in a list outside the lock, so that the lock held time and the potential lock contention is reduced. Signed-off-by: Zhen Lei <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/[email protected] Link: https://lore.kernel.org/all/[email protected]
1 parent a0ae950 commit 813fd07

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/debugobjects.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,25 @@ static void fill_pool(void)
161161
return;
162162

163163
while (READ_ONCE(obj_pool_free) < debug_objects_pool_min_level) {
164-
struct debug_obj *new[ODEBUG_BATCH_SIZE];
164+
struct debug_obj *new, *last = NULL;
165+
HLIST_HEAD(head);
165166
int cnt;
166167

167168
for (cnt = 0; cnt < ODEBUG_BATCH_SIZE; cnt++) {
168-
new[cnt] = kmem_cache_zalloc(obj_cache, gfp);
169-
if (!new[cnt])
169+
new = kmem_cache_zalloc(obj_cache, gfp);
170+
if (!new)
170171
break;
172+
hlist_add_head(&new->node, &head);
173+
if (!last)
174+
last = new;
171175
}
172176
if (!cnt)
173177
return;
174178

175179
raw_spin_lock_irqsave(&pool_lock, flags);
176-
while (cnt) {
177-
hlist_add_head(&new[--cnt]->node, &obj_pool);
178-
debug_objects_allocated++;
179-
WRITE_ONCE(obj_pool_free, obj_pool_free + 1);
180-
}
180+
hlist_splice_init(&head, &last->node, &obj_pool);
181+
debug_objects_allocated += cnt;
182+
WRITE_ONCE(obj_pool_free, obj_pool_free + cnt);
181183
raw_spin_unlock_irqrestore(&pool_lock, flags);
182184
}
183185
}

0 commit comments

Comments
 (0)