[master] 4ded44b Make DYING a main Obj flag, add a function to set it (ObjKill) and end random code mucking about with it.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Feb 3 11:32:11 CET 2016
commit 4ded44b6c9633d483de1609a97c99fa0b6db153a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Feb 3 10:17:14 2016 +0000
Make DYING a main Obj flag, add a function to set it (ObjKill)
and end random code mucking about with it.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index a1f8eba..599844b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -427,12 +427,12 @@ struct objcore {
#define OC_F_ABANDON (1<<4)
#define OC_F_PRIVATE (1<<5)
#define OC_F_FAILED (1<<6)
+#define OC_F_DYING (1<<7)
uint8_t exp_flags;
#define OC_EF_MOVE (1<<2)
#define OC_EF_INSERT (1<<3)
#define OC_EF_EXP (1<<4)
-#define OC_EF_DYING (1<<5)
uint16_t oa_present;
@@ -858,6 +858,7 @@ void ObjWaitState(const struct objcore *, enum boc_state_e want);
void ObjTrimStore(struct worker *, struct objcore *);
void ObjTouch(struct worker *, struct objcore *, double now);
int ObjSnipe(const struct worker *, struct objcore *);
+void ObjKill(struct objcore *);
unsigned ObjGetXID(struct worker *, struct objcore *);
uint64_t ObjGetLen(struct worker *, struct objcore *);
void ObjUpdateMeta(struct worker *, struct objcore *);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 118743d..960fba2 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -143,7 +143,7 @@ exp_mail_it(struct objcore *oc)
AN(oc->lru_flags & OC_LRU_OFFLRU);
Lck_Lock(&exphdl->mtx);
- if (oc->exp_flags & OC_EF_DYING)
+ if (oc->flags & OC_F_DYING)
VTAILQ_INSERT_HEAD(&exphdl->inbox, oc, lru_list);
else
VTAILQ_INSERT_TAIL(&exphdl->inbox, oc, lru_list);
@@ -168,7 +168,7 @@ EXP_Inject(struct worker *wrk, struct objcore *oc, struct lru *lru)
AZ(oc->lru_flags & OC_LRU_OFFLRU);
AZ(oc->exp_flags & (OC_EF_INSERT | OC_EF_MOVE));
- AZ(oc->exp_flags & OC_EF_DYING);
+ AZ(oc->flags & OC_F_DYING);
AZ(oc->flags & OC_F_BUSY);
CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
@@ -202,7 +202,7 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
AZ(oc->lru_flags & OC_LRU_OFFLRU);
AZ(oc->exp_flags & (OC_EF_INSERT | OC_EF_MOVE));
- AZ(oc->exp_flags & OC_EF_DYING);
+ AZ(oc->flags & OC_F_DYING);
AN(oc->flags & OC_F_BUSY);
lru = ObjGetLRU(oc);
@@ -256,15 +256,11 @@ EXP_Rearm(struct objcore *oc, double now, double ttl, double grace, double keep)
Lck_Lock(&lru->mtx);
- if (!isnan(now) && when <= now)
- oc->exp_flags |= OC_EF_DYING;
- else
- oc->exp_flags |= OC_EF_MOVE;
-
if (oc->lru_flags & OC_LRU_OFFLRU) {
oc = NULL;
} else {
oc->lru_flags |= OC_LRU_OFFLRU;
+ oc->exp_flags |= OC_EF_MOVE;
VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
}
Lck_Unlock(&lru->mtx);
@@ -384,13 +380,13 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now)
AN(oc->lru_flags & OC_LRU_OFFLRU);
oc->exp_flags &= ~(OC_EF_INSERT | OC_EF_MOVE);
oc->last_lru = now;
- if (!(flags & OC_EF_DYING)) {
+ if (!(oc->flags & OC_F_DYING)) {
VTAILQ_INSERT_TAIL(&lru->lru_head, oc, lru_list);
oc->lru_flags &= ~OC_LRU_OFFLRU;
}
Lck_Unlock(&lru->mtx);
- if (flags & OC_EF_DYING) {
+ if (oc->flags & OC_F_DYING) {
VSLb(&ep->vsl, SLT_ExpKill, "EXP_Kill p=%p e=%.9f f=0x%x", oc,
oc->timer_when, oc->flags);
if (!(flags & OC_EF_INSERT)) {
@@ -458,7 +454,8 @@ exp_expire(struct exp_priv *ep, double now)
CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
Lck_Lock(&lru->mtx);
- oc->exp_flags |= OC_EF_DYING;
+ if (!(oc->flags & OC_F_DYING))
+ ObjKill(oc);
if (oc->lru_flags & OC_LRU_OFFLRU)
oc = NULL;
else {
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index fb1c5db..24c2084 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -393,7 +393,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(oc->objhead == oh);
- if (oc->exp_flags & OC_EF_DYING)
+ if (oc->flags & OC_F_DYING)
continue;
if (oc->flags & OC_F_FAILED)
continue;
@@ -415,8 +415,10 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
if (oc->exp.ttl <= 0.)
continue;
- if (BAN_CheckObject(wrk, oc, req))
+ if (BAN_CheckObject(wrk, oc, req)) {
+ oc->flags |= OC_F_DYING;
continue;
+ }
if (ObjHasAttr(wrk, oc, OA_VARY)) {
vary = ObjGetAttr(wrk, oc, OA_VARY, NULL);
@@ -585,7 +587,7 @@ double keep)
*/
continue;
}
- if (oc->exp_flags & OC_EF_DYING)
+ if (oc->flags & OC_F_DYING)
continue;
if (spc < sizeof *ocp) {
/* Iterate if aws is not big enough */
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index d8cf967..3cc195b 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -370,6 +370,26 @@ ObjTouch(struct worker *wrk, struct objcore *oc, double now)
}
/*====================================================================
+ * ObjKill()
+ *
+ * It's dead Jim, kick it...
+ */
+
+void
+ObjKill(struct objcore *oc)
+{
+
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
+
+ AZ(oc->flags & OC_F_DYING); // XXX ?
+
+ Lck_Lock(&oc->objhead->mtx);
+ oc->flags |= OC_F_DYING;
+ Lck_Unlock(&oc->objhead->mtx);
+}
+
+/*====================================================================
* ObjSnipe()
*
* If objcore is idle, gain a ref and mark it dead.
@@ -384,11 +404,11 @@ ObjSnipe(const struct worker *wrk, struct objcore *oc)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
- AZ(oc->exp_flags & OC_EF_DYING);
+ AZ(oc->flags & OC_F_DYING);
if (oc->refcnt == 1 && !Lck_Trylock(&oc->objhead->mtx)) {
if (oc->refcnt == 1) {
- oc->exp_flags |= OC_EF_DYING;
+ oc->flags |= OC_F_DYING;
oc->refcnt++;
retval = 1;
}
More information about the varnish-commit
mailing list