From: Andrew Morton <akpm@osdl.org>
To: NeilBrown <neilb@suse.de>
Cc: linux-kernel@vger.kernel.org, wli@holomorphy.com
Subject: Re: [PATCH-RFC] Improve randomness of hash_long on 64bit.
Date: Thu, 11 May 2006 00:35:56 -0700 [thread overview]
Message-ID: <20060511003556.5ba2e3d2.akpm@osdl.org> (raw)
In-Reply-To: <1060509065940.10406@suse.de>
NeilBrown <neilb@suse.de> wrote:
>
> I'm still bothered by the poor showing on hash_long on 64bit
> on number that differ only in the 3rd or 4th byte (as IP addresses might
> on a little-endian host).
> I hacked around the problem in net/sunrpc/svcauth_unix.c until this
> issue got resolved, but it never did. So I am pushing again.
>
> The problem is that the bit-spares prime that is close to the
> golden ratio isn't really close enough.
>
> I propose 'fixing' it by using hash_u32 on the upper and lower halfs
> of a 64bit value. This is slightly less efficient, but most code would
> probably be happy calling hash_u32 anyway.
We end up with
static inline u32 hash_u32(u32 val, unsigned int bits)
{
u32 hash = val;
/* On some cpus multiply is faster, on others gcc will do shifts */
hash *= GOLDEN_RATIO_PRIME_32;
/* High bits are more random, so use them. */
return hash >> (32 - bits);
}
static inline u32 hash_u64(u64 val, unsigned int bits)
{
u32 hi = val >> 32;
return hash_u32(hash_u32(val, 32) ^ hi, bits);
}
So if one does
hash_u64(foo, 44)
we have a negative shift distance.
next prev parent reply other threads:[~2006-05-11 7:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060509165610.10378.patches@notabene>
2006-05-09 6:59 ` NeilBrown
2006-05-11 7:35 ` Andrew Morton [this message]
2006-05-11 9:51 ` Neil Brown
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=20060511003556.5ba2e3d2.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
--cc=wli@holomorphy.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
all inboxes | Powered by JetHome®