ftrace: Simplify the hash calculation
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Tue, 6 Oct 2020 00:21:14 +0000 (20:21 -0400)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 8 Oct 2020 19:29:06 +0000 (15:29 -0400)
No need to add a check to subtract the number of bits if bits is zero after
fls(). Just divide the size by two before calling it. This does give the
same answer for size of 0 and 1, but that's fine.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index 5633d37d880659b9b189a58ad55506bff040c6d2..c51a91aea1fd97bc7d6fcb0b25e8fd864bc9913c 100644 (file)
@@ -1368,11 +1368,10 @@ static struct ftrace_hash *dup_hash(struct ftrace_hash *src, int size)
        int i;
 
        /*
-        * Make the hash size about 1/2 the # found
+        * Use around half the size (max bit of it), but
+        * a minimum of 2 is fine (as size of 0 or 1 both give 1 for bits).
         */
-       bits = fls(size);
-       if (bits)
-               bits--;
+       bits = fls(size / 2);
 
        /* Don't allocate too much */
        if (bits > FTRACE_HASH_MAX_BITS)