Re: [PATCH bpf-next v3 02/18] bpf: lpm_trie memory usage

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

 



On Wed, Mar 1, 2023 at 10:31 AM Hou Tao <houtao@xxxxxxxxxxxxxxx> wrote:
>
> From: Hou Tao <houtao1@xxxxxxxxxx>
>
> Hi,
>
> > trie_mem_usage() is introduced to calculate the lpm_trie memory usage.
> > Some small memory allocations are ignored. The inner node is also
> > ignored.
> >
> > The result as follows,
> >
> > - before
> > 10: lpm_trie  flags 0x1
> >         key 8B  value 8B  max_entries 65536  memlock 1048576B
> >
> > - after
> > 10: lpm_trie  flags 0x1
> >         key 8B  value 8B  max_entries 65536  memlock 2291536B
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> >  kernel/bpf/lpm_trie.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
> > index d833496..e0ca08e 100644
> > --- a/kernel/bpf/lpm_trie.c
> > +++ b/kernel/bpf/lpm_trie.c
> > @@ -720,6 +720,16 @@ static int trie_check_btf(const struct bpf_map *map,
> >              -EINVAL : 0;
> >  }
> >
> > +static u64 trie_mem_usage(const struct bpf_map *map)
> > +{
> > +     struct lpm_trie *trie = container_of(map, struct lpm_trie, map);
> > +     u64 elem_size;
> > +
> > +     elem_size = sizeof(struct lpm_trie_node) + trie->data_size +
> > +                         trie->map.value_size;
> > +     return elem_size * trie->n_entries;
> Need to use READ_ONCE(trie->n_entries) because all updates of n_entries are protected by trie->lock and here it is a lockless read.

Indeed. Will change it in the next version.
Thanks for your 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