From: Yosry Ahmed <yosryahmed@google.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Shuah Khan <shuah@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Michal Hocko <mhocko@kernel.org>
Cc: Stanislav Fomichev <sdf@google.com>,
David Rientjes <rientjes@google.com>,
Greg Thelen <gthelen@google.com>,
Shakeel Butt <shakeelb@google.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
cgroups@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next 0/9] bpf: cgroup hierarchical stats collection
Date: Fri, 13 May 2022 00:16:28 -0700 [thread overview]
Message-ID: <CAJD7tkaUBDnjL_Mt-t1ictGO552QF31DQ+VrEwkm3gg2DFZ14Q@mail.gmail.com> (raw)
In-Reply-To: <20220510001807.4132027-1-yosryahmed@google.com>
I have done some significant changes on the BPF side of this. I will
send a RFC V2 soon with those changes and incorporating the feedback
on the cgroup side that I got from Tejun. Hold off on reviewing this
version.
On Mon, May 9, 2022 at 5:18 PM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> This patch series allows for using bpf to collect hierarchical cgroup
> stats efficiently by integrating with the rstat framework. The rstat
> framework provides an efficient way to collect cgroup stats and
> propagate them through the cgroup hierarchy.
>
> The last patch is a selftest that demonastrates the entire workflow.
> The workflow consists of:
> - bpf programs that collect per-cpu per-cgroup stats (tracing progs).
> - bpf rstat flusher that contains the logic for aggregating stats
> across cpus and across the cgroup hierarchy.
> - bpf cgroup_iter responsible for outputting the stats to userspace
> through reading a file in bpffs.
>
> The first 3 patches include the new bpf rstat flusher program type and
> the needed support in rstat code and libbpf. The rstat flusher program
> is a callback that the rstat framework makes to bpf when a stat flush is
> ongoing, similar to the css_rstat_flush() callback that rstat makes to
> cgroup controllers. Each callback is parameterized by a (cgroup, cpu)
> pair that has been updated. The program contains the logic for
> aggregating the stats across cpus and across the cgroup hierarchy.
> These programs can be attached to any cgroup subsystem, not only the
> ones that implement the css_rstat_flush() callback in the kernel. This
> gives bpf programs more flexibility, and more isolation from the kernel
> implementation.
>
> The following 2 patches add necessary helpers for the stats collection
> workflow. Helpers that call into cgroup_rstat_updated() and
> cgroup_rstat_flush() are added to allow bpf programs collecting stats to
> tell the rstat framework that a cgroup has been updated, and to allow
> bpf programs outputting stats to tell the rstat framework to flush the
> stats before they are displayed to the user. An additional
> bpf_map_lookup_percpu_elem is introduced to allow rstat flusher programs
> to access percpu stats of the cpu being flushed.
>
> The following 3 patches add the cgroup_iter program type (v2). This was
> originally introduced by Hao as a part of a different series [1].
> Their usecase is better showcased as part of this patch series. We also
> make cgroup_get_from_id() cgroup v1 friendly to allow cgroup_iter programs
> to display stats for cgroup v1 as well. This small change makes the
> entire workflow cgroup v1 friendly without any other dedicated changes.
>
> The final patch is a selftest demonstrating the entire workflow with a
> set of bpf programs that collect per-cgroup latency of memcg reclaim.
>
> [1]https://lore.kernel.org/lkml/20220225234339.2386398-9-haoluo@google.com/
>
>
> Hao Luo (2):
> cgroup: Add cgroup_put() in !CONFIG_CGROUPS case
> bpf: Introduce cgroup iter
>
> Yosry Ahmed (7):
> bpf: introduce CGROUP_SUBSYS_RSTAT program type
> cgroup: bpf: flush bpf stats on rstat flush
> libbpf: Add support for rstat progs and links
> bpf: add bpf rstat helpers
> bpf: add bpf_map_lookup_percpu_elem() helper
> cgroup: add v1 support to cgroup_get_from_id()
> bpf: add a selftest for cgroup hierarchical stats collection
>
> include/linux/bpf-cgroup-subsys.h | 35 ++
> include/linux/bpf.h | 4 +
> include/linux/bpf_types.h | 2 +
> include/linux/cgroup-defs.h | 4 +
> include/linux/cgroup.h | 5 +
> include/uapi/linux/bpf.h | 45 +++
> kernel/bpf/Makefile | 3 +-
> kernel/bpf/arraymap.c | 11 +-
> kernel/bpf/cgroup_iter.c | 148 ++++++++
> kernel/bpf/cgroup_subsys.c | 212 +++++++++++
> kernel/bpf/hashtab.c | 25 +-
> kernel/bpf/helpers.c | 56 +++
> kernel/bpf/syscall.c | 6 +
> kernel/bpf/verifier.c | 6 +
> kernel/cgroup/cgroup.c | 16 +-
> kernel/cgroup/rstat.c | 11 +
> scripts/bpf_doc.py | 2 +
> tools/include/uapi/linux/bpf.h | 45 +++
> tools/lib/bpf/bpf.c | 3 +
> tools/lib/bpf/bpf.h | 3 +
> tools/lib/bpf/libbpf.c | 35 ++
> tools/lib/bpf/libbpf.h | 3 +
> tools/lib/bpf/libbpf.map | 1 +
> .../test_cgroup_hierarchical_stats.c | 335 ++++++++++++++++++
> tools/testing/selftests/bpf/progs/bpf_iter.h | 7 +
> .../selftests/bpf/progs/cgroup_vmscan.c | 211 +++++++++++
> 26 files changed, 1212 insertions(+), 22 deletions(-)
> create mode 100644 include/linux/bpf-cgroup-subsys.h
> create mode 100644 kernel/bpf/cgroup_iter.c
> create mode 100644 kernel/bpf/cgroup_subsys.c
> create mode 100644 tools/testing/selftests/bpf/prog_tests/test_cgroup_hierarchical_stats.c
> create mode 100644 tools/testing/selftests/bpf/progs/cgroup_vmscan.c
>
> --
> 2.36.0.512.ge40c2bad7a-goog
>
prev parent reply other threads:[~2022-05-13 7:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 0:17 [RFC PATCH bpf-next 0/9] bpf: cgroup hierarchical stats collection Yosry Ahmed
2022-05-10 0:17 ` [RFC PATCH bpf-next 1/9] bpf: introduce CGROUP_SUBSYS_RSTAT program type Yosry Ahmed
2022-05-10 18:07 ` Yosry Ahmed
2022-05-10 19:21 ` Yosry Ahmed
2022-05-10 18:44 ` Tejun Heo
2022-05-10 19:34 ` Yosry Ahmed
2022-05-10 19:59 ` Tejun Heo
2022-05-10 20:43 ` Yosry Ahmed
2022-05-10 21:01 ` Tejun Heo
2022-05-10 21:55 ` Yosry Ahmed
2022-05-10 22:09 ` Tejun Heo
2022-05-10 22:10 ` Yosry Ahmed
2022-05-10 0:18 ` [RFC PATCH bpf-next 2/9] cgroup: bpf: flush bpf stats on rstat flush Yosry Ahmed
2022-05-10 18:45 ` Tejun Heo
2022-05-10 0:18 ` [RFC PATCH bpf-next 3/9] libbpf: Add support for rstat progs and links Yosry Ahmed
2022-05-10 0:18 ` [RFC PATCH bpf-next 4/9] bpf: add bpf rstat helpers Yosry Ahmed
2022-05-10 0:18 ` [RFC PATCH bpf-next 5/9] bpf: add bpf_map_lookup_percpu_elem() helper Yosry Ahmed
2022-05-10 0:18 ` [RFC PATCH bpf-next 6/9] cgroup: add v1 support to cgroup_get_from_id() Yosry Ahmed
2022-05-10 18:33 ` Tejun Heo
2022-05-10 18:36 ` Yosry Ahmed
2022-05-10 0:18 ` [RFC PATCH bpf-next 7/9] cgroup: Add cgroup_put() in !CONFIG_CGROUPS case Yosry Ahmed
2022-05-10 18:25 ` Hao Luo
2022-05-10 0:18 ` [RFC PATCH bpf-next 8/9] bpf: Introduce cgroup iter Yosry Ahmed
2022-05-10 18:25 ` Hao Luo
2022-05-10 18:54 ` Tejun Heo
2022-05-10 21:12 ` Hao Luo
2022-05-10 22:07 ` Tejun Heo
2022-05-10 22:49 ` Hao Luo
2022-05-10 0:18 ` [RFC PATCH bpf-next 9/9] selftest/bpf: add a selftest for cgroup hierarchical stats Yosry Ahmed
2022-05-13 7:16 ` Yosry Ahmed [this message]
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=CAJD7tkaUBDnjL_Mt-t1ictGO552QF31DQ+VrEwkm3gg2DFZ14Q@mail.gmail.com \
--to=yosryahmed@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=sdf@google.com \
--cc=shakeelb@google.com \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=tj@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).