Commit e679654a704e ("bpf: Fix a rcu_sched stall issue with bpf task/task_file iterator") introduced rate limiting in bpf_seq_read() to fix a case where traversing too many tasks and files (tens of millions of files) may cause kernel rcu stall. But rate limiting won't reduce the amount of work to traverse all these files. In practice, for a user process, typically all threads belongs to that process share the same file table and there is no need to visit every thread for its files. This patch implemented a customization for task/task_file iterators to traverse files only for thread with task->tgid == task->pid, which will include some kernel threads and user process main threads. Such reduction of unnecessary work will make iterator runtime much faster if there are a lot of non-main threads and open files for the process. Patch #1 fix an uapi issue for bpf_link_info.iter. Patch #2 implemented the main_thread_only customization for task/task_file iterators. Patch #3 added link_query support for new customization. Patch #4 added bpftool support and Patch #5 added a selftest. Yonghong Song (5): bpf: make bpf_link_info.iter similar to bpf_iter_link_info bpf: add main_thread_only customization for task/task_file iterators bpf: add link_query support for newly added main_thread_only info bpftool: support optional 'task main_thread_only' argument selftests/bpf: test task_file iterator with main_thread_only include/linux/bpf.h | 3 +- include/uapi/linux/bpf.h | 16 ++++- kernel/bpf/task_iter.c | 63 ++++++++++++++----- .../bpftool/Documentation/bpftool-iter.rst | 17 ++++- tools/bpf/bpftool/bash-completion/bpftool | 9 ++- tools/bpf/bpftool/iter.c | 28 +++++++-- tools/bpf/bpftool/link.c | 12 ++++ tools/include/uapi/linux/bpf.h | 16 ++++- .../selftests/bpf/prog_tests/bpf_iter.c | 50 +++++++++++---- .../selftests/bpf/progs/bpf_iter_task_file.c | 9 ++- 10 files changed, 183 insertions(+), 40 deletions(-) -- 2.24.1