All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
	daniel@iogearbox.net, 	martin.lau@linux.dev, kernel-team@fb.com,
	yonghong.song@linux.dev
Subject: Re: [PATCH bpf-next v2 2/2] veristat: memory accounting for bpf programs
Date: Thu, 12 Jun 2025 17:31:28 -0700	[thread overview]
Message-ID: <bb0a4b1d12c8d3e7a5aba2cfce1f07143a7e2b71.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzbTxyGXi=ZNU_yebe2a=zgNoeafRTK9pixJMihUwwo0Pg@mail.gmail.com>

On Thu, 2025-06-12 at 17:01 -0700, Andrii Nakryiko wrote:

[...]

> > +static void destroy_stat_cgroup(void)
> > +{
> > +       char buf[PATH_MAX];
> > +       int err;
> > +
> > +       close(env.memory_peak_fd);
> > +
> > +       if (env.orig_cgroup[0]) {
> > +               snprintf_trunc(buf, sizeof(buf), "%s/cgroup.procs", env.orig_cgroup);
> > +               err = write_one_line(buf, "%d\n", getpid());
> > +               if (err < 0)
> > +                       log_errno("moving self to original cgroup %s\n", env.orig_cgroup);
> > +       }
> > +
> > +       if (env.stat_cgroup[0]) {
> > +               err = rmdir(env.stat_cgroup);
> 
> We need to enter the original cgroup to successfully remove the one we
> created, is that right? Otherwise, why bother reentering if we are on
> our way out, no?

Yes, cgroup can't be removed if there are member processes.
I chose to organize this way because there would be a message printed
with a name of stale group.

> 
> > +               if (err < 0)
> > +                       log_errno("deletion of cgroup %s", env.stat_cgroup);
> > +       }
> > +
> > +       env.memory_peak_fd = -1;
> > +       env.orig_cgroup[0] = 0;
> > +       env.stat_cgroup[0] = 0;
> > +}
> > +
> > +/*
> > + * Creates a cgroup at /sys/fs/cgroup/veristat-accounting-<pid>,
> > + * moves current process to this cgroup.
> > + */
> > +static void create_stat_cgroup(void)
> > +{
> > +       char cgroup_fs_mount[PATH_MAX + 1];
> > +       char buf[PATH_MAX + 1];
> > +       int err;
> > +
> > +       env.memory_peak_fd = -1;
> > +
> > +       if (!output_stat_enabled(MEMORY_PEAK))
> > +               return;
> > +
> > +       err = scanf_one_line("/proc/self/mounts", 2, "%*s %" STR(PATH_MAX) "s cgroup2 %s",
> 
> let's just hard-code 1024 or something and not do that STR() magic,
> please (same below).
> 
> > +                            cgroup_fs_mount, buf);
> > +       if (err != 2) {
> > +               if (err < 0)
> > +                       log_errno("reading /proc/self/mounts");
> > +               else if (!env.quiet)
> > +                       fprintf(stderr, "Can't find cgroupfs v2 mount point.\n");
> > +               goto err_out;
> > +       }
> > +
> > +       /* cgroup-v2.rst promises the line "0::<group>" for cgroups v2 */
> > +       err = scanf_one_line("/proc/self/cgroup", 1, "0::%" STR(PATH_MAX) "s", buf);
> 
> do you think just hard-coding /sys/fs/cgroup would not work in
> practice? It just feels like we are trying to be a bit too flexible
> here...

Idk, removing this saves 10 lines.
On machines I have access to (one CentOS, one Fedora) the mount point
is /sys/fs/cgroup.

> 
> > +       if (err != 1) {
> > +               if (err < 0)
> > +                       log_errno("reading /proc/self/cgroup");
> > +               else if (!env.quiet)
> > +                       fprintf(stderr, "Can't infer veristat process cgroup.");
> > +               goto err_out;
> > +       }
> > +
> 
> [...]

Ack for other points, thank you for taking a look.

  reply	other threads:[~2025-06-13  0:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12 13:08 [PATCH bpf-next v2 0/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-12 13:08 ` [PATCH bpf-next v2 1/2] bpf: include verifier memory allocations in memcg statistics Eduard Zingerman
2025-06-13  0:05   ` Andrii Nakryiko
2025-06-13  0:15     ` Eduard Zingerman
2025-06-13  0:18       ` Andrii Nakryiko
2025-06-13  0:53         ` Alexei Starovoitov
2025-06-13  1:29           ` Eduard Zingerman
2025-06-13  2:25             ` Alexei Starovoitov
2025-06-16  8:02               ` Eduard Zingerman
2025-06-12 13:08 ` [PATCH bpf-next v2 2/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-13  0:01   ` Andrii Nakryiko
2025-06-13  0:31     ` Eduard Zingerman [this message]
2025-06-13  7:09     ` 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=bb0a4b1d12c8d3e7a5aba2cfce1f07143a7e2b71.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii.nakryiko@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.