From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Peng Hao" <flyingpenghao@gmail.com>, <ast@kernel.org>,
<andrii@kernel.org>
Cc: <bpf@vger.kernel.org>
Subject: Re: [PATCH] bpf: Mix the seed into 8-byte resizable hashtab keys before folding
Date: Tue, 01 Dec 2026 03:17:38 +0000 [thread overview]
Message-ID: <DN92K6ZOESRF.3F4B146XQP25R@gmail.com> (raw)
In-Reply-To: <20261130140332.80373-1-flyingpeng@tencent.com>
On Mon Nov 30, 2026 at 2:03 PM UTC, Peng Hao wrote:
> rhtab_hashfn_long() folds the two halves of the key together and only
> then XORs in the seed:
>
> return (u32)(k ^ (k >> 32)) ^ seed;
>
> Two keys that fold to the same value therefore collide under every seed,
> so rhashtable's defence against long chains, a rehash with a new seed,
> can't separate them. Keys with equal halves all hash to the seed itself;
> bpf_get_current_pid_tgid() of a single-threaded task is such a key.
>
> Inserting 20000 keys of the form (i << 32 | i) into a
> BPF_MAP_TYPE_RHASH map with max_entries 40000 on arm64:
>
> random n=20000 insert 0.285s lookup 0.154s (7.7 us/lookup) insert failures 0
> collide n=20000 insert 3.896s lookup 2.460s (123.0 us/lookup) insert failures 18447 [Device or resource busy x18447]
>
> Almost all inserts fail with -EBUSY once the chain is too long and the
> rehash doesn't help, and lookups of the keys that did go in degrade to a
> linear scan of one bucket.
>
> Use jhash_2words(), as htab_map_hash() does for 8-byte keys, so that the
> seed affects every bit of the result.
>
> Fixes: 9dcbb5045fe5 ("bpf: Optimize word-sized keys for resizable hashtable")
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>
> ---
> kernel/bpf/hashtab.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index a2d0bfd4c3ec..6cdd8e1dc2bd 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -3029,7 +3029,7 @@ static __always_inline u32 rhtab_hashfn_long(const void *data, u32 len, u32 seed
> {
> u64 k = *(const unsigned long *)data;
>
> - return (u32)(k ^ (k >> 32)) ^ seed;
> + return jhash_2words((u32)k, (u32)(k >> 32), seed);
Looks like real issue, but please benchmark it first and cc Mykyta.
pw-bot: cr
prev parent reply other threads:[~2026-12-01 3:17 UTC|newest]
Thread overview: 2+ 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 [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=DN92K6ZOESRF.3F4B146XQP25R@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=flyingpenghao@gmail.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