From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Kernel Team <kernel-team@fb.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH bpf-next v1 2/2] veristat: memory accounting for bpf programs
Date: Thu, 05 Jun 2025 19:33:46 -0700 [thread overview]
Message-ID: <d4bc026d37fc75f986abe276f2650feff0d4ad70.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQKsfQSM76q88o38GboUrSuts9xEYAMZ=36AUCcrwG34Jg@mail.gmail.com>
On Thu, 2025-06-05 at 19:17 -0700, Alexei Starovoitov wrote:
> On Thu, Jun 5, 2025 at 6:04 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > On Thu, 2025-06-05 at 16:06 -0700, Eduard Zingerman wrote:
> >
> > [...]
> >
> > > +/*
> > > + * Enters new cgroup namespace and mounts cgroupfs at /tmp/veristat-cgroup-mount-XXXXXX,
> > > + * enables "memory" controller for the root cgroup.
> > > + */
> > > +static int mount_cgroupfs(void)
> > > +{
> > > + char buf[PATH_MAX + 1];
> > > + int err;
> > > +
> > > + env.memory_peak_fd = -1;
> > > +
> > > + err = unshare(CLONE_NEWCGROUP);
> > > + if (err < 0) {
> > > + err = log_errno("unshare(CLONE_NEWCGROUP)");
> > > + goto err_out;
> > > + }
> >
> > The `unshare` call is useless. I thought it would grant me a new
> > hierarchy with separate cgroup.subtree_control in the root.
> > But that's now how things work, hierarchy is shared across namespaces.
> > I'll drop this call and just complain if "memory" controller is not enabled.
> >
> > The "mount" part can remain, I use it to avoid searching for cgroupfs
> > mount point. Alternatively I can inspect /proc/self/mountinfo and
> > complain if cgroupfs is not found. Please let me know which way is
> > preferred.
>
> I would keep unshare and mount,
But what would be the purpose of the unshare?
I thought that it provides a new isolated new independent
cgroup.subtree_control, but that is not the case.
Outside from that the feature gains nothing from entering new namespace.
> and if possible share the code with setup_cgroup_environment()
> from cgroup_helpers.c
setup_cgroup_environment() does the following:
a. creates a directory for cgroupfs mount
b. creates a new mount namespace
c. mounts a new empty root
d. mounts cgroupfs inside new root
e. creates a cgroup
f. enables controllers
Of these only (a) and (d) are needed for veristat (and (f) is deligated to init).
Also my current version does unshare for cgroup namespace, while
setup_cgroup_environment() does not do that.
Things that might be reusable:
- get_root_cgroup
- remove_cgroup
- join_root_cgroup
- join_cgroup
These rely on CGROUP_MOUNT_PATH and CGROUP_WORK_DIR being constants,
I'll need to modify these helpers to parameterize this.
next prev parent reply other threads:[~2025-06-06 2:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 23:06 [PATCH bpf-next v1 0/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-05 23:06 ` [PATCH bpf-next v1 1/2] bpf: include verifier memory allocations in memcg statistics Eduard Zingerman
2025-06-05 23:06 ` [PATCH bpf-next v1 2/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-06 1:03 ` Eduard Zingerman
2025-06-06 2:17 ` Alexei Starovoitov
2025-06-06 2:33 ` Eduard Zingerman [this message]
2025-06-06 2:35 ` Alexei Starovoitov
2025-06-06 2:46 ` Eduard Zingerman
2025-06-06 16:53 ` Mykyta Yatsenko
2025-06-06 17:03 ` Eduard Zingerman
2025-06-06 18:19 ` Andrii Nakryiko
2025-06-07 8:13 ` Eduard Zingerman
2025-06-09 20:57 ` Andrii Nakryiko
2025-06-09 22:45 ` Eduard Zingerman
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=d4bc026d37fc75f986abe276f2650feff0d4ad70.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.