Skip to contentSkip to conversation

Minor rhashtable fixes

PATCH Applied Thomas Graf 3 participants 7 messages Mar 16, 2015

Subsystems (4)
lore
Share & tools
lore

Thomas Graf

author maintainer
#0 lore raw

v2 cover Minor rhashtable fixes

Thomas Graf (2):
rhashtable: Avoid calculating hash again to unlock
rhashtable: Annotate RCU locking of walkers

 lib/rhashtable.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

---
v2: Dropped patch 2

author maintainer
#1 lore raw

PATCH v2 1/2 rhashtable: Avoid calculating hash again to unlock

Caching the lock pointer avoids having to hash on the object again to unlock the bucket locks.

---
 lib/rhashtable.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
lib/rhashtable.c +5 -6
index c523d3a..e396d7e 100644
@@ -384,14 +384,16 @@ static bool __rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj,
 	struct rhash_head *head;
 	bool no_resize_running;
 	unsigned hash;
+	spinlock_t *old_lock;
 	bool success = true;
 
 	rcu_read_lock();
 
 	old_tbl = rht_dereference_rcu(ht->tbl, ht);
 	hash = head_hashfn(ht, old_tbl, obj);
+	old_lock = bucket_lock(old_tbl, hash);
 
-	spin_lock_bh(bucket_lock(old_tbl, hash));
+	spin_lock_bh(old_lock);
 
 	/* Because we have already taken the bucket lock in old_tbl,
 	 * 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,
 		schedule_work(&ht->run_work);
 
 exit:
-	if (tbl != old_tbl) {
-		hash = head_hashfn(ht, tbl, obj);
+	if (tbl != old_tbl)
 		spin_unlock(bucket_lock(tbl, hash));
-	}
 
-	hash = head_hashfn(ht, old_tbl, obj);
-	spin_unlock_bh(bucket_lock(old_tbl, hash));
+	spin_unlock_bh(old_lock);
 
 	rcu_read_unlock();
 
Signature · 1 line
1.9.3
maintainer
#2 lore raw

Re: [PATCH 1/2 net-next] rhashtable: Avoid calculating hash again to unlock

From: Thomas Graf <[email protected]>
Date: Mon, 16 Mar 2015 10:42:26 +0100

Quoted 4 lines

Caching the lock pointer avoids having to hash on the object again to unlock the bucket locks.

I'd like to hold off on this.

My understanding is that Herbert plans to expand the table size synchonously during insert in emergency situations, and in that regime some of these optimization won't be valid.

maintainer
#3 lore raw

Re: [PATCH 1/2 net-next] rhashtable: Avoid calculating hash again to unlock

Quoted 6 lines · David Miller

From: Thomas Graf <[email protected]>
Date: Mon, 16 Mar 2015 10:42:26 +0100

Quoted 3 lines

Caching the lock pointer avoids having to hash on the object again to unlock the bucket locks.

Quoted 7 lines
Quoted 1 line

I'd like to hold off on this.

My understanding is that Herbert plans to expand the table size synchonously during insert in emergency situations, and in that regime some of these optimization won't be valid.

Actually this patch does not conflict with my multiple rehashing work (the final scheme I used only requires two locks) so please feel free to merge it and I will rebase my stuff.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#4 lore raw

Re: [PATCH 1/2 net-next] rhashtable: Avoid calculating hash again to unlock

From: Herbert Xu <[email protected]>
Date: Tue, 17 Mar 2015 07:48:36 +1100

Quoted 11 lines · David Miller
Quoted 10 lines

From: Thomas Graf <[email protected]>
Date: Mon, 16 Mar 2015 10:42:26 +0100

Quoted 4 lines

Caching the lock pointer avoids having to hash on the object again to unlock the bucket locks.

I'd like to hold off on this.

Quoted 7 lines
Quoted 3 lines

My understanding is that Herbert plans to expand the table size synchonously during insert in emergency situations, and in that regime some of these optimization won't be valid.

Actually this patch does not conflict with my multiple rehashing work (the final scheme I used only requires two locks) so please feel free to merge it and I will rebase my stuff.

Ok, done, thanks.

author maintainer
#5 lore raw

PATCH v2 2/2 rhashtable: Annotate RCU locking of walkers

In reply to Thomas Graf

Fixes the following sparse warnings:

lib/rhashtable.c:767:5: warning: context imbalance in 'rhashtable_walk_start' - wrong count at exit lib/rhashtable.c:849:6: warning: context imbalance in 'rhashtable_walk_stop' - unexpected unlock

Fixes f2dba9c6ff0d ("rhashtable: Introduce rhashtable_walk_*")
---
 lib/rhashtable.c | 2 ++
 1 file changed, 2 insertions(+)
lib/rhashtable.c +2 -0
index e396d7e..09a7ada 100644
@@ -759,6 +759,7 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_exit);
  * by calling rhashtable_walk_next.
  */
 int rhashtable_walk_start(struct rhashtable_iter *iter)
+	__acquires(RCU)
 {
 	struct rhashtable *ht = iter->ht;
 
@@ -846,6 +847,7 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_next);
  * Finish a hash table walk.
  */
 void rhashtable_walk_stop(struct rhashtable_iter *iter)
+	__releases(RCU)
 {
 	struct rhashtable *ht;
 	struct bucket_table *tbl = iter->walker->tbl;
Signature · 1 line
1.9.3
maintainer Applied
#6 lore raw

Re: [PATCH 2/2 net-next] rhashtable: Annotate RCU locking of walkers

From: Thomas Graf <[email protected]>
Date: Mon, 16 Mar 2015 10:42:27 +0100

Quoted 7 lines

Fixes the following sparse warnings:

lib/rhashtable.c:767:5: warning: context imbalance in 'rhashtable_walk_start' - wrong count at exit lib/rhashtable.c:849:6: warning: context imbalance in 'rhashtable_walk_stop' - unexpected unlock

Fixes f2dba9c6ff0d ("rhashtable: Introduce rhashtable_walk_*")

Applied, thanks.