rhashtable: Free bucket tables asynchronously after rehash
authorHerbert Xu <herbert@gondor.apana.org.au>
Sat, 14 Mar 2015 02:57:23 +0000 (13:57 +1100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 15 Mar 2015 05:35:34 +0000 (01:35 -0400)
There is in fact no need to wait for an RCU grace period in the
rehash function, since all insertions are guaranteed to go into
the new table through spin locks.

This patch uses call_rcu to free the old/rehashed table at our
leisure.

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

index 4192682c1d5c3681d063e999fe4d150c8fded4b1..a0abddd226b382d93062369cc87ae309ea4a5450 100644 (file)
@@ -54,6 +54,7 @@ struct rhash_head {
  * @locks_mask: Mask to apply before accessing locks[]
  * @locks: Array of spinlocks protecting individual buckets
  * @walkers: List of active walkers
+ * @rcu: RCU structure for freeing the table
  * @buckets: size * hash buckets
  */
 struct bucket_table {
@@ -63,6 +64,7 @@ struct bucket_table {
        unsigned int            locks_mask;
        spinlock_t              *locks;
        struct list_head        walkers;
+       struct rcu_head         rcu;
 
        struct rhash_head __rcu *buckets[] ____cacheline_aligned_in_smp;
 };
index e55bbc84c4494640123da0b2e58d1c470c075f73..36fb0910bec21085b6f23bfe1847f05e816c398a 100644 (file)
@@ -141,6 +141,11 @@ static void bucket_table_free(const struct bucket_table *tbl)
        kvfree(tbl);
 }
 
+static void bucket_table_free_rcu(struct rcu_head *head)
+{
+       bucket_table_free(container_of(head, struct bucket_table, rcu));
+}
+
 static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
                                               size_t nbuckets)
 {
@@ -288,9 +293,7 @@ static void rhashtable_rehash(struct rhashtable *ht,
         * table, and thus no references to the old table will
         * remain.
         */
-       synchronize_rcu();
-
-       bucket_table_free(old_tbl);
+       call_rcu(&old_tbl->rcu, bucket_table_free_rcu);
 }
 
 /**