[6.0] 718918663 Simplify HSH_Lookup 3/N
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:11 UTC 2019
commit 718918663cacd1159efa550da1fce8aed669feb3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Dec 4 23:08:02 2018 +0000
Simplify HSH_Lookup 3/N
Use req->hash_always_miss directly
Inspired by: #2856
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index c5f5d3c7d..94b7d2dd9 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -338,8 +338,7 @@ hsh_insert_busyobj(struct worker *wrk, struct objhead *oh)
*/
enum lookup_e
-HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
- int always_insert)
+HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
{
struct worker *wrk;
struct objhead *oh;
@@ -384,7 +383,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_AssertHeld(&oh->mtx);
- if (always_insert) {
+ if (req->hash_always_miss) {
/* XXX: should we do predictive Vary in this case ? */
/* Insert new objcore in objecthead and release mutex */
*bocp = hsh_insert_busyobj(wrk, oh);
@@ -472,7 +471,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
wrk->stats->cache_hitmiss++;
VSLb(req->vsl, SLT_HitMiss, "%u %.6f", xid, dttl);
return (HSH_HITMISS);
- }
+ }
if (oc->hits < LONG_MAX)
oc->hits++;
AN(hsh_deref_objhead_unlock(wrk, &oh));
diff --git a/bin/varnishd/cache/cache_objhead.h b/bin/varnishd/cache/cache_objhead.h
index 9e90d5b32..e12463981 100644
--- a/bin/varnishd/cache/cache_objhead.h
+++ b/bin/varnishd/cache/cache_objhead.h
@@ -68,8 +68,7 @@ int HSH_DerefObjCore(struct worker *, struct objcore **, int rushmax);
#define HSH_RUSH_POLICY -1
#define HSH_RUSH_ALL INT_MAX
-enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **,
- int always_insert);
+enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **);
void HSH_Ref(struct objcore *o);
void HSH_AddString(struct req *, void *ctx, const char *str);
unsigned HSH_Purge(struct worker *, struct objhead *, vtim_real ttl_now,
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index b4bcc71ce..78395d7e5 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -495,7 +495,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
AZ(req->objcore);
if (req->hash_objhead)
had_objhead = 1;
- lr = HSH_Lookup(req, &oc, &busy, req->hash_always_miss ? 1 : 0);
+ lr = HSH_Lookup(req, &oc, &busy);
if (lr == HSH_BUSY) {
/*
* We lost the session to a busy object, disembark the
@@ -986,7 +986,8 @@ cnt_purge(struct worker *wrk, struct req *req)
VRY_Prep(req);
AZ(req->objcore);
- lr = HSH_Lookup(req, &oc, &boc, 1);
+ req->hash_always_miss = 1;
+ lr = HSH_Lookup(req, &oc, &boc);
assert (lr == HSH_MISS);
AZ(oc);
CHECK_OBJ_NOTNULL(boc, OBJCORE_MAGIC);
More information about the varnish-commit
mailing list