Commit c72dd103 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3843 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2c87bd1f
...@@ -314,7 +314,7 @@ cnt_error(struct sess *sp) ...@@ -314,7 +314,7 @@ cnt_error(struct sess *sp)
w = sp->wrk; w = sp->wrk;
if (sp->obj == NULL) { if (sp->obj == NULL) {
HSH_Prealloc(sp); HSH_Prealloc(sp);
sp->obj = HSH_NewObject(sp); sp->obj = HSH_NewObject(sp, 1);
sp->obj->xid = sp->xid; sp->obj->xid = sp->xid;
sp->obj->entered = sp->t_req; sp->obj->entered = sp->t_req;
} else { } else {
...@@ -682,7 +682,7 @@ cnt_lookup(struct sess *sp) ...@@ -682,7 +682,7 @@ cnt_lookup(struct sess *sp)
VSL_stats->cache_miss++; VSL_stats->cache_miss++;
AZ(oc->obj); AZ(oc->obj);
o = HSH_NewObject(sp); o = HSH_NewObject(sp, 0);
o->objhead = oh; o->objhead = oh;
o->objcore = oc; o->objcore = oc;
...@@ -819,7 +819,7 @@ cnt_pass(struct sess *sp) ...@@ -819,7 +819,7 @@ cnt_pass(struct sess *sp)
assert(sp->handling == VCL_RET_PASS); assert(sp->handling == VCL_RET_PASS);
sp->acct_req.pass++; sp->acct_req.pass++;
HSH_Prealloc(sp); HSH_Prealloc(sp);
sp->obj = HSH_NewObject(sp); sp->obj = HSH_NewObject(sp, 1);
sp->sendbody = 1; sp->sendbody = 1;
sp->step = STP_FETCH; sp->step = STP_FETCH;
return (0); return (0);
......
...@@ -80,24 +80,35 @@ HSH_Grace(double g) ...@@ -80,24 +80,35 @@ HSH_Grace(double g)
} }
struct object * struct object *
HSH_NewObject(struct sess *sp) HSH_NewObject(struct sess *sp, int transient)
{ {
struct object *o; struct object *o;
struct storage *st; struct storage *st;
void *p;
st = STV_alloc(sp, params->obj_workspace);
XXXAN(st); if (transient) {
assert(st->space > sizeof *o); p = malloc(sizeof *o + params->obj_workspace);
o = (void *)st->ptr; /* XXX: align ? */ XXXAN(p);
st->len = sizeof *o; o = p;
memset(o, 0, sizeof *o); p = o + 1;
o->objstore = st; memset(o, 0, sizeof *o);
WS_Init(o->ws_o, "obj", o->magic = OBJECT_MAGIC;
st->ptr + st->len, st->space - st->len); WS_Init(o->ws_o, "obj", p, params->obj_workspace);
st->len = st->space; } 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); WS_Assert(o->ws_o);
http_Setup(o->http, o->ws_o); http_Setup(o->http, o->ws_o);
o->magic = OBJECT_MAGIC;
o->http->magic = HTTP_MAGIC; o->http->magic = HTTP_MAGIC;
o->refcnt = 1; o->refcnt = 1;
o->grace = NAN; o->grace = NAN;
...@@ -510,7 +521,10 @@ HSH_Deref(const struct worker *w, struct object **oo) ...@@ -510,7 +521,10 @@ HSH_Deref(const struct worker *w, struct object **oo)
ESI_Destroy(o); ESI_Destroy(o);
HSH_Freestore(o); HSH_Freestore(o);
STV_free(o->objstore); if (o->objstore != NULL)
STV_free(o->objstore);
else
FREE_OBJ(o);
w->stats->n_object--; w->stats->n_object--;
if (oh == NULL) { if (oh == NULL) {
......
...@@ -50,7 +50,7 @@ struct hash_slinger { ...@@ -50,7 +50,7 @@ struct hash_slinger {
}; };
/* cache_hash.c */ /* 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_Prealloc(const struct sess *sp);
void HSH_Cleanup(struct worker *w); void HSH_Cleanup(struct worker *w);
void HSH_Freestore(struct object *o); void HSH_Freestore(struct object *o);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment