Skip to content

Commit c4b2896

Browse files
Davidlohr Buesotorvalds
authored andcommitted
mm/kmemleak: rely on rcu for task stack scanning
kmemleak_scan() currently relies on the big tasklist_lock hammer to stabilize iterating through the tasklist. Instead, this patch proposes simply using rcu along with the rcu-safe for_each_process_thread flavor (without changing scan semantics), which doesn't make use of next_thread/p->thread_group and thus cannot race with exit. Furthermore, any races with fork() and not seeing the new child should be benign as it's not running yet and can also be detected by the next scan. Avoiding the tasklist_lock could prove beneficial for performance considering the scan operation is done periodically. I have seen improvements of 30%-ish when doing similar replacements on very pathological microbenchmarks (ie stressing get/setpriority(2)). However my main motivation is that it's one less user of the global lock, something that Linus has long time wanted to see gone eventually (if ever) even if the traditional fairness issues has been dealt with now with qrwlocks. Of course this is a very long ways ahead. This patch also kills another user of the deprecated tsk->thread_group. Signed-off-by: Davidlohr Bueso <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Qian Cai <[email protected]> Acked-by: Catalin Marinas <[email protected]> Acked-by: Oleg Nesterov <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9cf7a11 commit c4b2896

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mm/kmemleak.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,15 +1471,15 @@ static void kmemleak_scan(void)
14711471
if (kmemleak_stack_scan) {
14721472
struct task_struct *p, *g;
14731473

1474-
read_lock(&tasklist_lock);
1475-
do_each_thread(g, p) {
1474+
rcu_read_lock();
1475+
for_each_process_thread(g, p) {
14761476
void *stack = try_get_task_stack(p);
14771477
if (stack) {
14781478
scan_block(stack, stack + THREAD_SIZE, NULL);
14791479
put_task_stack(p);
14801480
}
1481-
} while_each_thread(g, p);
1482-
read_unlock(&tasklist_lock);
1481+
}
1482+
rcu_read_unlock();
14831483
}
14841484

14851485
/*

0 commit comments

Comments
 (0)