]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Avoid iterating duplicated files for task_file iterator
authorYonghong Song <yhs@fb.com>
Wed, 2 Sep 2020 02:31:12 +0000 (19:31 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 2 Sep 2020 14:40:33 +0000 (16:40 +0200)
commit203d7b054fc719561fe258e46e280930890dceaf
treee00ae0f55c6ec8774ea5664a0ce88eab88dccf29
parent0697fecf7ecd8abf70d0f46e6a352818e984cc9f
bpf: Avoid iterating duplicated files for task_file iterator

Currently, task_file iterator iterates all files from all tasks.
This may potentially visit a lot of duplicated files if there are
many tasks sharing the same files, e.g., typical pthreads
where these pthreads and the main thread are sharing the same files.

This patch changed task_file iterator to skip a particular task
if that task shares the same files as its group_leader (the task
having the same tgid and also task->tgid == task->pid).
This will preserve the same result, visiting all files from all
tasks, and will reduce runtime cost significantl, e.g., if there are
a lot of pthreads and the process has a lot of open files.

Suggested-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/bpf/20200902023112.1672792-1-yhs@fb.com
kernel/bpf/task_iter.c