rhashtable: Add rehash counter to bucket_table
authorHerbert Xu <herbert@gondor.apana.org.au>
Sat, 14 Mar 2015 02:57:24 +0000 (13:57 +1100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 15 Mar 2015 05:35:34 +0000 (01:35 -0400)
This patch adds a rehash counter to bucket_table to indicate
the last bucket that has been rehashed.  This serves two purposes:

1. Any bucket that has been rehashed can never gain a new object.
2. If the rehash counter reaches the size of the table, the table
will forever remain empty.

This patch also downsizes bucket_table->size to an unsigned int
since we do not support sizes greater than 32 bits yet.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/rhashtable.h
lib/rhashtable.c
lib/test_rhashtable.c

index a0abddd226b382d93062369cc87ae309ea4a5450..ed7562ad4ca0649e3798afa9abea73aaf68efb8e 100644 (file)
@@ -49,6 +49,7 @@ struct rhash_head {
 /**
  * struct bucket_table - Table of hash buckets
  * @size: Number of hash buckets
+ * @rehash: Current bucket being rehashed
  * @hash_rnd: Random seed to fold into hash
  * @shift: Current size (1 << shift)
  * @locks_mask: Mask to apply before accessing locks[]
@@ -58,7 +59,8 @@ struct rhash_head {
  * @buckets: size * hash buckets
  */
 struct bucket_table {
-       size_t                  size;
+       unsigned int            size;
+       unsigned int            rehash;
        u32                     hash_rnd;
        u32                     shift;
        unsigned int            locks_mask;
index 36fb0910bec21085b6f23bfe1847f05e816c398a..ff4ea1704546a25c9a2f88e0f387b0de4c6f5dd3 100644 (file)
@@ -260,6 +260,7 @@ static void rhashtable_rehash_chain(struct rhashtable *ht, unsigned old_hash)
        spin_lock_bh(old_bucket_lock);
        while (!rhashtable_rehash_one(ht, old_hash))
                ;
+       old_tbl->rehash++;
        spin_unlock_bh(old_bucket_lock);
 }
 
index 67c7593d1dd69c91f646e21e47b589c40c808837..16974fd89e4e854edabc9b66533b4e3da2e9ccba 100644 (file)
@@ -80,7 +80,7 @@ static void test_bucket_stats(struct rhashtable *ht, bool quiet)
                rcu_cnt = cnt = 0;
 
                if (!quiet)
-                       pr_info(" [%#4x/%zu]", i, tbl->size);
+                       pr_info(" [%#4x/%u]", i, tbl->size);
 
                rht_for_each_entry_rcu(obj, pos, tbl, i, node) {
                        cnt++;