Skip to content

Commit d1534ae

Browse files
Waiman-Longakpm00
authored andcommitted
mm/kmemleak: avoid soft lockup in __kmemleak_do_cleanup()
A soft lockup warning was observed on a relative small system x86-64 system with 16 GB of memory when running a debug kernel with kmemleak enabled. watchdog: BUG: soft lockup - CPU#8 stuck for 33s! [kworker/8:1:134] The test system was running a workload with hot unplug happening in parallel. Then kemleak decided to disable itself due to its inability to allocate more kmemleak objects. The debug kernel has its CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE set to 40,000. The soft lockup happened in kmemleak_do_cleanup() when the existing kmemleak objects were being removed and deleted one-by-one in a loop via a workqueue. In this particular case, there are at least 40,000 objects that need to be processed and given the slowness of a debug kernel and the fact that a raw_spinlock has to be acquired and released in __delete_object(), it could take a while to properly handle all these objects. As kmemleak has been disabled in this case, the object removal and deletion process can be further optimized as locking isn't really needed. However, it is probably not worth the effort to optimize for such an edge case that should rarely happen. So the simple solution is to call cond_resched() at periodic interval in the iteration loop to avoid soft lockup. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Waiman Long <[email protected]> Acked-by: Catalin Marinas <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5a309db commit d1534ae

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mm/kmemleak.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,7 @@ static const struct file_operations kmemleak_fops = {
21842184
static void __kmemleak_do_cleanup(void)
21852185
{
21862186
struct kmemleak_object *object, *tmp;
2187+
unsigned int cnt = 0;
21872188

21882189
/*
21892190
* Kmemleak has already been disabled, no need for RCU list traversal
@@ -2192,6 +2193,10 @@ static void __kmemleak_do_cleanup(void)
21922193
list_for_each_entry_safe(object, tmp, &object_list, object_list) {
21932194
__remove_object(object);
21942195
__delete_object(object);
2196+
2197+
/* Call cond_resched() once per 64 iterations to avoid soft lockup */
2198+
if (!(++cnt & 0x3f))
2199+
cond_resched();
21952200
}
21962201
}
21972202

0 commit comments

Comments
 (0)