r3843 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Feb 28 20:00:00 CET 2009


Author: phk
Date: 2009-02-28 20:00:00 +0100 (Sat, 28 Feb 2009)
New Revision: 3843

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/hash_slinger.h
Log:
When we know that an object will not make it into the hash
table permanently, use malloc(3) as backing store.

This affects mainly pass'ed requests.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-02-28 18:34:07 UTC (rev 3842)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-02-28 19:00:00 UTC (rev 3843)
@@ -314,7 +314,7 @@
 	w = sp->wrk;
 	if (sp->obj == NULL) {
 		HSH_Prealloc(sp);
-		sp->obj = HSH_NewObject(sp);
+		sp->obj = HSH_NewObject(sp, 1);
 		sp->obj->xid = sp->xid;
 		sp->obj->entered = sp->t_req;
 	} else {
@@ -682,7 +682,7 @@
 		VSL_stats->cache_miss++;
 
 		AZ(oc->obj);
-		o = HSH_NewObject(sp);
+		o = HSH_NewObject(sp, 0);
 
 		o->objhead = oh;
 		o->objcore = oc;
@@ -819,7 +819,7 @@
 	assert(sp->handling == VCL_RET_PASS);
 	sp->acct_req.pass++;
 	HSH_Prealloc(sp);
-	sp->obj = HSH_NewObject(sp);
+	sp->obj = HSH_NewObject(sp, 1);
 	sp->sendbody = 1;
 	sp->step = STP_FETCH;
 	return (0);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-02-28 18:34:07 UTC (rev 3842)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-02-28 19:00:00 UTC (rev 3843)
@@ -80,24 +80,35 @@
 }
 
 struct object *
-HSH_NewObject(struct sess *sp)
+HSH_NewObject(struct sess *sp, int transient)
 {
 	struct object *o;
 	struct storage *st;
+	void *p;
 
-	st = STV_alloc(sp, params->obj_workspace);
-	XXXAN(st);
-	assert(st->space > sizeof *o);
-	o = (void *)st->ptr; /* XXX: align ? */
-	st->len = sizeof *o;
-	memset(o, 0, sizeof *o);
-	o->objstore = st;
-	WS_Init(o->ws_o, "obj",
-	    st->ptr + st->len, st->space - st->len);
-	st->len = st->space;
+	if (transient) {
+		p = malloc(sizeof *o + params->obj_workspace);
+		XXXAN(p);
+		o = p;
+		p = o + 1;
+		memset(o, 0, sizeof *o);
+		o->magic = OBJECT_MAGIC;
+		WS_Init(o->ws_o, "obj", p, params->obj_workspace);
+	} else {
+		st = STV_alloc(sp, params->obj_workspace);
+		XXXAN(st);
+		assert(st->space > sizeof *o);
+		o = (void *)st->ptr; /* XXX: align ? */
+		st->len = sizeof *o;
+		memset(o, 0, sizeof *o);
+		o->magic = OBJECT_MAGIC;
+		o->objstore = st;
+		WS_Init(o->ws_o, "obj",
+		    st->ptr + st->len, st->space - st->len);
+		st->len = st->space;
+	}
 	WS_Assert(o->ws_o);
 	http_Setup(o->http, o->ws_o);
-	o->magic = OBJECT_MAGIC;
 	o->http->magic = HTTP_MAGIC;
 	o->refcnt = 1;
 	o->grace = NAN;
@@ -510,7 +521,10 @@
 
 	ESI_Destroy(o);
 	HSH_Freestore(o);
-	STV_free(o->objstore);
+	if (o->objstore != NULL)
+		STV_free(o->objstore);
+	else
+		FREE_OBJ(o);
 	w->stats->n_object--;
 
 	if (oh == NULL) {

Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-02-28 18:34:07 UTC (rev 3842)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-02-28 19:00:00 UTC (rev 3843)
@@ -50,7 +50,7 @@
 };
 
 /* cache_hash.c */
-struct object *HSH_NewObject(struct sess *sp);
+struct object *HSH_NewObject(struct sess *sp, int transient);
 void HSH_Prealloc(const struct sess *sp);
 void HSH_Cleanup(struct worker *w);
 void HSH_Freestore(struct object *o);



More information about the varnish-commit mailing list