ftrace: fix incorrect hash size in register_ftrace_direct()
PATCH 1/1 ftrace: fix incorrect hash size in register_ftrace_direct()
The max ftrace hash bits is made fls(32) in register_ftrace_direct(), which seems illogical, and it seems to be a spelling mistake.
Just fix it.
(Do I misunderstand something?)
--- kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/ftrace.c +1 -1
@@ -5914,7 +5914,7 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)/* Make a copy hash to place the new and the old entries in */ size = hash->count + direct_functions->count; -if (size >32 ) +if (size <32 ) size =32 ; new_hash =alloc_ftrace_hash (fls (size));if (!new_hash)
Signature · 1 line
2.39.5
Steven Rostedt
maintainerQuoted 6 lines · On Sat, 12 Apr 2025 21:33:48 +0800 Menglong Dong <[email protected]>…
The max ftrace hash bits is made fls(32) in
register_ftrace_direct(), which seems illogical, and it seems to be a spelling mistake.Just fix it.
(Do I misunderstand something?)
I think the logic is incorrect and this patch doesn't fix it.
Quoted 12 lines
Fixes d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")Signed-off-by Menglong Dong <[email protected]>--- kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/ftrace.c +0
-0
kernel/trace/ftrace.c int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr) · line 5920
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -5914,7 +5914,7 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)/* Make a copy hash to place the new and the old entries in */ size = hash->count + direct_functions->count; -if (size >32 ) +if (size <32 ) size =32 ; new_hash =alloc_ftrace_hash (fls (size));if (!new_hash)
The above probably should be:
size = hash->count + direct_functions->count
size = fls(size);
if (size > FTRACE_HASH_MAX_BITS)
size = FTRACE_HASH_MAX_BITS;
new_hash = alloc_ftrace_hash(size);-- Steve
Quoted 36 lines · Steven Rostedt
Quoted 6 lines · On Sat, 12 Apr 2025 21:33:48 +0800 Menglong Dong <[email protected]>…
The max ftrace hash bits is made fls(32) in
register_ftrace_direct(), which seems illogical, and it seems to be a spelling mistake.Just fix it.
(Do I misunderstand something?)
I think the logic is incorrect and this patch doesn't fix it.
Quoted 12 lines
Fixes d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")Signed-off-by Menglong Dong <[email protected]>--- kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr) · line 5920
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -5914,7 +5914,7 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)/* Make a copy hash to place the new and the old entries in */ size = hash->count + direct_functions->count; -if (size >32 ) +if (size <32 ) size =32 ; new_hash =alloc_ftrace_hash (fls (size));if (!new_hash)The above probably should be:
Quoted 5 lines
size = hash->count + direct_functions->count
size = fls(size);
if (size > FTRACE_HASH_MAX_BITS)
size = FTRACE_HASH_MAX_BITS;
new_hash = alloc_ftrace_hash(size);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 to avoid the hash bits being too small, just like the origin logic in "dup_hash"?
Thanks!
Menglong Dong
Quoted 4 lines
-- Steve
Quoted 44 lines · Menglong Dong
Quoted 36 lines · Steven Rostedt
Quoted 6 lines · On Sat, 12 Apr 2025 21:33:48 +0800 Menglong Dong <[email protected]>…
The max ftrace hash bits is made fls(32) in
register_ftrace_direct(), which seems illogical, and it seems to be a spelling mistake.Just fix it.
(Do I misunderstand something?)
I think the logic is incorrect and this patch doesn't fix it.
Quoted 12 lines
Fixes d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")Signed-off-by Menglong Dong <[email protected]>--- kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr) · line 5920
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -5914,7 +5914,7 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)/* Make a copy hash to place the new and the old entries in */ size = hash->count + direct_functions->count; -if (size >32 ) +if (size <32 ) size =32 ; new_hash =alloc_ftrace_hash (fls (size));if (!new_hash)The above probably should be:
Quoted 5 lines
size = hash->count + direct_functions->count size = fls(size); if (size > FTRACE_HASH_MAX_BITS) size = FTRACE_HASH_MAX_BITS; new_hash = alloc_ftrace_hash(size);
Quoted 4 lines
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 :/
Quoted 10 lines
to avoid the hash bits being too small, just like the origin logic in "
dup_hash"?Thanks!
Menglong DongQuoted 4 lines
-- Steve
Steven Rostedt
maintainerQuoted 10 lines · On Sat, 12 Apr 2025 22:36:56 +0800 Menglong Dong <[email protected]>…
Quoted 4 lines
Yeah, this seems to make more sense. And I'll send a V2 later.
BTW, Should we still keep the "size =
min(size, 32)" logicOops, I mean "size =
max(size, 32); size = fls(size);" here :/Quoted 3 lines
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
Quoted 25 lines · Steven Rostedt
Quoted 10 lines · On Sat, 12 Apr 2025 22:36:56 +0800 Menglong Dong <[email protected]>…
Quoted 4 lines
Yeah, this seems to make more sense. And I'll send a V2 later.
BTW, Should we still keep the "size =
min(size, 32)" logicOops, I mean "size =
max(size, 32); size = fls(size);" here :/Quoted 3 lines
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, ...);
Quoted 3 lines
Now you have 32 buckets for 5 functions. Why waste the memory?
If you add more functions, the hash bucket size will get updated.
Yeah, I see. The hash bucket will be reallocated when we add more functions to the direct_funtions, so it is not necessary to make the budget size large here.
Thanks!
Menglong Dong
Quoted 2 lines
-- Steve