r2073 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Oct 1 10:54:27 CEST 2007


Author: phk
Date: 2007-10-01 10:54:26 +0200 (Mon, 01 Oct 2007)
New Revision: 2073

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Move the objects and their http header into storage instead of
malloc'ing them.

This should reduce the N(nobj) swap-loading considerably.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2007-10-01 07:45:58 UTC (rev 2072)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2007-10-01 08:54:26 UTC (rev 2073)
@@ -222,6 +222,7 @@
 	unsigned 		refcnt;
 	unsigned		xid;
 	struct objhead		*objhead;
+	struct storage		*objstore;
 
 	struct ws		ws_o[1];
 	unsigned char		*vary;
@@ -448,7 +449,7 @@
 int Fetch(struct sess *sp);
 
 /* cache_hash.c */
-void HSH_Prealloc(const struct sess *sp);
+void HSH_Prealloc(struct sess *sp);
 int HSH_Compare(const struct sess *sp, const struct objhead *o);
 void HSH_Copy(const struct sess *sp, const struct objhead *o);
 struct object *HSH_Lookup(struct sess *sp);

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-10-01 07:45:58 UTC (rev 2072)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-10-01 08:54:26 UTC (rev 2073)
@@ -259,7 +259,6 @@
 	struct storage *st;
 	struct bereq *bereq;
 	int mklen, is_head;
-	unsigned len;
 	struct http_conn htc[1];
 	int i;
 
@@ -276,6 +275,13 @@
 
 	sp->obj->xid = sp->xid;
 
+	/* Set up obj's workspace */
+	st = sp->obj->objstore;
+	WS_Init(sp->obj->ws_o, st->ptr + st->len, st->space - st->len);
+	st->len = st->space;
+	WS_Assert(sp->obj->ws_o);
+	http_Setup(sp->obj->http, sp->obj->ws_o);
+
 	vc = VBE_GetFd(sp);
 	if (vc == NULL)
 		return (1);
@@ -310,14 +316,7 @@
 
 	/* Filter into object */
 	hp2 = sp->obj->http;
-	len = Tlen(htc->rxbuf);
-	len += 256;	/* XXX: margin for content-length etc */
 
-	b = malloc(len);
-	AN(b);
-	WS_Init(sp->obj->ws_o, b, len);
-	http_Setup(hp2, sp->obj->ws_o);
-
 	hp2->logtag = HTTP_Obj;
 	http_CopyResp(hp2, hp);
 	http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2007-10-01 07:45:58 UTC (rev 2072)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2007-10-01 08:54:26 UTC (rev 2073)
@@ -67,9 +67,10 @@
 
 /* Precreate an objhead and object for later use */
 void
-HSH_Prealloc(const struct sess *sp)
+HSH_Prealloc(struct sess *sp)
 {
 	struct worker *w;
+	struct storage *st;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	w = sp->wrk;
@@ -84,8 +85,12 @@
 	} else
 		CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC);
 	if (w->nobj == NULL) {
-		w->nobj = calloc(sizeof *w->nobj, 1);
-		XXXAN(w->nobj);
+		st = STV_alloc(sp, params->mem_workspace);
+		XXXAN(st);
+		w->nobj = (void *)st->ptr;
+		st->len = sizeof *w->nobj;
+		memset(w->nobj, 0, sizeof *w->nobj);
+		w->nobj->objstore = st;
 		w->nobj->magic = OBJECT_MAGIC;
 		w->nobj->http->magic = HTTP_MAGIC;
 		w->nobj->busy = 1;
@@ -304,14 +309,11 @@
 	if (r != 0)
 		return;
 
-	if (o->http->ws != NULL && o->http->ws->s != NULL)
-		free(o->http->ws->s);
-
 	if (o->vary != NULL)
 		free(o->vary);
 
 	HSH_Freestore(o);
-	FREE_OBJ(o);
+	STV_free(o->objstore);
 	VSL_stats->n_object--;
 
 	if (oh == NULL)

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2007-10-01 07:45:58 UTC (rev 2072)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2007-10-01 08:54:26 UTC (rev 2073)
@@ -56,6 +56,7 @@
 #include "vcl.h"
 #include "cli_priv.h"
 #include "cache.h"
+#include "stevedore.h"
 
 VTAILQ_HEAD(workerhead, worker);
 
@@ -261,7 +262,7 @@
 		FREE_OBJ(w->nobjhead);
 	}
 	if (w->nobj!= NULL)
-		FREE_OBJ(w->nobj);
+		STV_free(w->nobj->objstore);
 	return (NULL);
 }
 




More information about the varnish-commit mailing list