[master] d387098 Make FetchStorage() take a busyobj instead of a worker as arg.

Poul-Henning Kamp phk at varnish-cache.org
Wed Feb 15 13:49:52 CET 2012


commit d387098f00fabf8965ac47f1313cf63ac4d16a46
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 15 12:49:25 2012 +0000

    Make FetchStorage() take a busyobj instead of a worker as arg.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f2f64d3..74a8b5d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -745,10 +745,10 @@ void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
 void EXP_Init(void);
 void EXP_Rearm(const struct object *o);
 int EXP_Touch(struct objcore *oc);
-int EXP_NukeOne(struct vsl_log *, struct dstat *, struct lru *lru);
+int EXP_NukeOne(struct busyobj *, struct lru *lru);
 
 /* cache_fetch.c */
-struct storage *FetchStorage(struct worker *w, ssize_t sz);
+struct storage *FetchStorage(struct busyobj *, ssize_t sz);
 int FetchError(struct busyobj *, const char *error);
 int FetchError2(struct busyobj *, const char *error, const char *more);
 int FetchHdr(struct sess *sp, int need_host_hdr, int sendbody);
@@ -1013,7 +1013,7 @@ int RFC2616_Do_Cond(const struct sess *sp);
 /* stevedore.c */
 struct object *STV_NewObject(struct worker *wrk, const char *hint, unsigned len,
     uint16_t nhttp);
-struct storage *STV_alloc(struct worker *w, size_t size);
+struct storage *STV_alloc(struct busyobj *, size_t size);
 void STV_trim(struct storage *st, size_t size);
 void STV_free(struct storage *st);
 void STV_open(void);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index c3ca15e..c16568a 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -94,7 +94,7 @@ vfp_esi_bytes_uu(struct worker *wrk, const struct vef_priv *vef,
 	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 
 	while (bytes > 0) {
-		st = FetchStorage(wrk, 0);
+		st = FetchStorage(wrk->busyobj, 0);
 		if (st == NULL)
 			return (-1);
 		wl = vef_read(htc,
@@ -396,7 +396,7 @@ vfp_esi_end(struct worker *wrk)
 			l = VSB_len(vsb);
 			assert(l > 0);
 			/* XXX: This is a huge waste of storage... */
-			bo->fetch_obj->esidata = STV_alloc(wrk, l);
+			bo->fetch_obj->esidata = STV_alloc(bo, l);
 			if (bo->fetch_obj->esidata != NULL) {
 				memcpy(bo->fetch_obj->esidata->ptr,
 				    VSB_data(vsb), l);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 9bdf25f..060ed58 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -414,7 +414,7 @@ exp_timer(struct sess *sp, void *priv)
  */
 
 int
-EXP_NukeOne(struct vsl_log *vsl, struct dstat *ds, struct lru *lru)
+EXP_NukeOne(struct busyobj *bo, struct lru *lru)
 {
 	struct objcore *oc;
 
@@ -445,8 +445,8 @@ EXP_NukeOne(struct vsl_log *vsl, struct dstat *ds, struct lru *lru)
 		return (-1);
 
 	/* XXX: bad idea for -spersistent */
-	WSL(vsl, SLT_ExpKill, -1, "%u LRU", oc_getxid(ds, oc));
-	(void)HSH_Deref(ds, oc, NULL);
+	WSL(bo->vsl, SLT_ExpKill, -1, "%u LRU", oc_getxid(bo->stats, oc));
+	(void)HSH_Deref(bo->stats, oc, NULL);
 	return (1);
 }
 
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 928ecc4..e520e6d 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -92,7 +92,7 @@ vfp_nop_begin(struct worker *wrk, size_t estimate)
 {
 
 	if (estimate > 0)
-		(void)FetchStorage(wrk, estimate);
+		(void)FetchStorage(wrk->busyobj, estimate);
 }
 
 /*--------------------------------------------------------------------
@@ -114,7 +114,7 @@ vfp_nop_bytes(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
 
 	AZ(wrk->busyobj->fetch_failed);
 	while (bytes > 0) {
-		st = FetchStorage(wrk, 0);
+		st = FetchStorage(wrk->busyobj, 0);
 		if (st == NULL)
 			return(-1);
 		l = st->space - st->len;
@@ -170,13 +170,14 @@ static struct vfp vfp_nop = {
  */
 
 struct storage *
-FetchStorage(struct worker *wrk, ssize_t sz)
+FetchStorage(struct busyobj *bo, ssize_t sz)
 {
 	ssize_t l;
 	struct storage *st;
 	struct object *obj;
 
-	obj = wrk->busyobj->fetch_obj;
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	obj = bo->fetch_obj;
 	CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
 	st = VTAILQ_LAST(&obj->store, storagehead);
 	if (st != NULL && st->len < st->space)
@@ -187,9 +188,9 @@ FetchStorage(struct worker *wrk, ssize_t sz)
 		l = sz;
 	if (l == 0)
 		l = cache_param->fetch_chunksize;
-	st = STV_alloc(wrk, l);
+	st = STV_alloc(bo, l);
 	if (st == NULL) {
-		(void)FetchError(wrk->busyobj, "Could not get storage");
+		(void)FetchError(bo, "Could not get storage");
 		return (NULL);
 	}
 	AZ(st->len);
@@ -507,7 +508,7 @@ FetchBody(struct worker *wrk, struct object *obj)
 	CHECK_OBJ_NOTNULL(obj->http, HTTP_MAGIC);
 
 	/*
- 	 * XXX: The busyobj needs a dstat, but it is not obvious which one
+	 * XXX: The busyobj needs a dstat, but it is not obvious which one
 	 * XXX: it should be (own/borrowed).  For now borrow the wrk's.
 	 */
 	AZ(bo->stats);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index d16d4b1..c2764b5 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -207,7 +207,7 @@ VGZ_ObufStorage(struct worker *wrk, struct vgz *vg)
 {
 	struct storage *st;
 
-	st = FetchStorage(wrk, 0);
+	st = FetchStorage(wrk->busyobj, 0);
 	if (st == NULL)
 		return (-1);
 
@@ -627,7 +627,7 @@ vfp_testgzip_bytes(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
 	AZ(vg->vz.avail_in);
 	while (bytes > 0) {
-		st = FetchStorage(wrk, 0);
+		st = FetchStorage(wrk->busyobj, 0);
 		if (st == NULL)
 			return(-1);
 		l = st->space - st->len;
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 50db0db..2fce063 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -157,18 +157,20 @@ stv_pick_stevedore(struct vsl_log *vsl, const char **hint)
 /*-------------------------------------------------------------------*/
 
 static struct storage *
-stv_alloc(struct worker *w, const struct object *obj, size_t size)
+stv_alloc(struct busyobj *bo, size_t size)
 {
 	struct storage *st;
 	struct stevedore *stv;
 	unsigned fail = 0;
+	struct object *obj;
 
 	/*
 	 * Always use the stevedore which allocated the object in order to
 	 * keep an object inside the same stevedore.
 	 */
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	obj = bo->fetch_obj;
 	CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
 	stv = obj->objstore->stevedore;
 	CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
 
@@ -188,7 +190,7 @@ stv_alloc(struct worker *w, const struct object *obj, size_t size)
 		}
 
 		/* no luck; try to free some space and keep trying */
-		if (EXP_NukeOne(w->vsl, &w->stats, stv->lru) == -1)
+		if (EXP_NukeOne(bo, stv->lru) == -1)
 			break;
 
 		/* Enough is enough: try another if we have one */
@@ -337,12 +339,16 @@ STV_NewObject(struct worker *wrk, const char *hint, unsigned wsl,
 		} while (o == NULL && stv != stv0);
 	}
 	if (o == NULL) {
+		/* XXX: lend busyobj wrk's stats while we nuke */
+		AZ(wrk->busyobj->stats);
+		wrk->busyobj->stats = &wrk->stats;
 		/* no luck; try to free some space and keep trying */
 		for (i = 0; o == NULL && i < cache_param->nuke_limit; i++) {
-			if (EXP_NukeOne(wrk->vsl, &wrk->stats, stv->lru) == -1)
+			if (EXP_NukeOne(wrk->busyobj, stv->lru) == -1)
 				break;
 			o = stv->allocobj(stv, wrk, ltot, &soc);
 		}
+		wrk->busyobj->stats = NULL;
 	}
 
 	if (o == NULL)
@@ -373,10 +379,10 @@ STV_Freestore(struct object *o)
 /*-------------------------------------------------------------------*/
 
 struct storage *
-STV_alloc(struct worker *w, size_t size)
+STV_alloc(struct busyobj *bo, size_t size)
 {
 
-	return (stv_alloc(w, w->busyobj->fetch_obj, size));
+	return (stv_alloc(bo, size));
 }
 
 void



More information about the varnish-commit mailing list