All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ho-Ren Chuang <horenc@vt.edu>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: John Fastabend <john.fastabend@gmail.com>,
	ast@kernel.org, daniel@iogearbox.net,  andrii@kernel.org,
	kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
	 kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	jolsa@kernel.org,  tj@kernel.org, dennis@kernel.org,
	cl@linux.com, akpm@linux-foundation.org,  penberg@kernel.org,
	rientjes@google.com, iamjoonsoo.kim@lge.com,
	 roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, vbabka@suse.cz,
	 urezki@gmail.com, linux-mm@kvack.org, bpf@vger.kernel.org,
	 hao.xiang@bytedance.com, yifeima@bytedance.com,
	 Xiaoning Ding <xiaoning.ding@bytedance.com>,
	horenchuang@bytedance.com
Subject: Re: [PATCH bpf-next 0/7] bpf, mm: bpf memory usage
Date: Mon, 6 Feb 2023 16:48:56 -0800	[thread overview]
Message-ID: <CAOfppAUgB1qtFQfSb7WnGTJ+0fP2NL_T9EJYHgwQyW0mx4vnXA@mail.gmail.com> (raw)
In-Reply-To: <CALOAHbAjHqXGZH_p19aYTbqK=sE8ZaMxhVzAoTO4ZKSXLiyx-w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4066 bytes --]

Hi Yafang and everyone,

We've proposed very similar features at
https://lore.kernel.org/bpf/CAAYibXgiCOOEY9NvLXbY4ve7pH8xWrZjnczrj6SHy3x_TtOU1g@mail.gmail.com/#t


We are very excited seeing we are not the only ones eager to have this
feature upstream to monitor eBPF map's actual usage. This shows the need
for having such an ability in eBPF.


Regarding the use cases please also check
https://lore.kernel.org/all/CAADnVQLBt0snxv4bKwg1WKQ9wDFbaDCtZ03v1-LjOTYtsKPckQ@mail.gmail.com/#t
<https://lore.kernel.org/all/CAADnVQLBt0snxv4bKwg1WKQ9wDFbaDCtZ03v1-LjOTYtsKPckQ@mail.gmail.com/>
.
We are developing an app to monitor memory footprints used by eBPF
programs/maps similar to Linux `top` command.

Thank you,

On Sat, Feb 4, 2023 at 8:03 PM Yafang Shao <laoar.shao@gmail.com> wrote:

> On Sat, Feb 4, 2023 at 10:15 AM John Fastabend <john.fastabend@gmail.com>
> wrote:
> >
> > Yafang Shao wrote:
> > > Currently we can't get bpf memory usage reliably. bpftool now shows the
> > > bpf memory footprint, which is difference with bpf memory usage. The
> > > difference can be quite great between the footprint showed in bpftool
> > > and the memory actually allocated by bpf in some cases, for example,
> > >
> > > - non-preallocated bpf map
> > >   The non-preallocated bpf map memory usage is dynamically changed. The
> > >   allocated elements count can be from 0 to the max entries. But the
> > >   memory footprint in bpftool only shows a fixed number.
> > > - bpf metadata consumes more memory than bpf element
> > >   In some corner cases, the bpf metadata can consumes a lot more memory
> > >   than bpf element consumes. For example, it can happen when the
> element
> > >   size is quite small.
> >
> > Just following up slightly on previous comment.
> >
> > The metadata should be fixed and knowable correct?
>
> The metadata of BPF itself is fixed, but the medata of MM allocation
> depends on the kernel configuretion.
>
> > What I'm getting at
> > is if this can be calculated directly instead of through a BPF helper
> > and walking the entire map.
> >
>
> As I explained in another thread, it doesn't walk the entire map.
>
> > >
> > > We need a way to get the bpf memory usage especially there will be more
> > > and more bpf programs running on the production environment and thus
> the
> > > bpf memory usage is not trivial.
> >
> > In our environments we track map usage so we always know how many entries
> > are in a map. I don't think we use this to calculate memory footprint
> > at the moment, but just for map usage. Seems though once you have this
> > calculating memory footprint can be done out of band because element
> > and overheads costs are fixed.
> >
> > >
> > > This patchset introduces a new map ops ->map_mem_usage to get the
> memory
> > > usage. In this ops, the memory usage is got from the pointers which is
> > > already allocated by a bpf map. To make the code simple, we igore some
> > > small pointers as their size are quite small compared with the total
> > > usage.
> > >
> > > In order to get the memory size from the pointers, some generic mm
> helpers
> > > are introduced firstly, for example, percpu_size(), vsize() and
> kvsize().
> > >
> > > This patchset only implements the bpf memory usage for hashtab. I will
> > > extend it to other maps and bpf progs (bpf progs can dynamically
> allocate
> > > memory via bpf_obj_new()) in the future.
> >
> > My preference would be to calculate this out of band. Walking a
> > large map and doing it in a critical section to get the memory
> > usage seems not optimal
> >
>
> I don't quite understand what you mean by calculating it out of band.
> This patchset introduces a BPF helper which is used in bpftool, so it
> is already out of band, right ?
> We should do it in bpftool, because the sys admin wants a generic way
> to get the system-wide bpf memory usage.
>
> --
> Regards
> Yafang
>


-- 
Best regards,
Ho-Ren (Jack) Chuang
莊賀任
1(540)449-9833

[-- Attachment #2: Type: text/html, Size: 6241 bytes --]

  reply	other threads:[~2023-02-07  0:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02  1:41 [PATCH bpf-next 0/7] bpf, mm: bpf memory usage Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 1/7] mm: percpu: fix incorrect size in pcpu_obj_full_size() Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 2/7] mm: percpu: introduce percpu_size() Yafang Shao
2023-02-02 14:32   ` Christoph Lameter
2023-02-02 15:01     ` Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 3/7] mm: vmalloc: introduce vsize() Yafang Shao
2023-02-02 10:23   ` Christoph Hellwig
2023-02-02 14:10     ` Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 4/7] mm: util: introduce kvsize() Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 5/7] bpf: add new map ops ->map_mem_usage Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 6/7] bpf: introduce bpf_mem_alloc_size() Yafang Shao
2023-02-02  4:53   ` kernel test robot
2023-02-02 14:11     ` Yafang Shao
2023-02-02  1:41 ` [PATCH bpf-next 7/7] bpf: hashtab memory usage Yafang Shao
2023-02-04  2:01   ` John Fastabend
2023-02-05  3:55     ` Yafang Shao
2023-02-08  1:56       ` Alexei Starovoitov
2023-02-08  3:33         ` Yafang Shao
2023-02-08  4:29           ` Alexei Starovoitov
2023-02-08 14:22             ` Yafang Shao
2023-02-05 22:14   ` Cong Wang
2023-02-06 11:52     ` Yafang Shao
2023-02-04  2:15 ` [PATCH bpf-next 0/7] bpf, mm: bpf " John Fastabend
2023-02-05  4:03   ` Yafang Shao
2023-02-07  0:48     ` Ho-Ren Chuang [this message]
2023-02-07  7:02       ` Yafang Shao
2023-02-07  0:53     ` Ho-Ren Chuang

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=CAOfppAUgB1qtFQfSb7WnGTJ+0fP2NL_T9EJYHgwQyW0mx4vnXA@mail.gmail.com \
    --to=horenc@vt.edu \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cl@linux.com \
    --cc=daniel@iogearbox.net \
    --cc=dennis@kernel.org \
    --cc=hao.xiang@bytedance.com \
    --cc=haoluo@google.com \
    --cc=horenchuang@bytedance.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --cc=tj@kernel.org \
    --cc=urezki@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=xiaoning.ding@bytedance.com \
    --cc=yhs@fb.com \
    --cc=yifeima@bytedance.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 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.