linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hao Luo <haoluo@google.com>
To: Yonghong Song <yhs@fb.com>
Cc: "Yosry Ahmed" <yosryahmed@google.com>,
	"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>, "Tejun Heo" <tj@kernel.org>,
	"Zefan Li" <lizefan.x@bytedance.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Shuah Khan" <shuah@kernel.org>,
	"Michal Hocko" <mhocko@kernel.org>,
	"KP Singh" <kpsingh@kernel.org>,
	"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"David Rientjes" <rientjes@google.com>,
	"Stanislav Fomichev" <sdf@google.com>,
	"Greg Thelen" <gthelen@google.com>,
	"Shakeel Butt" <shakeelb@google.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bpf@vger.kernel.org, cgroups@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 4/8] bpf: Introduce cgroup iter
Date: Thu, 21 Jul 2022 10:21:53 -0700	[thread overview]
Message-ID: <CA+khW7ihQmjwGuVPCEuZ5EXMiMWWaxiAatmjpo1xiaWokUNRGw@mail.gmail.com> (raw)
In-Reply-To: <3f3ffe0e-d2ac-c868-a1bf-cdf1b58fd666@fb.com>

On Thu, Jul 21, 2022 at 9:15 AM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 7/20/22 5:40 PM, Hao Luo wrote:
> > On Mon, Jul 11, 2022 at 8:45 PM Yonghong Song <yhs@fb.com> wrote:
> >>
> >> On 7/11/22 5:42 PM, Hao Luo wrote:
> > [...]
> >>>>>> +
> >>>>>> +static void *cgroup_iter_seq_start(struct seq_file *seq, loff_t *pos)
> >>>>>> +{
> >>>>>> +    struct cgroup_iter_priv *p = seq->private;
> >>>>>> +
> >>>>>> +    mutex_lock(&cgroup_mutex);
> >>>>>> +
> >>>>>> +    /* support only one session */
> >>>>>> +    if (*pos > 0)
> >>>>>> +        return NULL;
> >>>>>
> >>>>> This might be okay. But want to check what is
> >>>>> the practical upper limit for cgroups in a system
> >>>>> and whether we may miss some cgroups. If this
> >>>>> happens, it will be a surprise to the user.
> >>>>>
> >>>
> >>> Ok. What's the max number of items supported in a single session?
> >>
> >> The max number of items (cgroups) in a single session is determined
> >> by kernel_buffer_size which equals to 8 * PAGE_SIZE. So it really
> >> depends on how much data bpf program intends to send to user space.
> >> If each bpf program run intends to send 64B to user space, e.g., for
> >> cpu, memory, cpu pressure, mem pressure, io pressure, read rate, write
> >> rate, read/write rate. Then each session can support 512 cgroups.
> >>
> >
> > Hi Yonghong,
> >
> > Sorry about the late reply. It's possible that the number of cgroup
> > can be large, 1000+, in our production environment. But that may not
> > be common. Would it be good to leave handling large number of cgroups
> > as follow up for this patch? If it turns out to be a problem, to
> > alleviate it, we could:
> >
> > 1. tell users to write program to skip a certain uninteresting cgroups.
> > 2. support requesting large kernel_buffer_size for bpf_iter, maybe as
> > a new bpf_iter flag.
>
> Currently if we intend to support multiple read() for cgroup_iter,
> the following is a very inefficient approach:
>
> in seq_file private data structure, remember the last cgroup visited
> and for the second read() syscall, do the traversal again (but not
> calling bpf program) until the last cgroup and proceed from there.
> This is inefficient and probably works. But if the last cgroup is
> gone from the hierarchy, that the above approach won't work. One
> possibility is to remember the last two cgroups. If the last cgroup
> is gone, check the 'next' cgroup based on the one before the last
> cgroup. If both are gone, we return NULL.
>

I suspect in reality, just remembering the last cgroup (or two
cgroups) may not be sufficient. First, I don't want to hold
cgroup_mutex across multiple sessions. I assume it's also not safe to
release cgroup_mutex in the middle of walking cgroup hierarchy.
Supporting multiple read() can be nasty for cgroup_iter.

> But in any case, if there are additional cgroups not visited,
> in the second read(), we should not return NULL which indicates
> done with all cgroups. We may return EOPNOTSUPP to indicate there
> are missing cgroups due to not supported.
>
> Once users see EOPNOTSUPP which indicates there are missing
> cgroups, they can do more filtering in bpf program to avoid
> large data volume to user space.
>

Makes sense. Yonghong, one question to confirm, if the first read()
overflows, does the user still get partial data?

I'll change the return code to EOPNOTSUPP in v4 of this patchset.

> To provide a way to truely visit *all* cgroups,
> we can either use bpf_iter link_create->flags
> to increase the buffer size as your suggested in the above so
> user can try to allocate more kernel buffer size. Or implement
> proper second read() traversal which I don't have a good idea
> how to do it efficiently.

I will try the buffer size increase first. Looks more doable. Do you
mind putting this support as a follow-up?

> >
> > Hao
> >
> >>>
> > [...]
> >>>>> [...]

  reply	other threads:[~2022-07-21 17:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-09  0:04 [PATCH bpf-next v3 0/8] bpf: rstat: cgroup hierarchical stats Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 1/8] btf: Add a new kfunc set which allows to mark a function to be sleepable Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 2/8] cgroup: enable cgroup_get_from_file() on cgroup1 Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 3/8] bpf, iter: Fix the condition on p when calling stop Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 4/8] bpf: Introduce cgroup iter Yosry Ahmed
2022-07-11  0:19   ` Yonghong Song
2022-07-11 23:20     ` Yonghong Song
2022-07-12  0:42       ` Hao Luo
2022-07-12  3:45         ` Yonghong Song
2022-07-21  0:40           ` Hao Luo
2022-07-21 16:15             ` Yonghong Song
2022-07-21 17:21               ` Hao Luo [this message]
2022-07-21 18:15                 ` Yonghong Song
2022-07-21 21:07                   ` Hao Luo
2022-07-09  0:04 ` [PATCH bpf-next v3 5/8] selftests/bpf: Test cgroup_iter Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 6/8] cgroup: bpf: enable bpf programs to integrate with rstat Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 7/8] selftests/bpf: extend cgroup helpers Yosry Ahmed
2022-07-09  0:04 ` [PATCH bpf-next v3 8/8] bpf: add a selftest for cgroup hierarchical stats collection Yosry Ahmed
2022-07-11  0:26   ` Yonghong Song
2022-07-11  0:51     ` Yonghong Song
2022-07-11  6:01       ` Hao Luo
2022-07-11  6:19         ` Yonghong Song
2022-07-12  0:44           ` Hao Luo
2022-07-12  3:55       ` Yosry Ahmed
2022-07-18 19:34         ` Yosry Ahmed
2022-07-19  0:19           ` Hao Luo
2022-07-19 16:17           ` Yonghong Song
2022-07-19 17:02             ` Yosry Ahmed

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=CA+khW7ihQmjwGuVPCEuZ5EXMiMWWaxiAatmjpo1xiaWokUNRGw@mail.gmail.com \
    --to=haoluo@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --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=mkoutny@suse.com \
    --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 \
    --cc=yosryahmed@google.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).