Skip to content

RFC bpf: Introduce cgroup_task iter

Yafang Shao bpf 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest4 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4bpf: Add __bpf_iter_attach_cgroup()kernel/bpf/cgroup_iter.c+19 -110 replies
2/4bpf: Add cgroup_task iterinclude/linux/btf_ids.h kernel/bpf/cgroup_iter.c+162 -30 replies
3/4bpftool: Add support for cgroup_tasktools/bpf/bpftool/link.c+2 -10 replies
4/4selftests/bpf: Add selftest for cgroup_task itertools/testing/selftests/bpf/prog_tests/cgroup_task_iter.c tools/testing/selftests/bpf/progs/cgroup_task_iter.c+236 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH bpf-next 0/4] bpf: Introduce cgroup_task iter

This patch introduces cgroup_task iter, which allows for efficient iteration of tasks within a specific cgroup. For example, we can effiently get the nr_{running,blocked} of a container with this new feature.

The cgroup_task iteration serves as an alternative to task_iter in container environments due to certain limitations associated with task_iter.

- Firstly, task_iter only supports the 'current' pidns. However, since our data collector operates on the host, we may need to collect information from multiple containers simultaneously. Using task_iter would require us to fork the collector for each container, which is not ideal.

- Additionally, task_iter is unable to collect task information from containers running in the host pidns.
In our container environment, we have containers running in the host pidns, and we would like to collect task information from them as well.

- Lastly, task_iter does not support multiple-container pods. In a Kubernetes environment, a single pod may contain multiple containers, all sharing the same pidns. However, we are only interested in iterating tasks within the main container, which is not possible with task_iter.

To address the first issue, we could potentially extend task_iter to support specifying a pidns other than the current one. However, for the other two issues, extending task_iter would not provide a solution. Therefore, we believe it is preferable to introduce the cgroup_task iter to handle these scenarios effectively.

Patch #1: Preparation
Patch #2: Add cgroup_task iter
Patch #3: Add support for cgroup_task iter in bpftool Patch #4: Selftests for cgroup_task iter

Yafang Shao (4):
bpf: Add __bpf_iter_attach_cgroup()
bpf: Add cgroup_task iter
bpftool: Add support for cgroup_task selftests/bpf: Add selftest for cgroup_task iter

 include/linux/btf_ids.h                       |  14 ++
 kernel/bpf/cgroup_iter.c                      | 181 ++++++++++++++--
 tools/bpf/bpftool/link.c                      |   3 +-
 .../bpf/prog_tests/cgroup_task_iter.c         | 197 ++++++++++++++++++
 .../selftests/bpf/progs/cgroup_task_iter.c    |  39 ++++
 5 files changed, 419 insertions(+), 15 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_task_iter.c
 create mode 100644 tools/testing/selftests/bpf/progs/cgroup_task_iter.c
Signature · 1 line
2.39.3