On Wednesday, July 16, 2025 1:20 AM Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> write: > On Mon, Jul 14, 2025 at 9:41 PM Menglong Dong <menglong.dong@xxxxxxxxx> wrote: > > > > > > On 7/15/25 06:07, Andrii Nakryiko wrote: > > > On Thu, Jul 3, 2025 at 5:22 AM Menglong Dong <menglong8.dong@xxxxxxxxx> wrote: > > >> For now, the libbpf find the btf type id by loop all the btf types and > > >> compare its name, which is inefficient if we have many functions to > > >> lookup. > > >> > > >> We add the "use_hash" to the function args of find_kernel_btf_id() to > > >> indicate if we should lookup the btf type id by hash. The hash table will > > >> be initialized if it has not yet. > > > Or we could build hashtable-based index outside of struct btf for a > > > specific use case, because there is no one perfect hashtable-based > > > indexing that can be done generically (e.g., just by name, or > > > name+kind, or kind+name, or some more complicated lookup key) and > > > cover all potential use cases. I'd prefer not to get into a problem of > > > defining and building indexes and leave it to callers (even if the > > > caller is other part of libbpf itself). > > > > > > I think that works. We can define a global hash table in libbpf.c, > > and add all the btf type to it. I'll redesign this part, and make it > > separate with the btf. > > No global things, please. It can be held per-bpf_object, or even > constructed on demand during attachment and then freed. No need for > anything global. Okay, the per-bpf_object is a good idea, and I'll try to implement it this way. Thanks! Menglong Dong