[master] 73289ed99 Reduce locking in HSH_Lookup()
Martin Blix Grydeland
martin at varnish-software.com
Tue Dec 4 13:46:09 UTC 2018
commit 73289ed99e0cb0e8fcbb666ffc55b30c9d51a680
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 593ca01dc..5d68a1392 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