r1321 - in branches/1.0: . bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Thu Apr 19 16:50:38 CEST 2007


Author: des
Date: 2007-04-19 16:50:38 +0200 (Thu, 19 Apr 2007)
New Revision: 1321

Modified:
   branches/1.0/
   branches/1.0/bin/varnishd/cache.h
   branches/1.0/bin/varnishd/cache_center.c
   branches/1.0/bin/varnishd/cache_hash.c
Log:
 r37054 at cat (orig r1278):  phk | 2007-03-07 11:38:20 +0100
 Add a bit of garbage collection to yesterdays change:  Passed objects need
 to have their storage properly reclaimed, including the actual content
 of a obj.pass=1 cache entry, once we have sent the content to the original
 requestor.
 



Property changes on: branches/1.0
___________________________________________________________________
Name: svk:merge
   - d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1277
   + d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1278

Modified: branches/1.0/bin/varnishd/cache.h
===================================================================
--- branches/1.0/bin/varnishd/cache.h	2007-04-19 14:50:37 UTC (rev 1320)
+++ branches/1.0/bin/varnishd/cache.h	2007-04-19 14:50:38 UTC (rev 1321)
@@ -351,6 +351,7 @@
 
 /* cache_hash.c */
 void HSH_Prealloc(struct sess *sp);
+void HSH_Freestore(struct object *o);
 struct object *HSH_Lookup(struct sess *sp);
 void HSH_Unbusy(struct object *o);
 void HSH_Ref(struct object *o);

Modified: branches/1.0/bin/varnishd/cache_center.c
===================================================================
--- branches/1.0/bin/varnishd/cache_center.c	2007-04-19 14:50:37 UTC (rev 1320)
+++ branches/1.0/bin/varnishd/cache_center.c	2007-04-19 14:50:38 UTC (rev 1321)
@@ -136,6 +136,10 @@
 {
 
 	RES_WriteObj(sp);
+	if (sp->obj->objhead != NULL && sp->obj->pass) {
+		/* we will no longer need the storage */
+		HSH_Freestore(sp->obj);
+	}
 	HSH_Deref(sp->obj);
 	sp->obj = NULL;
 	sp->step = STP_DONE;
@@ -300,9 +304,10 @@
 		sp->obj->pass = 1;
 
 	sp->obj->cacheable = 1;
-	HSH_Ref(sp->obj); /* get another, STP_DELIVER will deref */
-	if (sp->obj->objhead != NULL)
+	if (sp->obj->objhead != NULL) {
+		HSH_Ref(sp->obj); /* get another, STP_DELIVER will deref */
 		HSH_Unbusy(sp->obj);
+	}
 	sp->wrk->acct.fetch++;
 	sp->step = STP_DELIVER;
 	return (0);

Modified: branches/1.0/bin/varnishd/cache_hash.c
===================================================================
--- branches/1.0/bin/varnishd/cache_hash.c	2007-04-19 14:50:37 UTC (rev 1320)
+++ branches/1.0/bin/varnishd/cache_hash.c	2007-04-19 14:50:38 UTC (rev 1321)
@@ -96,6 +96,18 @@
 		CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC);
 }
 
+void
+HSH_Freestore(struct object *o)
+{
+	struct storage *st, *stn;
+
+	TAILQ_FOREACH_SAFE(st, &o->store, list, stn) {
+		CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
+		TAILQ_REMOVE(&o->store, st, list);
+		st->stevedore->free(st);
+	}
+}
+
 struct object *
 HSH_Lookup(struct sess *sp)
 {
@@ -213,43 +225,37 @@
 HSH_Deref(struct object *o)
 {
 	struct objhead *oh;
-	struct storage *st, *stn;
 	unsigned r;
 
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	oh = o->objhead;
-	if (oh == NULL) {
-		/* Pass object, not referenced anywhere */
-		free(o);
-		return;
+	if (oh != NULL) {
+		CHECK_OBJ(oh, OBJHEAD_MAGIC);
+
+		/* drop ref on object */
+		LOCK(&oh->mtx);
 	}
-
-	CHECK_OBJ(oh, OBJHEAD_MAGIC);
-
-	/* drop ref on object */
-	LOCK(&oh->mtx);
 	assert(o->refcnt > 0);
 	r = --o->refcnt;
-	if (!r)
-		TAILQ_REMOVE(&oh->objects, o, list);
-	UNLOCK(&oh->mtx);
+	if (oh != NULL) {
+		if (!r)
+			TAILQ_REMOVE(&oh->objects, o, list);
+		UNLOCK(&oh->mtx);
+	}
 
 	/* If still referenced, done */
 	if (r != 0)
 		return;
 
-	if (o->http.s != NULL) {
+	if (o->http.s != NULL)
 		free(o->http.s);
-	}
 
-	TAILQ_FOREACH_SAFE(st, &o->store, list, stn) {
-		CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
-		TAILQ_REMOVE(&o->store, st, list);
-		st->stevedore->free(st);
-	}
+	HSH_Freestore(o);
 	free(o);
 	VSL_stats->n_object--;
 
+	if (oh == NULL)
+		return;
 	/* Drop our ref on the objhead */
 	if (hash->deref(oh))
 		return;




More information about the varnish-commit mailing list