public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: William Lee Irwin III <wli@holomorphy.com>
To: linux-kernel@vger.kernel.org
Subject: Re: hashed waitqueues
Date: Fri, 4 Jan 2002 17:39:23 -0800	[thread overview]
Message-ID: <20020104173923.B10391@holomorphy.com> (raw)
In-Reply-To: <20020104094049.A10326@holomorphy.com> <E16MeqE-0001Ea-00@starship.berlin>
In-Reply-To: <E16MeqE-0001Ea-00@starship.berlin>; from phillips@bonn-fries.net on Sat, Jan 05, 2002 at 01:37:40AM +0100

On January 4, 2002 06:40 pm, William Lee Irwin III wrote:
+       unsigned long hash = (unsigned long)page;

On Sat, Jan 05, 2002 at 01:37:40AM +0100, Daniel Phillips wrote:
> Just to be anal here, 'long' doesn't add anything useful to this 
> declaration.  In fact, u32 is what you want since you've chosen your 
> multiplier with a 32 bit register in mind - on 64bit arch I think you'll get 
> distinctly non-random results as it stands.

On January 4, 2002 06:40 pm, William Lee Irwin III wrote:
+	hash *= GOLDEN_RATIO_PRIME;
+	hash >>= BITS_PER_LONG - zone->wait_table_bits;
+	hash &= zone->wait_table_size - 1;

On Sat, Jan 05, 2002 at 01:37:40AM +0100, Daniel Phillips wrote:
> Nice hash!  For arches with expensive multiplies you might want to look 
> for a near-golden ratio multiplier that has a simple contruction in terms of 
> 1's & 0's so it can be computed with 2 or 3 shift-adds, dumping the 
> efficiency problem on the compiler.  You don't have to restrict your search 
> to the neighbourhood of 32 bits, you can go a few bits less than that and 
> substract from a smaller value than BITS_PER_LONG (actually, you should just 
> write '32' there, since that's what you really have in mind).

For 64-bit machines an entirely different multiplier should be used,
one with p/2^64 approximately phi. And I'd rather see something like:

	hash   = (unsigned long)pages;
	hash  *= GOLDEN_RATIO_PRIME;
	hash >>= zone->wait_table_shift;

with no masking, since the above shift should be initialized so as
to annihilate all the high-order bits above where the table's page
size should be. On the other hand, shifting all the way may not be
truly optimal, and so it may be better to mask with a smaller shift.

2 or 3 shift/adds is really not possible, the population counts of the
primes in those ranges tends to be high, much to my chagrin. I actually
tried unrolling it by hand a few times, and it was slower than
multiplication on i386 (and uncomfortably lengthy). So Fibonacci
hashing may well not be the best strategy for architectures without
hardware integer multiplies.

I believe to address architectures where multiplication is prohibitively
expensive I should do some reading to determine a set of theoretically
sound candidates for non-multiplicative hash functions and benchmark them.
Knuth has some general rules about design but I would rather merely test
some already verified by someone else and use the one that benches best
than duplicate the various historical efforts to find good hash functions.


Cheers,
Bill

  reply	other threads:[~2002-01-05  1:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-04 17:40 hashed waitqueues William Lee Irwin III
2002-01-04 21:47 ` Momchil Velikov
2002-01-04 23:07 ` Andrew Morton
2002-01-04 23:21   ` Andrew Morton
2002-01-04 23:48   ` William Lee Irwin III
2002-01-05  0:37 ` Daniel Phillips
2002-01-05  1:39   ` William Lee Irwin III [this message]
2002-01-05  2:44     ` Daniel Phillips
2002-01-05  5:06       ` William Lee Irwin III
2002-01-08 18:20         ` William Lee Irwin III
2002-01-08 18:27           ` William Lee Irwin III
     [not found]             ` <523d1gu1ni.fsf@love-boat.topspincom.com>
2002-01-08 18:44               ` William Lee Irwin III
2002-01-08 19:20           ` Hugh Dickins
2002-01-08 20:19             ` William Lee Irwin III
2002-01-16 14:21     ` Jamie Lokier
2002-01-16 17:42       ` William Lee Irwin III
2002-01-18  0:34         ` Jamie Lokier
2002-01-06 21:09 ` Rik van Riel
  -- strict thread matches above, loose matches on Subject: below --
2002-01-04 21:17 Ed Tomlinson

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=20020104173923.B10391@holomorphy.com \
    --to=wli@holomorphy.com \
    --cc=linux-kernel@vger.kernel.org \
    /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