Skip to content

Commit dc4729e

Browse files
committed
hash: cleanups
- Use __hash_u64() for __fill_random_buffer() - Convert rdma to use GOLDEN_RATIO_64 That's the last user of GOLDEN_RATIO_PRIME, which due to bit sparseness isn't really useful for our purposes. Signed-off-by: Jens Axboe <[email protected]>
1 parent aa75fc9 commit dc4729e

File tree

3 files changed

+2
-28
lines changed

3 files changed

+2
-28
lines changed

Diff for: engines/rdma.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ static int fio_rdmaio_setup(struct thread_data *td)
13891389
rd = malloc(sizeof(*rd));
13901390

13911391
memset(rd, 0, sizeof(*rd));
1392-
init_rand_seed(&rd->rand_state, (unsigned int) GOLDEN_RATIO_PRIME, 0);
1392+
init_rand_seed(&rd->rand_state, (unsigned int) GOLDEN_RATIO_64, 0);
13931393
td->io_ops_data = rd;
13941394
}
13951395

Diff for: hash.h

-26
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,6 @@
99
(C) 2002 William Lee Irwin III, IBM */
1010

1111
/*
12-
* Knuth recommends primes in approximately golden ratio to the maximum
13-
* integer representable by a machine word for multiplicative hashing.
14-
* Chuck Lever verified the effectiveness of this technique:
15-
* http://www.citi.umich.edu/techreports/reports/citi-tr-00-1.pdf
16-
*
17-
* These primes are chosen to be bit-sparse, that is operations on
18-
* them can use shifts and additions instead of multiplications for
19-
* machines where multiplications are slow.
20-
*/
21-
22-
#if BITS_PER_LONG == 32
23-
/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
24-
#define GOLDEN_RATIO_PRIME 0x9e370001UL
25-
#elif BITS_PER_LONG == 64
26-
/* 2^63 + 2^61 - 2^57 + 2^54 - 2^51 - 2^18 + 1 */
27-
#define GOLDEN_RATIO_PRIME 0x9e37fffffffc0001UL
28-
#else
29-
#error Define GOLDEN_RATIO_PRIME for your wordsize.
30-
#endif
31-
32-
/*
33-
* The above primes are actively bad for hashing, since they are
34-
* too sparse. The 32-bit one is mostly ok, the 64-bit one causes
35-
* real problems. Besides, the "prime" part is pointless for the
36-
* multiplicative hash.
37-
*
3812
* Although a random odd number will do, it turns out that the golden
3913
* ratio phi = (sqrt(5)-1)/2, or its negative, has particularly nice
4014
* properties.

Diff for: lib/rand.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void __fill_random_buf(void *buf, unsigned int len, uint64_t seed)
103103

104104
for (; b != e; ++b) {
105105
*b = seed;
106-
seed *= GOLDEN_RATIO_64;
106+
seed = __hash_u64(seed);
107107
}
108108

109109
if (fio_unlikely(rest))

0 commit comments

Comments
 (0)