From: phk Date: Mon, 1 Oct 2007 08:54:26 +0000 (+0000) Subject: Move the objects and their http header into storage instead of X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cf57e69d33dd287524a67d9ae9bb2e0665e0a62;p=varnish Move the objects and their http header into storage instead of malloc'ing them. This should reduce the N(nobj) swap-loading considerably. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2073 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e0e58e97..74ff9fc9 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -222,6 +222,7 @@ struct object { unsigned refcnt; unsigned xid; struct objhead *objhead; + struct storage *objstore; struct ws ws_o[1]; unsigned char *vary; @@ -448,7 +449,7 @@ int EXP_NukeOne(struct sess *sp); 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); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 7fe52db0..1f6819f0 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -259,7 +259,6 @@ Fetch(struct sess *sp) struct storage *st; struct bereq *bereq; int mklen, is_head; - unsigned len; struct http_conn htc[1]; int i; @@ -276,6 +275,13 @@ Fetch(struct sess *sp) 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,13 +316,6 @@ Fetch(struct sess *sp) /* 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); diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 25cb7dd3..a26f1788 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -67,9 +67,10 @@ static struct hash_slinger *hash; /* 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 @@ HSH_Prealloc(const struct sess *sp) } 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 @@ HSH_Deref(struct object *o) 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) diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 0c85f3d5..7302e84d 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -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 @@ wrk_thread(void *priv) FREE_OBJ(w->nobjhead); } if (w->nobj!= NULL) - FREE_OBJ(w->nobj); + STV_free(w->nobj->objstore); return (NULL); }