git: ee44a57e34a8 - main - umtx: use a distribution-fair multiplier for the chain hash
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 31 Aug 2026 23:48:23 UTC
The branch main has been updated by nprice:
URL: https://cgit.FreeBSD.org/src/commit/?id=ee44a57e34a8812b4641d5c9202255ea7883764d
commit ee44a57e34a8812b4641d5c9202255ea7883764d
Author: Nick Price <nprice@FreeBSD.org>
AuthorDate: 2026-08-31 23:47:12 +0000
Commit: Nick Price <nprice@FreeBSD.org>
CommitDate: 2026-08-31 23:47:24 +0000
umtx: use a distribution-fair multiplier for the chain hash
umtxq_hash() multiplies the key by 0x9E370001 and keeps the high bits. That
constant is 0x9E37 * 2^16 + 1, so it degenerates for keys whose spacing carries
trailing zero bits: at a 64 KiB stride it puts 128 of 512 parked waiters onto a
single chain mutex, and at 16 KiB and up it uses only a handful of the 512
chains. Base-system consumers never hit this because libthr places its own wait
words 128 bytes apart, but a Linux-ABI runtime waiting on addresses it allocates
itself lands squarely on the floor. Switch to 0x61C88647, which leaves at most 3
waiters per chain at the same stride; Linux made this exact change in 2016, after
judging the sparse constants "actively bad for hashing".
Approved by: adrian (mentor)
Reviewed by: kib, adrian, emaste
Differential Revision: https://reviews.freebsd.org/D58337
Signed-off-by: Nick Price <nprice@FreeBSD.org>
---
sys/kern/kern_umtx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 69ea90ce9972..ac2469379690 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -113,7 +113,7 @@
(td)->td_user_pri <= PRI_MAX_TIMESHARE) ?\
PRI_MAX_TIMESHARE : (td)->td_user_pri)
-#define GOLDEN_RATIO_PRIME 2654404609U
+#define GOLDEN_RATIO_32 1640531527U
#ifndef UMTX_CHAINS
#define UMTX_CHAINS 512
#endif
@@ -380,7 +380,7 @@ umtxq_hash(struct umtx_key *key)
unsigned n;
n = (uintptr_t)key->info.both.a + key->info.both.b;
- key->hash = ((n * GOLDEN_RATIO_PRIME) >> UMTX_SHIFTS) % UMTX_CHAINS;
+ key->hash = ((n * GOLDEN_RATIO_32) >> UMTX_SHIFTS) % UMTX_CHAINS;
}
struct umtxq_chain *