Re: [PATCH bpf-next v3 07/18] bpf: ringbuf memory usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 28, 2023 at 1:22 AM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
>
> On Mon, Feb 27, 2023 at 7:21 AM Yafang Shao <laoar.shao@xxxxxxxxx> wrote:
> >
> > A new helper ringbuf_map_mem_usage() is introduced to calculate ringbuf
> > memory usage.
> >
> > The result as follows,
> > - before
> > 15: ringbuf  name count_map  flags 0x0
> >         key 0B  value 0B  max_entries 65536  memlock 0B
> >
> > - after
> > 15: ringbuf  name count_map  flags 0x0
> >         key 0B  value 0B  max_entries 65536  memlock 78424B
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> >  kernel/bpf/ringbuf.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
> > index 80f4b4d..2bbf6e2 100644
> > --- a/kernel/bpf/ringbuf.c
> > +++ b/kernel/bpf/ringbuf.c
> > @@ -336,6 +336,23 @@ static __poll_t ringbuf_map_poll_user(struct bpf_map *map, struct file *filp,
> >         return 0;
> >  }
> >
> > +static u64 ringbuf_map_mem_usage(const struct bpf_map *map)
> > +{
> > +       struct bpf_ringbuf_map *rb_map;
> > +       struct bpf_ringbuf *rb;
> > +       int nr_data_pages;
> > +       int nr_meta_pages;
> > +       u64 usage = sizeof(struct bpf_ringbuf_map);
> > +
> > +       rb_map = container_of(map, struct bpf_ringbuf_map, map);
> > +       rb = rb_map->rb;
>
> nit: rb_map seems unnecessary, I'd just go straight to rb
>
> rb = container_of(map, struct bpf_ringbuf_map, map)->rb;

Thanks for the suggestion. I will do it.

>
> > +       usage += (u64)rb->nr_pages << PAGE_SHIFT;
> > +       nr_meta_pages = RINGBUF_PGOFF + RINGBUF_POS_PAGES;
>
> it would be cleaner to extract this into a constant
> RINGBUF_NR_META_PAGES and use it in ringbuf_map_mem_usage and
> bpf_ringbuf_area_alloc to keep them in sync
>

Will do it.

> But other than that, looks good:
>
> Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

Thanks for the review.


-- 
Regards
Yafang



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux