[master] 61b722b Move always_miss check up front to get it over with.
Poul-Henning Kamp
phk at varnish-cache.org
Tue Apr 9 13:29:55 CEST 2013
commit 61b722b61676022997d366b55d6424e907001cfd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Apr 9 11:29:35 2013 +0000
Move always_miss check up front to get it over with.
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 7c51041..aeb7fe3 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -285,8 +285,50 @@ HSH_Insert(struct worker *wrk, const void *digest, struct objcore *oc)
/*---------------------------------------------------------------------
*/
+static struct objcore *
+hsh_insert_busyobj(struct worker *wrk, struct objhead *oh)
+{
+ struct objcore *oc;
+
+ CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
+
+ oc = wrk->nobjcore;
+ wrk->nobjcore = NULL;
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+
+ AN(oc->flags & OC_F_BUSY);
+ oc->refcnt = 1; /* Owned by busyobj */
+ oc->objhead = oh;
+ VTAILQ_INSERT_TAIL(&oh->objcs, oc, list);
+ return (oc);
+}
+
+/*---------------------------------------------------------------------
+ * XXX: future action:
+ *
+ * if (always_miss)
+ * return (insert_busy_obj())
+ * switch (Lookup()) {
+ * case HIT:
+ * return (object);
+ * case BUSY_ONLY:
+ * if (!ignore_body)
+ * return (WAIT)
+ * // fallthrough
+ * case MISS:
+ * return (insert_busy_obj())
+ * case EXPIRED_AND_BUSY:
+ * if (!ignore_body)
+ * return (expired_object)
+ * // fallthrough
+ * case EXPIRED:
+ * return (expired_object + insert_busy_obj())
+ * }
+ *
+ */
+
struct objcore *
-HSH_Lookup(struct req *req, int wait_for_busy)
+HSH_Lookup(struct req *req, int wait_for_busy, int always_insert)
{
struct worker *wrk;
struct objhead *oh;
@@ -324,6 +366,14 @@ HSH_Lookup(struct req *req, int wait_for_busy)
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_AssertHeld(&oh->mtx);
+ if (always_insert) {
+ /* Insert new objcore in objecthead and release mutex */
+ oc = hsh_insert_busyobj(wrk, oh);
+ /* NB: no deref of objhead, new object inherits reference */
+ Lck_Unlock(&oh->mtx);
+ return (oc);
+ }
+
assert(oh->refcnt > 0);
busy_found = 0;
grace_oc = NULL;
@@ -336,7 +386,7 @@ HSH_Lookup(struct req *req, int wait_for_busy)
if (oc->flags & OC_F_BUSY || oc->busyobj != NULL) {
CHECK_OBJ_ORNULL(oc->busyobj, BUSYOBJ_MAGIC);
- if (req->hash_ignore_busy || req->hash_always_miss)
+ if (req->hash_ignore_busy)
continue;
if (oc->busyobj != NULL &&
@@ -393,7 +443,7 @@ HSH_Lookup(struct req *req, int wait_for_busy)
oc = grace_oc;
}
- if (oc != NULL && !req->hash_always_miss) {
+ if (oc != NULL) {
/* We found an object we like */
assert(oh->refcnt > 1);
assert(oc->objhead == oh);
@@ -440,13 +490,8 @@ HSH_Lookup(struct req *req, int wait_for_busy)
}
/* Insert (precreated) objcore in objecthead and release mutex */
- oc = wrk->nobjcore;
- wrk->nobjcore = NULL;
- AN(oc->flags & OC_F_BUSY);
- oc->refcnt = 1; /* Owned by busyobj */
- oc->objhead = oh;
- VTAILQ_INSERT_TAIL(&oh->objcs, oc, list);
- /* NB: do not deref objhead the new object inherits our reference */
+ oc = hsh_insert_busyobj(wrk, oh);
+ /* NB: no deref of objhead, new object inherits reference */
Lck_Unlock(&oh->mtx);
return (oc);
}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 7891a5c..d0fb0e1 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -751,7 +751,10 @@ cnt_lookup(struct worker *wrk, struct req *req)
VRY_Prep(req);
AZ(req->objcore);
- oc = HSH_Lookup(req, req->esi_level == 0 ? 1 : 0);
+ oc = HSH_Lookup(req,
+ req->esi_level == 0 ? 1 : 0,
+ req->hash_always_miss ? 1 : 0
+ );
if (oc == NULL) {
/*
* We lost the session to a busy object, disembark the
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index f680881..1ff7cac 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -53,7 +53,7 @@ struct hash_slinger {
/* cache_hash.c */
void HSH_Cleanup(struct worker *w);
-struct objcore *HSH_Lookup(struct req *, int wait_for_busy);
+struct objcore *HSH_Lookup(struct req *, int wait_for_busy, int always_insert);
void HSH_Ref(struct objcore *o);
void HSH_Drop(struct worker *, struct object **);
void HSH_Init(const struct hash_slinger *slinger);
More information about the varnish-commit
mailing list