On Sat, Aug 13, 2022 at 3:17 PM Yonghong Song <yhs@xxxxxx> wrote: > > > > On 8/10/22 5:16 PM, Kui-Feng Lee wrote: > > Allow creating an iterator that loops through resources of one task/thread. > > > > People could only create iterators to loop through all resources of > > files, vma, and tasks in the system, even though they were interested > > in only the resources of a specific task or process. Passing the > > additional parameters, people can now create an iterator to go > > through all resources or only the resources of a task. > > > > Signed-off-by: Kui-Feng Lee <kuifeng@xxxxxx> > > --- > > include/linux/bpf.h | 29 ++++++++ > > include/uapi/linux/bpf.h | 8 +++ > > kernel/bpf/task_iter.c | 126 ++++++++++++++++++++++++++------- > > tools/include/uapi/linux/bpf.h | 8 +++ > > 4 files changed, 147 insertions(+), 24 deletions(-) > > Btw, Yonghong, I tried to figure it out myself, but got lost in all the kernel functions that don't seem to be very well documented. Sorry for being lazy and throwing this at you :) Is it easy and efficient to iterate only processes using whatever kernel helpers we have at our disposal? E.g., if I wanted to write an iterator that would go only over processes (not individual threads, just task leaders of each different process) within a cgroup, is that possible? I see task iterator as consisting of two different parts (and that makes it a bit hard to define nice and clean interface, but if we can crack this, we'd get an elegant and powerful construct): 1. What entity to iterate: threads or processes? (I'm ignoring task_vma and task_files here, but one could task about files of each thread or files of each process, but it's less practical, probably) 2. What's the scope of objects to iterate: just a thread by tid, just a process by pid/pidfd, once cgroup iter lands, we'll be able to talk about threads or processes within a cgroup or cgroup hierarchy (this is where descendants_{pre,post}, cgroup_self_only and ancestors ordering comes in as well). Currently Kui-Feng is addressing first half of #2 (tid/pid/pidfd parameters), we can use cgroup iter's parameters to define the scope of tasks/processes by cgroup "filter" in a follow up (it naturally extends what we have in this patch set). So now I'm wondering if there is any benefit to also somehow specifying threads vs processes as entities to iterate? And if we do that, does kernel support efficient iteration of processes (as opposed to threads). To be clear, there is a lot of value in having just #2, but while we are all at this topic, I thought I'd clarify for myself #1 as well. Thanks!