]> 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)
commitfa05e7b728165cad13cab893b36ae6454b88b6a5
treee00ae0f55c6ec8774ea5664a0ce88eab88dccf29
parent056a1540fa697b10869ffb7eb65d61dab575771a
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