From: Anton Protopopov <aspsk@isovalent.com>
To: Hou Tao <houtao@huaweicloud.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@vger.kernel.org
Subject: Re: [v3 PATCH bpf-next 3/6] bpf: populate the per-cpu insertions/deletions counters for hashmaps
Date: Thu, 6 Jul 2023 12:25:05 +0000 [thread overview]
Message-ID: <ZKayoTYomkVc/i3r@zh-lab-node-5> (raw)
In-Reply-To: <b1b9e2b8-f31e-abf5-8853-cb64bb0232a6@huaweicloud.com>
On Thu, Jul 06, 2023 at 10:01:26AM +0800, Hou Tao wrote:
> Hi,
>
> On 7/4/2023 10:34 PM, Anton Protopopov wrote:
> > On Tue, Jul 04, 2023 at 09:56:36PM +0800, Hou Tao wrote:
> >> Hi,
> >>
> >> On 6/30/2023 4:25 PM, Anton Protopopov wrote:
> >>> Initialize and utilize the per-cpu insertions/deletions counters for hash-based
> >>> maps. Non-trivial changes only apply to the 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 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.
> >>>
> >>> Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> >>> ---
> >>> kernel/bpf/hashtab.c | 23 ++++++++++++++++++++---
> >>> 1 file changed, 20 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> >>> index 56d3da7d0bc6..faaef4fd3df0 100644
> >>> --- a/kernel/bpf/hashtab.c
> >>> +++ b/kernel/bpf/hashtab.c
> >>> @@ -581,8 +581,14 @@ 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;
> >> Considering the per-cpu counter is not always needed, is it a good idea
> >> to make the elem_count being optional by introducing a new map flag ?
> > Per-map-flag or a static key? For me it looked like just doing an unconditional
> > `inc` for a per-cpu variable is better vs. doing a check then `inc` or an
> > unconditional jump.
>
> Sorry I didn't make it clear that I was worried about the allocated
> per-cpu memory. Previous I thought the per-cpu memory is limited, but
> after did some experiments I found it was almost the same as kmalloc()
> which could use all available memory to fulfill the allocation request.
> For a host with 72-cpus, the memory overhead for 10k hash map is about
> ~6MB. The overhead is tiny compared with the total available memory, but
> it is avoidable.
So, in my first patch I've only added new counters for preallocated maps. But
then the feedback was that we need a generic percpu inc/dec counters, so I
added them by default. For me a percpu s64 looks cheap enough for a hash map...
next prev parent reply other threads:[~2023-07-06 12:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 8:25 [v3 PATCH bpf-next 0/6] bpf: add percpu stats for bpf_map Anton Protopopov
2023-06-30 8:25 ` [v3 PATCH bpf-next 1/6] bpf: add percpu stats for bpf_map elements insertions/deletions Anton Protopopov
2023-06-30 8:25 ` [v3 PATCH bpf-next 2/6] bpf: add a new kfunc to return current bpf_map elements count Anton Protopopov
2023-06-30 8:25 ` [v3 PATCH bpf-next 3/6] bpf: populate the per-cpu insertions/deletions counters for hashmaps Anton Protopopov
2023-07-04 13:56 ` Hou Tao
2023-07-04 14:34 ` Anton Protopopov
2023-07-06 2:01 ` Hou Tao
2023-07-06 12:25 ` Anton Protopopov [this message]
2023-07-06 12:30 ` Hou Tao
2023-06-30 8:25 ` [v3 PATCH bpf-next 4/6] bpf: make preloaded map iterators to display map elements count Anton Protopopov
2023-06-30 8:25 ` [v3 PATCH bpf-next 5/6] selftests/bpf: test map percpu stats Anton Protopopov
2023-07-04 14:41 ` Hou Tao
2023-07-04 15:02 ` Anton Protopopov
2023-07-04 15:23 ` Anton Protopopov
2023-07-04 15:49 ` Anton Protopopov
2023-07-05 0:46 ` Hou Tao
2023-07-05 15:41 ` Anton Protopopov
2023-07-05 3:03 ` Hou Tao
2023-07-05 15:34 ` Anton Protopopov
2023-06-30 8:25 ` [v3 PATCH bpf-next 6/6] selftests/bpf: check that ->elem_count is non-zero for the hash map Anton Protopopov
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=ZKayoTYomkVc/i3r@zh-lab-node-5 \
--to=aspsk@isovalent.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=houtao@huaweicloud.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