From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Mykyta Yatsenko" <mykyta.yatsenko5@gmail.com>,
"Hao Peng" <flyingpenghao@gmail.com>
Cc: <andrii@kernel.org>, <bpf@vger.kernel.org>, <yatsenko@meta.com>
Subject: Re: [PATCH] bpf: Mix the seed into 8-byte resizable hashtab keys before folding
Date: Sat, 05 Dec 2026 04:30:41 +0000 [thread overview]
Message-ID: <DNCIMB13WU4G.W6ZYJBTTNF5O@gmail.com> (raw)
In-Reply-To: <b90f47a7-4547-4656-9b72-be3dbfc1b2dd@gmail.com>
On Thu, Dec 03, 2026 at 09:55 PM Mykyta Yatsenko <mykyta.yatsenko5@gmail.com> wrote:
> I tried this variant:
> static __always_inline u32 rhtab_hashfn_long(const void *data, u32 len, u32 seed)
> {
> u64 k = *(const unsigned long *)data;
> u64 x = ((k >> 3) ^ seed) * GOLDEN_RATIO_64;
>
> return (u32)swab64(x) ^ (k & 7);
> }
yep. Even better.
All bits of k >> 3 reach the top byte of the product.
swab64() moves that byte to the low bits of the hash, and
rht_bucket_index() takes those.
> keys max/nr xor jhash GR Alexei GR swap
> seq 1M/750K 76.91 19.07 (-75.2%) 48.72 (-36.7%) 48.70 (-36.7%)
> seq 1M/1M 76.12 16.52 (-78.3%) 44.74 (-41.2%) 47.19 (-38.0%)
I think it's almost there. not quite xor, but clearly better than jhash.
Could you do one more experiment and keep 6 bits of the key instead of 3 ?
u64 x = ((k >> 6) ^ seed) * GOLDEN_RATIO_64;
return (u32)swab64(x) ^ (k & 63);
Then 64 sequential keys use 8 cache lines in a row
and hopefully hw prefetcher will do its job.
prev parent reply other threads:[~2026-12-05 4:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 14:03 [PATCH] bpf: Mix the seed into 8-byte resizable hashtab keys before folding Peng Hao
2026-12-01 3:17 ` Alexei Starovoitov
2026-12-02 4:09 ` Hao Peng
2026-12-02 6:29 ` Mykyta Yatsenko
2026-12-03 4:03 ` Alexei Starovoitov
2026-12-04 1:11 ` Hao Peng
2026-12-04 1:35 ` Alexei Starovoitov
2026-12-04 5:55 ` Mykyta Yatsenko
2026-12-05 4:30 ` Alexei Starovoitov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DNCIMB13WU4G.W6ZYJBTTNF5O@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=flyingpenghao@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=yatsenko@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox