From: Yafang Shao <laoar.shao@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yhs@fb.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org, quentin@isovalent.com
Cc: bpf@vger.kernel.org, Yafang Shao <laoar.shao@gmail.com>
Subject: [RFC PATCH bpf-next 0/4] bpf: Introduce cgroup_task iter
Date: Sun, 16 Jul 2023 12:10:42 +0000 [thread overview]
Message-ID: <20230716121046.17110-1-laoar.shao@gmail.com> (raw)
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
--
2.39.3
next reply other threads:[~2023-07-16 12:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-16 12:10 Yafang Shao [this message]
2023-07-16 12:10 ` [RFC PATCH bpf-next 1/4] bpf: Add __bpf_iter_attach_cgroup() Yafang Shao
2023-07-16 12:10 ` [RFC PATCH bpf-next 2/4] bpf: Add cgroup_task iter Yafang Shao
2023-07-16 12:10 ` [RFC PATCH bpf-next 3/4] bpftool: Add support for cgroup_task Yafang Shao
2023-07-16 12:10 ` [RFC PATCH bpf-next 4/4] selftests/bpf: Add selftest for cgroup_task iter Yafang Shao
2023-07-27 14:29 ` [RFC PATCH bpf-next 0/4] bpf: Introduce " Yafang Shao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230716121046.17110-1-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).