diff options
author | Thomas Graf <tgraf@suug.ch> | 2015-03-16 05:42:26 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-16 17:14:34 -0400 |
commit | 617011e7d5559046e4fc8f87793c8a5d9c3431b0 (patch) | |
tree | 43dc9257e68f0bb7c5a3ce132932ecf632654d22 /lib/rhashtable.c | |
parent | 9f1ab18672bee992b6169bbfa2b5ae86b42e88a8 (diff) |
rhashtable: Avoid calculating hash again to unlock
Caching the lock pointer avoids having to hash on the object
again to unlock the bucket locks.
Signed-off-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.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index eae26a67bd18..09a7ada89ade 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c | |||
@@ -384,14 +384,16 @@ static bool __rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj, | |||
384 | struct rhash_head *head; | 384 | struct rhash_head *head; |
385 | bool no_resize_running; | 385 | bool no_resize_running; |
386 | unsigned hash; | 386 | unsigned hash; |
387 | spinlock_t *old_lock; | ||
387 | bool success = true; | 388 | bool success = true; |
388 | 389 | ||
389 | rcu_read_lock(); | 390 | rcu_read_lock(); |
390 | 391 | ||
391 | old_tbl = rht_dereference_rcu(ht->tbl, ht); | 392 | old_tbl = rht_dereference_rcu(ht->tbl, ht); |
392 | hash = head_hashfn(ht, old_tbl, obj); | 393 | hash = head_hashfn(ht, old_tbl, obj); |
394 | old_lock = bucket_lock(old_tbl, hash); | ||
393 | 395 | ||
394 | spin_lock_bh(bucket_lock(old_tbl, hash)); | 396 | spin_lock_bh(old_lock); |
395 | 397 | ||
396 | /* Because we have already taken the bucket lock in old_tbl, | 398 | /* Because we have already taken the bucket lock in old_tbl, |
397 | * if we find that future_tbl is not yet visible then that | 399 | * if we find that future_tbl is not yet visible then that |
@@ -428,13 +430,10 @@ static bool __rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj, | |||
428 | schedule_work(&ht->run_work); | 430 | schedule_work(&ht->run_work); |
429 | 431 | ||
430 | exit: | 432 | exit: |
431 | if (tbl != old_tbl) { | 433 | if (tbl != old_tbl) |
432 | hash = head_hashfn(ht, tbl, obj); | ||
433 | spin_unlock(bucket_lock(tbl, hash)); | 434 | spin_unlock(bucket_lock(tbl, hash)); |
434 | } | ||
435 | 435 | ||
436 | hash = head_hashfn(ht, old_tbl, obj); | 436 | spin_unlock_bh(old_lock); |
437 | spin_unlock_bh(bucket_lock(old_tbl, hash)); | ||
438 | 437 | ||
439 | rcu_read_unlock(); | 438 | rcu_read_unlock(); |
440 | 439 | ||