From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Song Liu <songliubraving@fb.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
"daniel@iogearbox.net" <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>,
Andrii Nakryiko <andriin@fb.com>
Subject: Re: [PATCH bpf-next 03/11] libbpf: unify and speed up BTF string deduplication
Date: Mon, 2 Nov 2020 20:51:33 -0800 [thread overview]
Message-ID: <CAEf4Bzavxu80+P8N+rEzHTNetsKcPqWkMUafpyG6Bz-6EydwiA@mail.gmail.com> (raw)
In-Reply-To: <11A01E1A-FBAC-490C-BFBC-CB7CF7F8E07A@fb.com>
On Fri, Oct 30, 2020 at 4:33 PM Song Liu <songliubraving@fb.com> wrote:
>
>
>
> > On Oct 28, 2020, at 5:58 PM, Andrii Nakryiko <andrii@kernel.org> wrote:
> >
> > From: Andrii Nakryiko <andriin@fb.com>
> >
> > Revamp BTF dedup's string deduplication to match the approach of writable BTF
> > string management. This allows to transfer deduplicated strings index back to
> > BTF object after deduplication without expensive extra memory copying and hash
> > map re-construction. It also simplifies the code and speeds it up, because
> > hashmap-based string deduplication is faster than sort + unique approach.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> LGTM, with a couple nitpick below:
>
> Acked-by: Song Liu <songliubraving@fb.com>
>
> > ---
> > tools/lib/bpf/btf.c | 265 +++++++++++++++++---------------------------
> > 1 file changed, 99 insertions(+), 166 deletions(-)
> >
> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index 89fecfe5cb2b..db9331fea672 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -90,6 +90,14 @@ struct btf {
> > struct hashmap *strs_hash;
> > /* whether strings are already deduplicated */
> > bool strs_deduped;
> > + /* extra indirection layer to make strings hashmap work with stable
> > + * string offsets and ability to transparently choose between
> > + * btf->strs_data or btf_dedup->strs_data as a source of strings.
> > + * This is used for BTF strings dedup to transfer deduplicated strings
> > + * data back to struct btf without re-building strings index.
> > + */
> > + void **strs_data_ptr;
> > +
> > /* BTF object FD, if loaded into kernel */
> > int fd;
> >
> > @@ -1363,17 +1371,19 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
> >
> > static size_t strs_hash_fn(const void *key, void *ctx)
> > {
> > - struct btf *btf = ctx;
> > - const char *str = btf->strs_data + (long)key;
> > + const char ***strs_data_ptr = ctx;
> > + const char *strs = **strs_data_ptr;
> > + const char *str = strs + (long)key;
>
> Can we keep using btf as the ctx here? "char ***" hurts my eyes...
>
yep, changed to struct btf *
> [...]
>
> > - d->btf->hdr->str_len = end - start;
> > + /* replace BTF string data and hash with deduped ones */
> > + free(d->btf->strs_data);
> > + hashmap__free(d->btf->strs_hash);
> > + d->btf->strs_data = d->strs_data;
> > + d->btf->strs_data_cap = d->strs_cap;
> > + d->btf->hdr->str_len = d->strs_len;
> > + d->btf->strs_hash = d->strs_hash;
> > + /* now point strs_data_ptr back to btf->strs_data */
> > + d->btf->strs_data_ptr = &d->btf->strs_data;
> > +
> > + d->strs_data = d->strs_hash = NULL;
> > + d->strs_len = d->strs_cap = 0;
> > d->btf->strs_deduped = true;
> > + return 0;
> > +
> > +err_out:
> > + free(d->strs_data);
> > + hashmap__free(d->strs_hash);
> > + d->strs_data = d->strs_hash = NULL;
> > + d->strs_len = d->strs_cap = 0;
> > +
> > + /* restore strings pointer for existing d->btf->strs_hash back */
> > + d->btf->strs_data_ptr = &d->strs_data;
>
> We have quite some duplicated code in err_out vs. succeed_out cases.
> How about we add a helper function, like
nope, that won't work, free(d->strs_data) vs free(d->btf->strs_data),
same for hashmap__free(), plus there are strict requirements about the
exact sequence of assignments in success case
>
> void free_strs_data(struct btf_dedup *d)
> {
> free(d->strs_data);
> hashmap__free(d->strs_hash);
> d->strs_data = d->strs_hash = NULL;
> d->strs_len = d->strs_cap = 0;
> }
>
> ?
next prev parent reply other threads:[~2020-11-03 4:51 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 0:58 [PATCH bpf-next 00/11] libbpf: split BTF support Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 01/11] libbpf: factor out common operations in BTF writing APIs Andrii Nakryiko
2020-10-30 0:36 ` Song Liu
2020-10-29 0:58 ` [PATCH bpf-next 02/11] selftest/bpf: relax btf_dedup test checks Andrii Nakryiko
2020-10-30 16:43 ` Song Liu
2020-10-30 18:44 ` Andrii Nakryiko
2020-10-30 22:30 ` Song Liu
2020-10-29 0:58 ` [PATCH bpf-next 03/11] libbpf: unify and speed up BTF string deduplication Andrii Nakryiko
2020-10-30 23:32 ` Song Liu
2020-11-03 4:51 ` Andrii Nakryiko [this message]
2020-11-03 4:59 ` Alexei Starovoitov
2020-11-03 6:01 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 04/11] libbpf: implement basic split BTF support Andrii Nakryiko
2020-11-02 23:23 ` Song Liu
2020-11-03 5:02 ` Andrii Nakryiko
2020-11-03 5:41 ` Song Liu
2020-11-04 23:51 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 05/11] selftests/bpf: add split BTF basic test Andrii Nakryiko
2020-11-02 23:36 ` Song Liu
2020-11-03 5:10 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 06/11] selftests/bpf: add checking of raw type dump in BTF writer APIs selftests Andrii Nakryiko
2020-11-03 0:08 ` Song Liu
2020-11-03 5:14 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 07/11] libbpf: fix BTF data layout checks and allow empty BTF Andrii Nakryiko
2020-11-03 0:51 ` Song Liu
2020-11-03 5:18 ` Andrii Nakryiko
2020-11-03 5:44 ` Song Liu
2020-10-29 0:58 ` [PATCH bpf-next 08/11] libbpf: support BTF dedup of split BTFs Andrii Nakryiko
2020-11-03 2:49 ` Song Liu
2020-11-03 5:25 ` Andrii Nakryiko
2020-11-03 5:59 ` Song Liu
2020-11-03 6:31 ` Andrii Nakryiko
2020-11-03 17:15 ` Song Liu
2020-11-03 5:10 ` Alexei Starovoitov
2020-11-03 6:27 ` Andrii Nakryiko
2020-11-03 17:55 ` Alexei Starovoitov
2020-10-29 0:59 ` [PATCH bpf-next 09/11] libbpf: accomodate DWARF/compiler bug with duplicated identical arrays Andrii Nakryiko
2020-11-03 2:52 ` Song Liu
2020-10-29 0:59 ` [PATCH bpf-next 10/11] selftests/bpf: add split BTF dedup selftests Andrii Nakryiko
2020-11-03 5:35 ` Song Liu
2020-11-03 6:05 ` Andrii Nakryiko
2020-11-03 6:30 ` Song Liu
2020-10-29 0:59 ` [PATCH bpf-next 11/11] tools/bpftool: add bpftool support for split BTF Andrii Nakryiko
2020-11-03 6:03 ` Song Liu
2020-10-30 0:33 ` [PATCH bpf-next 00/11] libbpf: split BTF support Song Liu
2020-10-30 2:33 ` Andrii Nakryiko
2020-10-30 6:45 ` Song Liu
2020-10-30 12:04 ` Alan Maguire
2020-10-30 18:30 ` Andrii Nakryiko
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=CAEf4Bzavxu80+P8N+rEzHTNetsKcPqWkMUafpyG6Bz-6EydwiA@mail.gmail.com \
--to=andrii.nakryiko@gmail.com \
--cc=Kernel-team@fb.com \
--cc=andrii@kernel.org \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@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;
as well as URLs for NNTP newsgroup(s).