[6.0] 02dd83ba1 Reduce locking in HSH_Lookup()

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:10 UTC 2019


commit 02dd83ba173406d2f0c8e4808f2c2dbc6061dd65
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Dec 4 10:57:11 2018 +0100

    Reduce locking in HSH_Lookup()
    
    Make use of the new hsh_deref_objhead_unlock() in HSH_Lookup() to reduce
    the number of times the objhead mutex is taken during cache hits.

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 5a13bffd0..cfda2bb9c 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -459,10 +459,11 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 					oc->hits++;
 				retval = HSH_HIT;
 			}
-			Lck_Unlock(&oh->mtx);
 			*ocp = oc;
 			if (*bocp == NULL)
-				assert(hsh_deref_objhead(wrk, &oh));
+				AN(hsh_deref_objhead_unlock(wrk, &oh));
+			else
+				Lck_Unlock(&oh->mtx);
 
 			switch (retval) {
 			case HSH_HITPASS:
@@ -539,12 +540,10 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 		assert(oh->refcnt > 1);
 		assert(exp_oc->objhead == oh);
 		exp_oc->refcnt++;
-		Lck_Unlock(&oh->mtx);
 		*ocp = exp_oc;
-
-		assert(hsh_deref_objhead(wrk, &oh));
 		if (exp_oc->hits < LONG_MAX)
 			exp_oc->hits++;
+		AN(hsh_deref_objhead_unlock(wrk, &oh));
 		return (HSH_GRACE);
 	}
 


More information about the varnish-commit mailing list