aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rhashtable.c
diff options
context:
space:
mode:
authorYing Xue <ying.xue@windriver.com>2015-01-07 00:41:56 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-08 22:47:11 -0500
commitc0c09bfdc4150b3918526660768585cd477adf35 (patch)
treeb314052625dceb2550c4b3c4b57ed609896127a6 /lib/rhashtable.c
parentbd6d4db552ceb52fb19890a454836dcda59743ce (diff)
rhashtable: avoid unnecessary wakeup for worker queue
Move condition statements of verifying whether hash table size exceeds its maximum threshold or reaches its minimum threshold from resizing functions to resizing decision functions, avoiding unnecessary wakeup for worker queue thread. Signed-off-by: Ying Xue <ying.xue@windriver.com> Cc: Thomas Graf <tgraf@suug.ch> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/rhashtable.c')
-rw-r--r--lib/rhashtable.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 1aef942976fe..7fb474b18f1b 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -199,7 +199,8 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
199bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size) 199bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size)
200{ 200{
201 /* Expand table when exceeding 75% load */ 201 /* Expand table when exceeding 75% load */
202 return atomic_read(&ht->nelems) > (new_size / 4 * 3); 202 return atomic_read(&ht->nelems) > (new_size / 4 * 3) &&
203 (ht->p.max_shift && atomic_read(&ht->shift) < ht->p.max_shift);
203} 204}
204EXPORT_SYMBOL_GPL(rht_grow_above_75); 205EXPORT_SYMBOL_GPL(rht_grow_above_75);
205 206
@@ -211,7 +212,8 @@ EXPORT_SYMBOL_GPL(rht_grow_above_75);
211bool rht_shrink_below_30(const struct rhashtable *ht, size_t new_size) 212bool rht_shrink_below_30(const struct rhashtable *ht, size_t new_size)
212{ 213{
213 /* Shrink table beneath 30% load */ 214 /* Shrink table beneath 30% load */
214 return atomic_read(&ht->nelems) < (new_size * 3 / 10); 215 return atomic_read(&ht->nelems) < (new_size * 3 / 10) &&
216 (atomic_read(&ht->shift) > ht->p.min_shift);
215} 217}
216EXPORT_SYMBOL_GPL(rht_shrink_below_30); 218EXPORT_SYMBOL_GPL(rht_shrink_below_30);
217 219
@@ -318,14 +320,11 @@ int rhashtable_expand(struct rhashtable *ht)
318 320
319 ASSERT_RHT_MUTEX(ht); 321 ASSERT_RHT_MUTEX(ht);
320 322
321 if (ht->p.max_shift && ht->shift >= ht->p.max_shift)
322 return 0;
323
324 new_tbl = bucket_table_alloc(ht, old_tbl->size * 2); 323 new_tbl = bucket_table_alloc(ht, old_tbl->size * 2);
325 if (new_tbl == NULL) 324 if (new_tbl == NULL)
326 return -ENOMEM; 325 return -ENOMEM;
327 326
328 ht->shift++; 327 atomic_inc(&ht->shift);
329 328
330 /* Make insertions go into the new, empty table right away. Deletions 329 /* Make insertions go into the new, empty table right away. Deletions
331 * and lookups will be attempted in both tables until we synchronize. 330 * and lookups will be attempted in both tables until we synchronize.
@@ -421,9 +420,6 @@ int rhashtable_shrink(struct rhashtable *ht)
421 420
422 ASSERT_RHT_MUTEX(ht); 421 ASSERT_RHT_MUTEX(ht);
423 422
424 if (ht->shift <= ht->p.min_shift)
425 return 0;
426
427 new_tbl = bucket_table_alloc(ht, tbl->size / 2); 423 new_tbl = bucket_table_alloc(ht, tbl->size / 2);
428 if (new_tbl == NULL) 424 if (new_tbl == NULL)
429 return -ENOMEM; 425 return -ENOMEM;
@@ -462,7 +458,7 @@ int rhashtable_shrink(struct rhashtable *ht)
462 458
463 /* Publish the new, valid hash table */ 459 /* Publish the new, valid hash table */
464 rcu_assign_pointer(ht->tbl, new_tbl); 460 rcu_assign_pointer(ht->tbl, new_tbl);
465 ht->shift--; 461 atomic_dec(&ht->shift);
466 462
467 /* Wait for readers. No new readers will have references to the 463 /* Wait for readers. No new readers will have references to the
468 * old hash table. 464 * old hash table.
@@ -851,7 +847,7 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
851 if (tbl == NULL) 847 if (tbl == NULL)
852 return -ENOMEM; 848 return -ENOMEM;
853 849
854 ht->shift = ilog2(tbl->size); 850 atomic_set(&ht->shift, ilog2(tbl->size));
855 RCU_INIT_POINTER(ht->tbl, tbl); 851 RCU_INIT_POINTER(ht->tbl, tbl);
856 RCU_INIT_POINTER(ht->future_tbl, tbl); 852 RCU_INIT_POINTER(ht->future_tbl, tbl);
857 853