[master] 74889dd Make persistent save the entire struct exp rather than only the deadline, in preparation for moving exp from obj to objcore
Poul-Henning Kamp
phk at FreeBSD.org
Thu Jun 26 09:55:43 CEST 2014
commit 74889dda9dbb3e6f4a9098ebbfd91badbff34f0a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jun 26 07:55:03 2014 +0000
Make persistent save the entire struct exp rather than only the deadline,
in preparation for moving exp from obj to objcore
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 410aa7e..baca07c 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -928,6 +928,7 @@ extern pthread_t cli_thread;
void EXP_Clr(struct exp *e);
double EXP_Ttl(const struct req *, const struct object*);
+double EXP_When(const struct exp *exp);
void EXP_Insert(struct objcore *oc);
void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
void EXP_Init(void);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 5f01f65..9ae6558 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -87,17 +87,17 @@ EXP_Ttl(const struct req *req, const struct object *o)
}
/*--------------------------------------------------------------------
- * Calculate when we should wake up for this object
+ * Calculate when this object is no longer useful
*/
-static double
-exp_when(const struct object *o)
+double
+EXP_When(const struct exp *e)
{
double when;
- CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-
- when = o->exp.t_origin + o->exp.ttl + o->exp.grace + o->exp.keep;
+ if (e->t_origin == 0)
+ return (0.);
+ when = e->t_origin + e->ttl + e->grace + e->keep;
AZ(isnan(when));
return (when);
}
@@ -243,7 +243,7 @@ EXP_Rearm(struct object *o, double now, double ttl, double grace, double keep)
if (!isnan(keep))
o->exp.keep = keep;
- when = exp_when(o);
+ when = EXP_When(&o->exp);
VSL(SLT_ExpKill, 0, "EXP_Rearm p=%p E=%.9f e=%.9f f=0x%x", oc,
oc->timer_when, when, oc->flags);
@@ -391,7 +391,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now)
if (flags & OC_EF_MOVE) {
o = oc_getobj(&ep->wrk->stats, oc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
- oc->timer_when = exp_when(o);
+ oc->timer_when = EXP_When(&o->exp);
oc_updatemeta(oc);
}
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 694d7fe..f1680a3 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -473,7 +473,7 @@ smp_allocx(struct stevedore *st, size_t min_size, size_t max_size,
sc->next_top -= sizeof(**so);
*so = (void*)(sc->base + sc->next_top);
/* Render this smp_object mostly harmless */
- (*so)->ttl = 0.;
+ EXP_Clr(&(*so)->exp);
(*so)->ban = 0.;
(*so)->ptr = 0;
sg->objs = *so;
@@ -545,7 +545,7 @@ smp_allocobj(struct stevedore *stv, struct busyobj *bo,
/* 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);
- so->ttl = oc->timer_when;
+ so->exp = bo->exp;
so->ptr = (uint8_t*)o - sc->base;
so->ban = BAN_Time(oc->ban);
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index 729570e..2d46297 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -144,7 +144,7 @@ struct smp_segptr {
struct smp_object {
uint8_t hash[32]; /* really: DIGEST_LEN */
- double ttl;
+ struct exp exp;
double ban;
uint64_t ptr; /* rel to silo */
};
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index ccd9991..4ceaa6a 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -148,7 +148,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
/* Clear the bogus "hold" count */
sg->nobj = 0;
for (;no > 0; so++,no--) {
- if (so->ttl == 0 || so->ttl < t_now)
+ if (EXP_When(&so->exp) < t_now)
continue;
ALLOC_OBJ(oc, OBJCORE_MAGIC);
AN(oc);
@@ -157,7 +157,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
smp_init_oc(oc, sg, no);
oc->ban = BAN_RefBan(oc, so->ban, sc->tailban);
HSH_Insert(wrk, so->hash, oc);
- EXP_Inject(oc, sg->lru, so->ttl);
+ EXP_Inject(oc, sg->lru, EXP_When(&so->exp));
sg->nobj++;
}
Pool_Sumstat(wrk);
@@ -463,7 +463,7 @@ smp_oc_getobj(struct dstat *ds, struct objcore *oc)
if(bad) {
o->exp.ttl = -1;
- so->ttl = 0;
+ EXP_Clr(&so->exp);
}
sg->nfixed++;
@@ -495,11 +495,11 @@ smp_oc_updatemeta(struct objcore *oc)
/* Lock necessary, we might race close_seg */
Lck_Lock(&sg->sc->mtx);
so->ban = BAN_Time(oc->ban);
- so->ttl = oc->timer_when;
+ so->exp = o->exp;;
Lck_Unlock(&sg->sc->mtx);
} else {
so->ban = BAN_Time(oc->ban);
- so->ttl = oc->timer_when;
+ so->exp = o->exp;;
}
}
@@ -515,7 +515,7 @@ smp_oc_freeobj(struct objcore *oc)
so = smp_find_so(sg, oc->priv2);
Lck_Lock(&sg->sc->mtx);
- so->ttl = 0;
+ EXP_Clr(&so->exp);
so->ptr = 0;
assert(sg->nobj > 0);
More information about the varnish-commit
mailing list