[master] 9f39566 More polishing

Poul-Henning Kamp phk at varnish-cache.org
Wed Oct 9 12:55:51 CEST 2013


commit 9f39566cf0bbbc1636d203da8d726664e7720488
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 9 10:55:38 2013 +0000

    More polishing

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 12118fd..5c249f5 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -442,6 +442,7 @@ struct objcore {
 #define OC_F_FAILED		(1<<9)
 #define OC_F_MOVE		(1<<10)
 #define OC_F_INSERT		(1<<11)
+#define OC_F_EXP		(1<<12)
 	unsigned		timer_idx;
 	VTAILQ_ENTRY(objcore)	list;
 	VTAILQ_ENTRY(objcore)	lru_list;
@@ -905,7 +906,7 @@ extern pthread_t cli_thread;
 void EXP_Clr(struct exp *e);
 
 double EXP_Ttl(const struct req *, const struct object*);
-void EXP_Insert(const struct object *o, double now);
+void EXP_Insert(struct objcore *oc);
 void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
 void EXP_Init(void);
 void EXP_Rearm(const struct object *o);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 381266f..dced5bb 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -122,9 +122,10 @@ exp_mail_it(struct objcore *oc)
 }
 
 /*--------------------------------------------------------------------
- * Object has been added to cache, record in lru & binheap.
+ * Inject an object with a reference into the lru/binheap.
  *
- * The objcore comes with a reference, which we inherit.
+ * This can either come from a stevedore (persistent) during startup
+ * or from EXP_Insert() below.
  */
 
 void
@@ -132,55 +133,40 @@ EXP_Inject(struct objcore *oc, struct lru *lru, double when)
 {
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
 
 	AZ(oc->flags & OC_F_OFFLRU);
+	AZ(oc->flags & OC_F_BUSY);
+
+	if (lru == NULL)
+		lru = oc_getlru(oc);
+	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
 
 	Lck_Lock(&lru->mtx);
 	lru->n_objcore++;
-	oc->flags |= OC_F_OFFLRU | OC_F_INSERT;
+	oc->flags |= OC_F_OFFLRU | OC_F_INSERT | OC_F_EXP;
+	if (when < 0)
+		oc->flags |= OC_F_MOVE;
+	else
+		oc->timer_when = when;
 	Lck_Unlock(&lru->mtx);
 
-	oc->timer_when = when;
-
 	exp_mail_it(oc);
 }
 
 /*--------------------------------------------------------------------
- * Object has been added to cache, record in lru & binheap.
+ * Insert new object.
  *
  * We grab a reference to the object, which will keep it around until
  * we decide its time to let it go.
  */
 
 void
-EXP_Insert(const struct object *o, double now)
+EXP_Insert(struct objcore *oc)
 {
-	struct objcore *oc;
-	struct lru *lru;
 
-	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-	oc = o->objcore;
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	HSH_Ref(oc);
-
-	assert(o->exp.t_origin != 0 && !isnan(o->exp.t_origin));
-	oc->last_lru = now;
-
-	AZ(oc->flags & OC_F_OFFLRU);
-
-	lru = oc_getlru(oc);
-	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
-
-	Lck_Lock(&lru->mtx);
-	lru->n_objcore++;
-	oc->flags |= OC_F_OFFLRU | OC_F_INSERT;
-	Lck_Unlock(&lru->mtx);
-
-	oc->timer_when = exp_when(o);
-	oc_updatemeta(oc);
-
-	exp_mail_it(oc);
+	EXP_Inject(oc, NULL, -1);
 }
 
 /*--------------------------------------------------------------------
@@ -211,6 +197,8 @@ EXP_Touch(struct objcore *oc)
 	if (Lck_Trylock(&lru->mtx))
 		return (0);
 
+	AN(oc->flags & OC_F_EXP);
+
 	if (!(oc->flags & OC_F_OFFLRU)) {
 		/* Can only it while it's actually on the LRU list */
 		VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
@@ -251,6 +239,7 @@ EXP_Rearm(const struct object *o)
 	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
 
 	Lck_Lock(&lru->mtx);
+	AN(oc->flags & OC_F_EXP);
 
 	if (when < 0)
 		oc->flags |= OC_F_DYING;
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index d65d181..3d75780 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -421,14 +421,14 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	assert(bo->refcount >= 1);
 
-	if (!(bo->fetch_obj->objcore->flags & OC_F_PRIVATE)) {
-		EXP_Insert(obj, bo->t_fetch);
-		AN(obj->objcore->ban);
-	}
-
 	AZ(bo->ws_o->overflow);
-	if (bo->do_stream)
+	if (bo->do_stream) {
 		HSH_Unbusy(&wrk->stats, obj->objcore);
+		if (!(obj->objcore->flags & OC_F_PRIVATE)) {
+			EXP_Insert(obj->objcore);
+			AN(obj->objcore->ban);
+		}
+	}
 
 	if (bo->vfp == NULL)
 		bo->vfp = &VFP_nop;
@@ -437,8 +437,13 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	VBO_setstate(bo, BOS_FETCHING);
 
 	V1F_fetch_body(wrk, bo);
-	if (!bo->do_stream)
+	if (!bo->do_stream) {
 		HSH_Unbusy(&wrk->stats, obj->objcore);
+		if (!(bo->fetch_obj->objcore->flags & OC_F_PRIVATE)) {
+			EXP_Insert(obj->objcore);
+			AN(obj->objcore->ban);
+		}
+	}
 	HSH_Complete(obj->objcore);
 
 	assert(bo->refcount >= 1);
@@ -516,15 +521,15 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	http_CopyHome(obj->http);
 
 
-	if (!(bo->fetch_obj->objcore->flags & OC_F_PRIVATE)) {
-		EXP_Insert(obj, bo->t_fetch);
-		AN(obj->objcore->ban);
-	}
-
 	AZ(bo->ws_o->overflow);
 	VBO_setstate(bo, BOS_FETCHING);
 	HSH_Unbusy(&wrk->stats, obj->objcore);
 
+	if (!(obj->objcore->flags & OC_F_PRIVATE)) {
+		EXP_Insert(obj->objcore);
+		AN(obj->objcore->ban);
+	}
+
 	st = NULL;
 	al = 0;
 
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index b2627fd..e0b35d8 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -411,8 +411,6 @@ V1F_fetch_body(struct worker *wrk, struct busyobj *bo)
 	if (bo->state == BOS_FAILED) {
 		wrk->stats.fetch_failed++;
 		obj->len = 0;
-		EXP_Clr(&obj->exp);
-		EXP_Rearm(obj);
 	} else {
 		assert(bo->state == BOS_FETCHING);
 



More information about the varnish-commit mailing list