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: 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 <thunder.leizhen@huawei.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240911083521.2257-3-thunder.leizhen@huawei.com
Link: https://lore.kernel.org/all/20241007164913.073653668@linutronix.de


authored by

Zhen Lei and committed by
Thomas Gleixner
813fd078 a0ae9504

+10 -8
+10 -8
lib/debugobjects.c
··· 161 161 return; 162 162 163 163 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); 165 166 int cnt; 166 167 167 168 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) 170 171 break; 172 + hlist_add_head(&new->node, &head); 173 + if (!last) 174 + last = new; 171 175 } 172 176 if (!cnt) 173 177 return; 174 178 175 179 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); 181 183 raw_spin_unlock_irqrestore(&pool_lock, flags); 182 184 } 183 185 }