Re: [PATCH bpf] ftrace: fix incorrect hash size in register_ftrace_direct()

From: Steven Rostedt
Date: Sat Apr 12 2025 - 10:45:30 EST


On Sat, 12 Apr 2025 22:36:56 +0800
Menglong Dong <menglong8.dong@xxxxxxxxx> wrote:

> > Yeah, this seems to make more sense. And I'll send a V2
> > later.
> >
> > BTW, Should we still keep the "size = min(size, 32)" logic
>
> Oops, I mean "size = max(size, 32); size = fls(size);" here :/
>
> > to avoid the hash bits being too small, just like the origin
> > logic in "dup_hash"?
> >

If you have 5 functions, why do you need more that 5 buckets?

size = 5;
size = max(5, 32); // size = 32
size = fls(size); // size = 5
alloc_ftrace_hash(size);

size = 1 << size; // size = 32
hash->buckets = kcalloc(size, ...);

Now you have 32 buckets for 5 functions. Why waste the memory?

If you add more functions, the hash bucket size will get updated.

-- Steve