[master] 56ea5e3 Go over the entire struct exp-thing and simplify it a lot.

Poul-Henning Kamp phk at varnish-cache.org
Fri Oct 4 09:58:40 CEST 2013


commit 56ea5e3cf99cc90a80d0f561ad9eecfd2ed0b8f3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Oct 4 07:58:06 2013 +0000

    Go over the entire struct exp-thing and simplify it a lot.
    
    We now kill objects when t_origin + ttl + grace + keep has elapsed.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7880481..bd28089 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -289,10 +289,10 @@ typedef int vdp_bytes(struct req *, enum vdp_action, const void *ptr,
 /*--------------------------------------------------------------------*/
 
 struct exp {
-	double			ttl;
-	double			grace;
-	double			keep;
 	double			t_origin;
+	float			ttl;
+	float			grace;
+	float			keep;
 };
 
 /*--------------------------------------------------------------------*/
@@ -896,12 +896,6 @@ extern pthread_t cli_thread;
 
 /* cache_expiry.c */
 void EXP_Clr(struct exp *e);
-double EXP_Get_ttl(const struct exp *e);
-double EXP_Get_grace(const struct exp *e);
-double EXP_Get_keep(const struct exp *e);
-void EXP_Set_ttl(struct exp *e, double v);
-void EXP_Set_grace(struct exp *e, double v);
-void EXP_Set_keep(struct exp *e, double v);
 
 double EXP_Ttl(const struct req *, const struct object*);
 void EXP_Insert(const struct object *o, double now);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index de4e3e9..0703050 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -35,18 +35,6 @@
  *
  * We hold a single object reference for both data structures.
  *
- * An attempted overview:
- *
- *	                        EXP_Ttl()      EXP_Grace()   EXP_Keep()
- *				   |                |            |
- *      entered                    v                v            |
- *         |                       +--------------->+            |
- *         v                       |      grace                  |
- *         +---------------------->+                             |
- *                  ttl            |                             v
- *                                 +---------------------------->+
- *                                     keep
- *
  */
 
 #include "config.h"
@@ -65,9 +53,6 @@ static struct lock exp_mtx;
 
 /*--------------------------------------------------------------------
  * struct exp manipulations
- *
- * The Get/Set functions encapsulate the mutual magic between the
- * fields in one single place.
  */
 
 void
@@ -75,36 +60,14 @@ EXP_Clr(struct exp *e)
 {
 
 	e->ttl = -1;
-	e->grace = -1;
-	e->keep = -1;
+	e->grace = 0;
+	e->keep = 0;
 	e->t_origin = 0;
 }
 
-#define EXP_ACCESS(fld, low_val, extra)				\
-	double							\
-	EXP_Get_##fld(const struct exp *e)			\
-	{							\
-		return (e->fld > 0. ? e->fld : low_val);	\
-	}							\
-								\
-	void							\
-	EXP_Set_##fld(struct exp *e, double v)			\
-	{							\
-		if (v > 0.)					\
-			e->fld = v;				\
-		else {						\
-			e->fld = -1.;				\
-			extra;					\
-		}						\
-	}							\
-
-EXP_ACCESS(ttl, -1., (e->grace = e->keep = -1.))
-EXP_ACCESS(grace, 0., )
-EXP_ACCESS(keep, 0.,)
-
 /*--------------------------------------------------------------------
- * Calculate an objects effective keep, grace or ttl time, suitably
- * adjusted for defaults and by per-session limits.
+ * Calculate an objects effective ttl time, taking req.ttl into account
+ * if it is available.
  */
 
 double
@@ -482,7 +445,7 @@ EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru)
 			VSLb(vsl, SLT_ExpKill, "%u %.0f LRU",
 			    oc_getxid(&wrk->stats, oc) & VSL_IDENTMASK,
 			    EXP_Ttl(NULL, o) - t);
-			EXP_Set_ttl(&o->exp, 0.);
+			o->exp.ttl = 0.0;
 			(void)HSH_DerefObjCore(&wrk->stats, &oc);
 		}
 
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 9c5ba19..3e0a73e 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -449,17 +449,22 @@ VRT_r_bereq_retries(const struct vrt_ctx *ctx)
  * keep are relative to ttl.
  */
 
-#define VRT_DO_EXP(which, exp, fld, offset, extra)		\
+#define VRT_DO_EXP(which, sexp, fld, offset, now, extra)	\
 								\
 void								\
 VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a)	\
 {								\
+	double dt;						\
 								\
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);			\
-	if (a > 0.)						\
-		a += offset;					\
-	EXP_Set_##fld(&exp, a);					\
+	if (a > 0.0)						\
+		sexp.fld = a + offset;				\
+	else							\
+		sexp.fld = 0;					\
 	extra;							\
+	dt = now - sexp.t_origin;				\
+	VSLb(ctx->vsl, SLT_TTL, "VCL %.0f %.0f %.0f %.0f %.0f",	\
+	    sexp.ttl - dt, sexp.grace, sexp.keep, now, dt);	\
 }								\
 								\
 double								\
@@ -467,36 +472,22 @@ VRT_r_##which##_##fld(const struct vrt_ctx *ctx)		\
 {								\
 								\
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);			\
-	return(EXP_Get_##fld(&exp) - offset);			\
+	if (sexp.fld > 0.0)					\
+		return(sexp.fld - offset);			\
+	return(0.0);						\
 }
 
-static void
-vrt_wsp_exp(struct vsl_log *vsl, double now, const struct exp *e)
-{
-	double dt;
-
-	dt = now - e->t_origin;
-	VSLb(vsl, SLT_TTL, "VCL %.0f %.0f %.0f %.0f %.0f",
-	    e->ttl - dt, e->grace, e->keep, now, dt);
-}
-
-VRT_DO_EXP(obj, ctx->req->obj->exp, grace, 0,
-   EXP_Rearm(ctx->req->obj);
-   vrt_wsp_exp(ctx->vsl, ctx->req->t_req, &ctx->req->obj->exp);)
+VRT_DO_EXP(obj, ctx->req->obj->exp, grace, 0, ctx->req->t_req,
+   EXP_Rearm(ctx->req->obj);)
 VRT_DO_EXP(obj, ctx->req->obj->exp, ttl,
-   (ctx->req->t_req - ctx->req->obj->exp.t_origin),
-   EXP_Rearm(ctx->req->obj);
-   vrt_wsp_exp(ctx->vsl, ctx->req->t_req, &ctx->req->obj->exp);)
-VRT_DO_EXP(obj, ctx->req->obj->exp, keep, 0,
-   EXP_Rearm(ctx->req->obj);
-   vrt_wsp_exp(ctx->vsl, ctx->req->t_req, &ctx->req->obj->exp);)
-
-VRT_DO_EXP(beresp, ctx->bo->exp, grace, 0,
-   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.t_origin, &ctx->bo->exp);)
-VRT_DO_EXP(beresp, ctx->bo->exp, ttl, 0,
-   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.t_origin, &ctx->bo->exp);)
-VRT_DO_EXP(beresp, ctx->bo->exp, keep, 0,
-   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.t_origin, &ctx->bo->exp);)
+   (ctx->req->t_req - ctx->req->obj->exp.t_origin), ctx->req->t_req,
+   EXP_Rearm(ctx->req->obj);)
+VRT_DO_EXP(obj, ctx->req->obj->exp, keep, 0, ctx->req->t_req,
+   EXP_Rearm(ctx->req->obj);)
+
+VRT_DO_EXP(beresp, ctx->bo->exp, grace, 0, ctx->bo->exp.t_origin,)
+VRT_DO_EXP(beresp, ctx->bo->exp, ttl, 0, ctx->bo->exp.t_origin,)
+VRT_DO_EXP(beresp, ctx->bo->exp, keep, 0, ctx->bo->exp.t_origin,)
 
 /*--------------------------------------------------------------------
  * req.xid
diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt
index 5402e1f..e203cb8 100644
--- a/bin/varnishd/flint.lnt
+++ b/bin/varnishd/flint.lnt
@@ -170,4 +170,4 @@
 -e840	// Use of nul character in a string literal (see: vcc_if.c)
 -e663	// Suspicious array to pointer conversion
 -e778   // Constant expression evaluates to 0 in operation '___'
-
+-e736	// Loss of precision (___) (___ bits to ___ bits)
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 75dee88..c6f8a2f 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -460,7 +460,7 @@ smp_oc_getobj(struct dstat *ds, struct objcore *oc)
 			bad |= 0x100;
 
 		if(bad) {
-			EXP_Set_ttl(&o->exp, -1);
+			o->exp.ttl = -1;
 			so->ttl = 0;
 		}
 



More information about the varnish-commit mailing list