aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2015-01-02 17:00:17 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-03 14:32:57 -0500
commitb8e1943e9f754219bcfb40bac4a605b5348acb25 (patch)
treea80b48e78a57a10ace266997f65f754034cce083 /lib
parent88d6ed15acff1cb44b1d1f3c0a393b7f7744957a (diff)
rhashtable: Factor out bucket_tail() function
Subsequent patches will require access to the bucket tail. Access to the tail is relatively cheap as the automatic resizing of the table should keep the number of entries per bucket to no more than 0.75 on average. Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/rhashtable.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index ce450d095fdf..0bd29c178910 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -83,6 +83,18 @@ static u32 head_hashfn(const struct rhashtable *ht,
83 return rht_bucket_index(tbl, obj_raw_hashfn(ht, rht_obj(ht, he))); 83 return rht_bucket_index(tbl, obj_raw_hashfn(ht, rht_obj(ht, he)));
84} 84}
85 85
86static struct rhash_head __rcu **bucket_tail(struct bucket_table *tbl, u32 n)
87{
88 struct rhash_head __rcu **pprev;
89
90 for (pprev = &tbl->buckets[n];
91 rht_dereference_bucket(*pprev, tbl, n);
92 pprev = &rht_dereference_bucket(*pprev, tbl, n)->next)
93 ;
94
95 return pprev;
96}
97
86static struct bucket_table *bucket_table_alloc(size_t nbuckets) 98static struct bucket_table *bucket_table_alloc(size_t nbuckets)
87{ 99{
88 struct bucket_table *tbl; 100 struct bucket_table *tbl;
@@ -266,7 +278,6 @@ EXPORT_SYMBOL_GPL(rhashtable_expand);
266int rhashtable_shrink(struct rhashtable *ht) 278int rhashtable_shrink(struct rhashtable *ht)
267{ 279{
268 struct bucket_table *ntbl, *tbl = rht_dereference(ht->tbl, ht); 280 struct bucket_table *ntbl, *tbl = rht_dereference(ht->tbl, ht);
269 struct rhash_head __rcu **pprev;
270 unsigned int i; 281 unsigned int i;
271 282
272 ASSERT_RHT_MUTEX(ht); 283 ASSERT_RHT_MUTEX(ht);
@@ -286,15 +297,9 @@ int rhashtable_shrink(struct rhashtable *ht)
286 */ 297 */
287 for (i = 0; i < ntbl->size; i++) { 298 for (i = 0; i < ntbl->size; i++) {
288 ntbl->buckets[i] = tbl->buckets[i]; 299 ntbl->buckets[i] = tbl->buckets[i];
300 RCU_INIT_POINTER(*bucket_tail(ntbl, i),
301 tbl->buckets[i + ntbl->size]);
289 302
290 /* Link each bucket in the new table to the first bucket
291 * in the old table that contains entries which will hash
292 * to the new bucket.
293 */
294 for (pprev = &ntbl->buckets[i]; *pprev != NULL;
295 pprev = &rht_dereference_bucket(*pprev, ntbl, i)->next)
296 ;
297 RCU_INIT_POINTER(*pprev, tbl->buckets[i + ntbl->size]);
298 } 303 }
299 304
300 /* Publish the new, valid hash table */ 305 /* Publish the new, valid hash table */