lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAErzpmtgFGVdy69O6jLvPRvp4sy1E_u=Hi+CkLC+se6UNDyS7g@mail.gmail.com>
Date: Fri, 19 Dec 2025 13:42:04 +0800
From: Donglin Peng <dolinux.peng@...il.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: ast@...nel.org, eddyz87@...il.com, zhangxiaoqin@...omi.com, 
	ihor.solodrai@...ux.dev, linux-kernel@...r.kernel.org, bpf@...r.kernel.org, 
	pengdonglin <pengdonglin@...omi.com>, Alan Maguire <alan.maguire@...cle.com>
Subject: Re: [PATCH bpf-next v10 10/13] libbpf: Optimize the performance of determine_ptr_size

On Fri, Dec 19, 2025 at 8:03 AM Andrii Nakryiko
<andrii.nakryiko@...il.com> wrote:
>
> On Thu, Dec 18, 2025 at 3:31 AM Donglin Peng <dolinux.peng@...il.com> wrote:
> >
> > From: pengdonglin <pengdonglin@...omi.com>
> >
> > Leverage the performance improvement of btf__find_by_name_kind() when
> > BTF is sorted. For sorted BTF, the function uses binary search with
> > O(log n) complexity instead of linear search, providing significant
> > performance benefits, especially for large BTF like vmlinux.
> >
> > Cc: Eduard Zingerman <eddyz87@...il.com>
> > Cc: Alexei Starovoitov <ast@...nel.org>
> > Cc: Andrii Nakryiko <andrii.nakryiko@...il.com>
> > Cc: Alan Maguire <alan.maguire@...cle.com>
> > Cc: Ihor Solodrai <ihor.solodrai@...ux.dev>
> > Cc: Xiaoqin Zhang <zhangxiaoqin@...omi.com>
> > Signed-off-by: pengdonglin <pengdonglin@...omi.com>
> > ---
> >  tools/lib/bpf/btf.c | 20 ++++++--------------
> >  1 file changed, 6 insertions(+), 14 deletions(-)
> >
>
> nice and clean

Thank you.

>
> Acked-by: Andrii Nakryiko <andrii@...nel.org>
>
> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index c63d46b7d74b..b5b0898d033d 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -659,29 +659,21 @@ static int determine_ptr_size(const struct btf *btf)
> >                 "int long unsigned",
> >         };
> >         const struct btf_type *t;
> > -       const char *name;
> > -       int i, j, n;
> > +       int i, id;
> >
> >         if (btf->base_btf && btf->base_btf->ptr_sz > 0)
> >                 return btf->base_btf->ptr_sz;
> >
> > -       n = btf__type_cnt(btf);
> > -       for (i = 1; i < n; i++) {
> > -               t = btf__type_by_id(btf, i);
> > -               if (!btf_is_int(t))
> > +       for (i = 0; i < ARRAY_SIZE(long_aliases); i++) {
> > +               id = btf__find_by_name_kind(btf, long_aliases[i], BTF_KIND_INT);
> > +               if (id < 0)
> >                         continue;
> >
> > +               t = btf__type_by_id(btf, id);
> >                 if (t->size != 4 && t->size != 8)
> >                         continue;
> >
> > -               name = btf__name_by_offset(btf, t->name_off);
> > -               if (!name)
> > -                       continue;
> > -
> > -               for (j = 0; j < ARRAY_SIZE(long_aliases); j++) {
> > -                       if (strcmp(name, long_aliases[j]) == 0)
> > -                               return t->size;
> > -               }
> > +               return t->size;
> >         }
> >
> >         return -1;
> > --
> > 2.34.1
> >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ