Skip to content

Commit 54c5b7d

Browse files
ying-xuedavem330
authored andcommitted
rhashtable: introduce rhashtable_wakeup_worker helper function
Introduce rhashtable_wakeup_worker() helper function to reduce duplicated code where to wake up worker. By the way, as long as the both "future_tbl" and "tbl" bucket table pointers point to the same bucket array, we should try to wake up the resizing worker thread, otherwise, it indicates the work of resizing hash table is not finished yet. However, currently we will wake up the worker thread only when the two pointers point to different bucket array. Obviously this is wrong. So, the issue is also fixed as well in the patch. Signed-off-by: Ying Xue <[email protected]> Cc: Thomas Graf <[email protected]> Acked-by: Thomas Graf <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent efb975a commit 54c5b7d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/rhashtable.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,19 @@ static void rht_deferred_worker(struct work_struct *work)
492492
mutex_unlock(&ht->mutex);
493493
}
494494

495+
static void rhashtable_wakeup_worker(struct rhashtable *ht)
496+
{
497+
struct bucket_table *tbl = rht_dereference_rcu(ht->tbl, ht);
498+
struct bucket_table *new_tbl = rht_dereference_rcu(ht->future_tbl, ht);
499+
size_t size = tbl->size;
500+
501+
/* Only adjust the table if no resizing is currently in progress. */
502+
if (tbl == new_tbl &&
503+
((ht->p.grow_decision && ht->p.grow_decision(ht, size)) ||
504+
(ht->p.shrink_decision && ht->p.shrink_decision(ht, size))))
505+
schedule_delayed_work(&ht->run_work, 0);
506+
}
507+
495508
/**
496509
* rhashtable_insert - insert object into hash hash table
497510
* @ht: hash table
@@ -532,10 +545,7 @@ void rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj)
532545

533546
atomic_inc(&ht->nelems);
534547

535-
/* Only grow the table if no resizing is currently in progress. */
536-
if (ht->tbl != ht->future_tbl &&
537-
ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size))
538-
schedule_delayed_work(&ht->run_work, 0);
548+
rhashtable_wakeup_worker(ht);
539549

540550
rcu_read_unlock();
541551
}
@@ -584,10 +594,7 @@ bool rhashtable_remove(struct rhashtable *ht, struct rhash_head *obj)
584594

585595
spin_unlock_bh(lock);
586596

587-
if (ht->tbl != ht->future_tbl &&
588-
ht->p.shrink_decision &&
589-
ht->p.shrink_decision(ht, tbl->size))
590-
schedule_delayed_work(&ht->run_work, 0);
597+
rhashtable_wakeup_worker(ht);
591598

592599
rcu_read_unlock();
593600

0 commit comments

Comments
 (0)