From: Anton Protopopov <aspsk@isovalent.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v4 bpf-next 3/6] bpf: populate the per-cpu insertions/deletions counters for hashmaps
Date: Thu, 6 Jul 2023 05:47:36 +0000 [thread overview]
Message-ID: <ZKZVeJKyZ9XOgP8Y@zh-lab-node-5> (raw)
In-Reply-To: <CAADnVQKX5Lu-frv38AAe15UmzRNMztB9vYSZTk986Y_UkPR30Q@mail.gmail.com>
On Wed, Jul 05, 2023 at 06:24:44PM -0700, Alexei Starovoitov wrote:
> On Wed, Jul 5, 2023 at 9:00 AM Anton Protopopov <aspsk@isovalent.com> wrote:
> >
> > Initialize and utilize the per-cpu insertions/deletions counters for hash-based
> > maps. Non-trivial changes apply to preallocated maps for which the
> > {inc,dec}_elem_count functions are not called, as there's no need in counting
> > elements to sustain proper map operations.
> >
> > To increase/decrease percpu counters for preallocated hash maps we add raw
> > calls to the bpf_map_{inc,dec}_elem_count functions so that the impact is
> > minimal. For dynamically allocated maps we add corresponding calls to the
> > existing {inc,dec}_elem_count functions.
> >
> > For LRU maps bpf_map_{inc,dec}_elem_count added to the lru pop/free helpers.
> >
> > Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> > ---
> > kernel/bpf/hashtab.c | 23 +++++++++++++++++++++--
> > 1 file changed, 21 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> > index 56d3da7d0bc6..c23557bf9a1a 100644
> > --- a/kernel/bpf/hashtab.c
> > +++ b/kernel/bpf/hashtab.c
> > @@ -302,6 +302,7 @@ static struct htab_elem *prealloc_lru_pop(struct bpf_htab *htab, void *key,
> > struct htab_elem *l;
> >
> > if (node) {
> > + bpf_map_inc_elem_count(&htab->map);
> > l = container_of(node, struct htab_elem, lru_node);
> > memcpy(l->key, key, htab->map.key_size);
> > return l;
> > @@ -581,10 +582,17 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
> > }
> > }
> >
> > + err = bpf_map_init_elem_count(&htab->map);
> > + if (err)
> > + goto free_extra_elements;
> > +
> > return &htab->map;
> >
> > +free_extra_elements:
> > + free_percpu(htab->extra_elems);
> > free_prealloc:
> > - prealloc_destroy(htab);
> > + if (prealloc)
> > + prealloc_destroy(htab);
>
> This is a bit difficult to read.
> I think the logic would be easier to understand if bpf_map_init_elem_count
> was done right before htab->buckets = bpf_map_area_alloc()
> and if (err) goto free_htab
> where you would add bpf_map_free_elem_count.
Thanks, I will fix this.
next prev parent reply other threads:[~2023-07-06 5:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-05 16:01 [PATCH v4 bpf-next 0/6] bpf: add percpu stats for bpf_map Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 1/6] bpf: add percpu stats for bpf_map elements insertions/deletions Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 2/6] bpf: add a new kfunc to return current bpf_map elements count Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 3/6] bpf: populate the per-cpu insertions/deletions counters for hashmaps Anton Protopopov
2023-07-06 1:24 ` Alexei Starovoitov
2023-07-06 5:47 ` Anton Protopopov [this message]
2023-07-05 16:01 ` [PATCH v4 bpf-next 4/6] bpf: make preloaded map iterators to display map elements count Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 5/6] selftests/bpf: test map percpu stats Anton Protopopov
2023-07-06 10:49 ` Hou Tao
2023-07-06 11:54 ` Anton Protopopov
2023-07-06 12:21 ` Hou Tao
2023-07-06 12:57 ` Anton Protopopov
2023-07-07 1:41 ` Hou Tao
2023-07-07 7:28 ` Anton Protopopov
2023-07-07 9:40 ` Hou Tao
2023-07-07 11:06 ` Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 6/6] selftests/bpf: check that ->elem_count is non-zero for the hash map Anton Protopopov
2023-07-06 1:26 ` Alexei Starovoitov
2023-07-06 5:44 ` Anton Protopopov
2023-07-06 17:03 ` Alexei Starovoitov
2023-07-06 17:43 ` Anton Protopopov
2023-07-06 17:48 ` Alexei Starovoitov
2023-07-06 18:35 ` Anton Protopopov
2023-07-06 20:33 ` Alexei Starovoitov
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=ZKZVeJKyZ9XOgP8Y@zh-lab-node-5 \
--to=aspsk@isovalent.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.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