[master] dadd878 Get rid of struct exp entirely
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 9 01:19:12 CET 2016
commit dadd87802ee41822ab3d5856aec494ffcf3f96ba
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 8 22:42:07 2016 +0000
Get rid of struct exp entirely
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 387aa01..a9cd4fd 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -273,15 +273,6 @@ struct dstat {
/*--------------------------------------------------------------------*/
-struct exp {
- double t_origin;
- float ttl;
- float grace;
- float keep;
-};
-
-/*--------------------------------------------------------------------*/
-
struct vsl_log {
uint32_t *wlb, *wlp, *wle;
unsigned wlr;
@@ -420,7 +411,10 @@ struct objcore {
double timer_when;
long hits;
- struct exp exp;
+ double t_origin;
+ float ttl;
+ float grace;
+ float keep;
uint8_t flags;
#define OC_F_BUSY (1<<1)
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 3f70c42..d79f75b 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -576,7 +576,7 @@ BAN_CheckObject(struct worker *wrk, struct objcore *oc, struct req *req)
} else {
VSLb(vsl, SLT_ExpBan, "%u banned lookup", ObjGetXID(wrk, oc));
VSC_C_main->bans_obj_killed++;
- EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0); // XXX fake now
+ EXP_Rearm(oc, oc->t_origin, 0, 0, 0); // XXX fake now
return (1);
}
}
diff --git a/bin/varnishd/cache/cache_ban_lurker.c b/bin/varnishd/cache/cache_ban_lurker.c
index e913fda..0c48da1 100644
--- a/bin/varnishd/cache/cache_ban_lurker.c
+++ b/bin/varnishd/cache/cache_ban_lurker.c
@@ -181,7 +181,7 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
VSLb(vsl, SLT_ExpBan, "%u banned by lurker",
ObjGetXID(wrk, oc));
- EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0);
+ EXP_Rearm(oc, oc->t_origin, 0, 0, 0);
// XXX ^ fake now
VSC_C_main->bans_lurker_obj_killed++;
} else {
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 590bc02..74e1bfc 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -98,26 +98,10 @@ EXP_Ttl(const struct req *req, const struct objcore *oc)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
- r = oc->exp.ttl;
+ r = oc->ttl;
if (req != NULL && req->d_ttl > 0. && req->d_ttl < r)
r = req->d_ttl;
- return (oc->exp.t_origin + r);
-}
-
-/*--------------------------------------------------------------------
- * Calculate when this object is no longer useful
- */
-
-static double
-EXP_When(const struct exp *e)
-{
- double when;
-
- if (e->t_origin == 0)
- return (0.);
- when = e->t_origin + e->ttl + e->grace + e->keep;
- AZ(isnan(when));
- return (when);
+ return (oc->t_origin + r);
}
/*--------------------------------------------------------------------
@@ -193,18 +177,18 @@ EXP_Rearm(struct objcore *oc, double now, double ttl, double grace, double keep)
AN(oc->exp_flags & OC_EF_EXP);
if (!isnan(ttl))
- oc->exp.ttl = now + ttl - oc->exp.t_origin;
+ oc->ttl = now + ttl - oc->t_origin;
if (!isnan(grace))
- oc->exp.grace = grace;
+ oc->grace = grace;
if (!isnan(keep))
- oc->exp.keep = keep;
+ oc->keep = keep;
- when = EXP_When(&oc->exp);
+ when = EXP_WHEN(oc);
VSL(SLT_ExpKill, 0, "EXP_Rearm p=%p E=%.9f e=%.9f f=0x%x", oc,
oc->timer_when, when, oc->flags);
- if (when < oc->exp.t_origin || when < oc->timer_when)
+ if (when < oc->t_origin || when < oc->timer_when)
exp_mail_it(oc, OC_EF_MOVE);
}
@@ -275,7 +259,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, unsigned flags)
}
if (flags & OC_EF_MOVE) {
- oc->timer_when = EXP_When(&oc->exp);
+ oc->timer_when = EXP_WHEN(oc);
ObjUpdateMeta(ep->wrk, oc);
}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 57295da..3b9e705 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -53,7 +53,7 @@ vbf_allocobj(struct busyobj *bo, unsigned l)
oc = bo->fetch_objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
- lifetime = oc->exp.ttl + oc->exp.grace + oc->exp.keep;
+ lifetime = oc->ttl + oc->grace + oc->keep;
if (bo->uncacheable || lifetime < cache_param->shortlived)
storage_hint = TRANSIENT_STORAGE;
@@ -73,10 +73,10 @@ vbf_allocobj(struct busyobj *bo, unsigned l)
* on Transient storage.
*/
- if (oc->exp.ttl > cache_param->shortlived)
- oc->exp.ttl = cache_param->shortlived;
- oc->exp.grace = 0.0;
- oc->exp.keep = 0.0;
+ if (oc->ttl > cache_param->shortlived)
+ oc->ttl = cache_param->shortlived;
+ oc->grace = 0.0;
+ oc->keep = 0.0;
return (STV_NewObject(bo->wrk, bo->fetch_objcore,
TRANSIENT_STORAGE, l));
}
@@ -150,7 +150,7 @@ vbf_beresp2obj(struct busyobj *bo)
VTIM_parse(b)));
else
AZ(ObjSetDouble(bo->wrk, bo->fetch_objcore, OA_LASTMODIFIED,
- floor(bo->fetch_objcore->exp.t_origin)));
+ floor(bo->fetch_objcore->t_origin)));
return (0);
}
@@ -385,15 +385,15 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
* What does RFC2616 think about TTL ?
*/
RFC2616_Ttl(bo, now,
- &bo->fetch_objcore->exp.t_origin,
- &bo->fetch_objcore->exp.ttl,
- &bo->fetch_objcore->exp.grace,
- &bo->fetch_objcore->exp.keep
+ &bo->fetch_objcore->t_origin,
+ &bo->fetch_objcore->ttl,
+ &bo->fetch_objcore->grace,
+ &bo->fetch_objcore->keep
);
/* private objects have negative TTL */
if (bo->fetch_objcore->flags & OC_F_PRIVATE)
- bo->fetch_objcore->exp.ttl = -1.;
+ bo->fetch_objcore->ttl = -1.;
AZ(bo->do_esi);
AZ(bo->was_304);
@@ -689,7 +689,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
ObjSetState(bo->fetch_objcore, BOS_FINISHED);
VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
if (bo->stale_oc != NULL)
- EXP_Rearm(bo->stale_oc, bo->stale_oc->exp.t_origin, 0, 0, 0);
+ EXP_Rearm(bo->stale_oc, bo->stale_oc->t_origin, 0, 0, 0);
return (F_STP_DONE);
}
@@ -756,7 +756,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
if (!bo->do_stream)
HSH_Unbusy(wrk, bo->fetch_objcore);
- EXP_Rearm(bo->stale_oc, bo->stale_oc->exp.t_origin, 0, 0, 0);
+ EXP_Rearm(bo->stale_oc, bo->stale_oc->t_origin, 0, 0, 0);
/* Recycle the backend connection before setting BOS_FINISHED to
give predictable backend reuse behavior for varnishtest */
@@ -798,7 +798,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
http_TimeHeader(bo->beresp, "Date: ", now);
http_SetHeader(bo->beresp, "Server: Varnish");
- bo->fetch_objcore->exp.t_origin = now;
+ bo->fetch_objcore->t_origin = now;
if (!VTAILQ_EMPTY(&bo->fetch_objcore->objhead->waitinglist)) {
/*
* If there is a waitinglist, it means that there is no
@@ -807,13 +807,13 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
* each objcore on the waiting list sequentially attempt
* to fetch from the backend.
*/
- bo->fetch_objcore->exp.ttl = 1;
- bo->fetch_objcore->exp.grace = 5;
- bo->fetch_objcore->exp.keep = 5;
+ bo->fetch_objcore->ttl = 1;
+ bo->fetch_objcore->grace = 5;
+ bo->fetch_objcore->keep = 5;
} else {
- bo->fetch_objcore->exp.ttl = 0;
- bo->fetch_objcore->exp.grace = 0;
- bo->fetch_objcore->exp.keep = 0;
+ bo->fetch_objcore->ttl = 0;
+ bo->fetch_objcore->grace = 0;
+ bo->fetch_objcore->keep = 0;
}
synth_body = VSB_new_auto();
@@ -883,7 +883,7 @@ vbf_stp_fail(struct worker *wrk, const struct busyobj *bo)
/* Already unbusied - expire it */
AN(bo->fetch_objcore);
EXP_Rearm(bo->fetch_objcore,
- bo->fetch_objcore->exp.t_origin, 0, 0, 0);
+ bo->fetch_objcore->t_origin, 0, 0, 0);
}
wrk->stats->fetch_failed++;
ObjSetState(bo->fetch_objcore, BOS_FAILED);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index a8f438b..7fbd283 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -392,7 +392,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
continue;
}
- if (oc->exp.ttl <= 0.)
+ if (oc->ttl <= 0.)
continue;
if (BAN_CheckObject(wrk, oc, req)) {
@@ -418,10 +418,10 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
*ocp = oc;
return (HSH_HIT);
}
- if (oc->exp.t_origin > exp_t_origin) {
+ if (oc->t_origin > exp_t_origin) {
/* record the newest object */
exp_oc = oc;
- exp_t_origin = oc->exp.t_origin;
+ exp_t_origin = oc->t_origin;
}
}
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 79566af..0a85637 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -249,7 +249,7 @@ pan_objcore(struct vsb *vsb, const char *typ, const struct objcore *oc)
if (oc->boc != NULL)
pan_boc(vsb, oc->boc);
VSB_printf(vsb, "exp = { %f, %f, %f, %f }\n",
- oc->exp.t_origin, oc->exp.ttl, oc->exp.grace, oc->exp.keep);
+ oc->t_origin, oc->ttl, oc->grace, oc->keep);
VSB_printf(vsb, "objhead = %p,\n", oc->objhead);
VSB_printf(vsb, "stevedore = %p", oc->stobj->stevedore);
if (oc->stobj->stevedore != NULL) {
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index fa8f373..04c4e7f 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -91,7 +91,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
* age. Truncate to zero in that case).
*/
http_PrintfHeader(req->resp, "Age: %.0f",
- fmax(0., req->t_prev - req->objcore->exp.t_origin));
+ fmax(0., req->t_prev - req->objcore->t_origin));
http_SetHeader(req->resp, "Via: 1.1 varnish-v4");
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index cf25f67..442bd47 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -481,65 +481,65 @@ VRT_r_bereq_retries(VRT_CTX)
* grace&keep are relative to ttl
*/
-#define VRT_DO_EXP_L(which, sexp, fld, offset) \
+#define VRT_DO_EXP_L(which, oc, fld, offset) \
\
void \
-VRT_l_##which##_##fld(VRT_CTX, double a) \
+VRT_l_##which##_##fld(VRT_CTX, double a) \
{ \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
a += (offset); \
if (a < 0.0) \
a = 0.0; \
- sexp.fld = a; \
+ oc->fld = a; \
VSLb(ctx->vsl, SLT_TTL, "VCL %.0f %.0f %.0f %.0f", \
- sexp.ttl, sexp.grace, sexp.keep, sexp.t_origin); \
+ oc->ttl, oc->grace, oc->keep, oc->t_origin); \
}
-#define VRT_DO_EXP_R(which, sexp, fld, offset) \
+#define VRT_DO_EXP_R(which, oc, fld, offset) \
\
double \
-VRT_r_##which##_##fld(VRT_CTX) \
+VRT_r_##which##_##fld(VRT_CTX) \
{ \
double d; \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
- d = sexp.fld; \
+ d = oc->fld; \
if (d <= 0.0) \
d = 0.0; \
d -= (offset); \
return(d); \
}
-VRT_DO_EXP_R(obj, ctx->req->objcore->exp, ttl,
- ctx->now - ctx->req->objcore->exp.t_origin)
-VRT_DO_EXP_R(obj, ctx->req->objcore->exp, grace, 0)
-VRT_DO_EXP_R(obj, ctx->req->objcore->exp, keep, 0)
+VRT_DO_EXP_R(obj, ctx->req->objcore, ttl,
+ ctx->now - ctx->req->objcore->t_origin)
+VRT_DO_EXP_R(obj, ctx->req->objcore, grace, 0)
+VRT_DO_EXP_R(obj, ctx->req->objcore, keep, 0)
-VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl,
- ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
-VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl,
- ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
-VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
-VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
-VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
-VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
+VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore, ttl,
+ ctx->now - ctx->bo->fetch_objcore->t_origin)
+VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore, ttl,
+ ctx->now - ctx->bo->fetch_objcore->t_origin)
+VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore, grace, 0)
+VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore, grace, 0)
+VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore, keep, 0)
+VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore, keep, 0)
/*--------------------------------------------------------------------
*/
-#define VRT_DO_AGE_R(which, sexp) \
+#define VRT_DO_AGE_R(which, oc) \
\
double \
VRT_r_##which##_##age(VRT_CTX) \
{ \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
- return(ctx->now - sexp.t_origin); \
+ return(ctx->now - oc->t_origin); \
}
-VRT_DO_AGE_R(obj, ctx->req->objcore->exp)
-VRT_DO_AGE_R(beresp, ctx->bo->fetch_objcore->exp)
+VRT_DO_AGE_R(obj, ctx->req->objcore)
+VRT_DO_AGE_R(beresp, ctx->bo->fetch_objcore)
/*--------------------------------------------------------------------
* [be]req.xid
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index bbc8a83..7ebb747 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -522,7 +522,11 @@ smp_allocobj(struct worker *wrk, const struct stevedore *stv,
assert(really >= 0);
/* Don't entertain already dead objects */
- if ((oc->exp.ttl + oc->exp.grace + oc->exp.keep) <= 0.)
+ if (oc->flags & OC_F_DYING)
+ return (0);
+ if (oc->t_origin <= 0.)
+ return (0);
+ if (oc->ttl + oc->grace + oc->keep <= 0.)
return (0);
ltot = sizeof(struct object) + PRNDUP(wsl);
@@ -562,7 +566,7 @@ smp_allocobj(struct worker *wrk, const struct stevedore *stv,
/* We have to do this somewhere, might as well be here... */
assert(sizeof so->hash == DIGEST_LEN);
memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
- EXP_COPY(so, &oc->exp);
+ EXP_COPY(so, oc);
so->ptr = (uint8_t*)o - sc->base;
so->ban = BAN_Time(oc->ban);
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 9710dab..e235c5f 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -166,7 +166,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
VTAILQ_INSERT_TAIL(&sg->objcores, oc, lru_list);
oc->stobj->priv2 |= NEED_FIXUP;
oc->ban = BAN_RefBan(oc, so->ban);
- EXP_COPY(&oc->exp, so);
+ EXP_COPY(oc, so);
sg->nobj++;
oc->refcnt++;
HSH_Insert(wrk, so->hash, oc);
@@ -439,7 +439,7 @@ smp_sml_getobj(struct worker *wrk, struct objcore *oc)
bad |= 0x100;
if(bad) {
- EXP_ZERO(&oc->exp);
+ EXP_ZERO(oc);
EXP_ZERO(so);
}
@@ -470,11 +470,11 @@ smp_oc_objupdatemeta(struct worker *wrk, struct objcore *oc)
/* Lock necessary, we might race close_seg */
Lck_Lock(&sg->sc->mtx);
so->ban = BAN_Time(oc->ban);
- EXP_COPY(so, &oc->exp);
+ EXP_COPY(so, oc);
Lck_Unlock(&sg->sc->mtx);
} else {
so->ban = BAN_Time(oc->ban);
- EXP_COPY(so, &oc->exp);
+ EXP_COPY(so, oc);
}
}
More information about the varnish-commit
mailing list