Re: [PATCH v2] ext4: improve str2hashbuf by processing 4-byte chunks and removing function pointers

From: Theodore Tso

Date: Thu Apr 09 2026 - 10:13:57 EST


On Sat, Nov 22, 2025 at 12:39:29PM +0800, Guan-Chun Wu wrote:
> The original byte-by-byte implementation with modulo checks is less
> efficient. Refactor str2hashbuf_unsigned() and str2hashbuf_signed()
> to process input in explicit 4-byte chunks instead of using a
> modulus-based loop to emit words byte by byte.
>
> Additionally, the use of function pointers for selecting the appropriate
> str2hashbuf implementation has been removed. Instead, the functions are
> directly invoked based on the hash type, eliminating the overhead of
> dynamic function calls.
>
> Performance test (x86_64, Intel Core i7-10700 @ 2.90GHz, average over 10000
> runs, using kernel module for testing):
>
> len | orig_s | new_s | orig_u | new_u
> ----+--------+-------+--------+-------
> 1 | 70 | 71 | 63 | 63
> 8 | 68 | 64 | 64 | 62
> 32 | 75 | 70 | 75 | 63
> 64 | 96 | 71 | 100 | 68
> 255 | 192 | 108 | 187 | 84
>
> This change improves performance, especially for larger input sizes.
>
> Signed-off-by: Guan-Chun Wu <409411716@xxxxxxxxxxxxxx>

Apologies for the delay in looking at this. It fell through the
cracks on my end.

Because of how I'm a bit late with reviewing patches before the merge
window, I'm going to be very conservative in which patches I'm going
to land. So this is going to be deferred until the next cycle, but I
wanted to let you know that I haven't forgotten about it.

If this was a comprehensive set of Kunit tests for fs/ext4/hash.c, I
might have taken it. And that's something that I would look at adding
for the next cycle, but if you'd be interested in creating the kunit
tests for hash.c, that would be great.

- Ted