diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2015-03-13 22:57:22 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-15 01:35:34 -0400 |
commit | 5269b53da4d432b0fbf755bd423c807bf6bd4aa0 (patch) | |
tree | 790a193e54c7c231c5835e18d555ba8248c11061 /lib/rhashtable.c | |
parent | 8f2484bdb55daa53ecaddb5fa4c298e3d262b69e (diff) |
rhashtable: Move seed init into bucket_table_alloc
It seems that I have already made every rehash redo the random
seed even though my commit message indicated otherwise :)
Since we have already taken that step, this patch goes one step
further and moves the seed initialisation into bucket_table_alloc.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/rhashtable.c')
-rw-r--r-- | lib/rhashtable.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 5d06cc2b1e4a..e55bbc84c449 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c | |||
@@ -142,7 +142,7 @@ static void bucket_table_free(const struct bucket_table *tbl) | |||
142 | } | 142 | } |
143 | 143 | ||
144 | static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, | 144 | static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, |
145 | size_t nbuckets, u32 hash_rnd) | 145 | size_t nbuckets) |
146 | { | 146 | { |
147 | struct bucket_table *tbl = NULL; | 147 | struct bucket_table *tbl = NULL; |
148 | size_t size; | 148 | size_t size; |
@@ -158,7 +158,6 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, | |||
158 | 158 | ||
159 | tbl->size = nbuckets; | 159 | tbl->size = nbuckets; |
160 | tbl->shift = ilog2(nbuckets); | 160 | tbl->shift = ilog2(nbuckets); |
161 | tbl->hash_rnd = hash_rnd; | ||
162 | 161 | ||
163 | if (alloc_bucket_locks(ht, tbl) < 0) { | 162 | if (alloc_bucket_locks(ht, tbl) < 0) { |
164 | bucket_table_free(tbl); | 163 | bucket_table_free(tbl); |
@@ -167,6 +166,8 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, | |||
167 | 166 | ||
168 | INIT_LIST_HEAD(&tbl->walkers); | 167 | INIT_LIST_HEAD(&tbl->walkers); |
169 | 168 | ||
169 | get_random_bytes(&tbl->hash_rnd, sizeof(tbl->hash_rnd)); | ||
170 | |||
170 | for (i = 0; i < nbuckets; i++) | 171 | for (i = 0; i < nbuckets; i++) |
171 | INIT_RHT_NULLS_HEAD(tbl->buckets[i], ht, i); | 172 | INIT_RHT_NULLS_HEAD(tbl->buckets[i], ht, i); |
172 | 173 | ||
@@ -264,8 +265,6 @@ static void rhashtable_rehash(struct rhashtable *ht, | |||
264 | struct rhashtable_walker *walker; | 265 | struct rhashtable_walker *walker; |
265 | unsigned old_hash; | 266 | unsigned old_hash; |
266 | 267 | ||
267 | get_random_bytes(&new_tbl->hash_rnd, sizeof(new_tbl->hash_rnd)); | ||
268 | |||
269 | /* Make insertions go into the new, empty table right away. Deletions | 268 | /* Make insertions go into the new, empty table right away. Deletions |
270 | * and lookups will be attempted in both tables until we synchronize. | 269 | * and lookups will be attempted in both tables until we synchronize. |
271 | * The synchronize_rcu() guarantees for the new table to be picked up | 270 | * The synchronize_rcu() guarantees for the new table to be picked up |
@@ -315,7 +314,7 @@ int rhashtable_expand(struct rhashtable *ht) | |||
315 | 314 | ||
316 | ASSERT_RHT_MUTEX(ht); | 315 | ASSERT_RHT_MUTEX(ht); |
317 | 316 | ||
318 | new_tbl = bucket_table_alloc(ht, old_tbl->size * 2, old_tbl->hash_rnd); | 317 | new_tbl = bucket_table_alloc(ht, old_tbl->size * 2); |
319 | if (new_tbl == NULL) | 318 | if (new_tbl == NULL) |
320 | return -ENOMEM; | 319 | return -ENOMEM; |
321 | 320 | ||
@@ -346,7 +345,7 @@ int rhashtable_shrink(struct rhashtable *ht) | |||
346 | 345 | ||
347 | ASSERT_RHT_MUTEX(ht); | 346 | ASSERT_RHT_MUTEX(ht); |
348 | 347 | ||
349 | new_tbl = bucket_table_alloc(ht, old_tbl->size / 2, old_tbl->hash_rnd); | 348 | new_tbl = bucket_table_alloc(ht, old_tbl->size / 2); |
350 | if (new_tbl == NULL) | 349 | if (new_tbl == NULL) |
351 | return -ENOMEM; | 350 | return -ENOMEM; |
352 | 351 | ||
@@ -926,7 +925,6 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params) | |||
926 | { | 925 | { |
927 | struct bucket_table *tbl; | 926 | struct bucket_table *tbl; |
928 | size_t size; | 927 | size_t size; |
929 | u32 hash_rnd; | ||
930 | 928 | ||
931 | size = HASH_DEFAULT_SIZE; | 929 | size = HASH_DEFAULT_SIZE; |
932 | 930 | ||
@@ -952,9 +950,7 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params) | |||
952 | else | 950 | else |
953 | ht->p.locks_mul = BUCKET_LOCKS_PER_CPU; | 951 | ht->p.locks_mul = BUCKET_LOCKS_PER_CPU; |
954 | 952 | ||
955 | get_random_bytes(&hash_rnd, sizeof(hash_rnd)); | 953 | tbl = bucket_table_alloc(ht, size); |
956 | |||
957 | tbl = bucket_table_alloc(ht, size, hash_rnd); | ||
958 | if (tbl == NULL) | 954 | if (tbl == NULL) |
959 | return -ENOMEM; | 955 | return -ENOMEM; |
960 | 956 | ||