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

Polish the object/storage allocation code a bit, in preparation for

some significant changes to the policy.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4228 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent c4b1e714
......@@ -335,7 +335,7 @@ cnt_error(struct sess *sp)
if (sp->obj == NULL) {
HSH_Prealloc(sp);
sp->wrk->cacheable = 0;
sp->obj = STV_NewObject(sp, 0);
sp->obj = STV_NewObject(sp, 0, 0);
sp->obj->xid = sp->xid;
sp->obj->entered = sp->t_req;
} else {
......@@ -526,7 +526,8 @@ cnt_fetch(struct sess *sp)
* XXX: If we have a Length: header, we should allocate the body
* XXX: also.
*/
sp->obj = STV_NewObject(sp, l);
sp->obj = STV_NewObject(sp, l, sp->wrk->ttl);
if (sp->objhead != NULL) {
CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
......
......@@ -65,42 +65,60 @@ LRU_Alloc(void)
return (l);
}
/*********************************************************************
* XXX: trust pointer writes to be atomic
*/
static struct stevedore *
stv_pick_stevedore(void)
{
struct stevedore *stv;
/* pick a stevedore and bump the head along */
stv = VTAILQ_NEXT(stv_next, list);
if (stv == NULL)
stv = VTAILQ_FIRST(&stevedores);
AN(stv);
AN(stv->name);
stv_next = stv;
return (stv);
}
/*********************************************************************/
struct object *
STV_NewObject(struct sess *sp, unsigned l)
STV_NewObject(struct sess *sp, unsigned l, double ttl)
{
struct object *o;
struct storage *st;
void *p;
struct storage *st = NULL;
(void)ttl;
if (l == 0)
l = 1024;
if (params->obj_workspace > 0 && params->obj_workspace > l)
l = params->obj_workspace;
if (!sp->wrk->cacheable) {
p = malloc(sizeof *o + l);
XXXAN(p);
o = p;
p = o + 1;
memset(o, 0, sizeof *o);
o->magic = OBJECT_MAGIC;
WS_Init(o->ws_o, "obj", p, l);
o = malloc(sizeof *o + l);
XXXAN(o);
} else {
st = STV_alloc(sp, sizeof *o + l);
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);
xxxassert(st->space >= (sizeof *o + l));
st->len = st->space;
l = st->space - sizeof *o;
o = (void *)st->ptr; /* XXX: align ? */
}
memset(o, 0, sizeof *o);
o->objstore = st;
o->magic = OBJECT_MAGIC;
WS_Init(o->ws_o, "obj", (o + 1), l);
WS_Assert(o->ws_o);
http_Setup(o->http, o->ws_o);
o->http->magic = HTTP_MAGIC;
o->refcnt = 1;
......@@ -135,13 +153,7 @@ STV_alloc(struct sess *sp, size_t size)
for (;;) {
if (stv == NULL) {
/* pick a stevedore and bump the head along */
stv = VTAILQ_NEXT(stv_next, list);
if (stv == NULL)
stv = VTAILQ_FIRST(&stevedores);
AN(stv);
AN(stv->name);
stv_next = stv;
stv = stv_pick_stevedore();
fail = 0;
}
......
......@@ -37,6 +37,7 @@ struct object;
typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
typedef void storage_open_f(const struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
typedef struct object *storage_alloc_obj_f(struct stevedore *, size_t size, double ttl);
typedef void storage_trim_f(struct storage *, size_t size);
typedef void storage_free_f(struct storage *);
typedef void storage_object_f(const struct sess *sp);
......@@ -50,6 +51,7 @@ struct stevedore {
storage_init_f *init; /* called by mgt process */
storage_open_f *open; /* called by cache process */
storage_alloc_f *alloc;
storage_alloc_obj_f *allocobj;
storage_trim_f *trim;
storage_free_f *free;
storage_object_f *object;
......@@ -63,7 +65,7 @@ struct stevedore {
VTAILQ_ENTRY(stevedore) list;
};
struct object *STV_NewObject(struct sess *sp, unsigned len);
struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl);
struct storage *STV_alloc(struct sess *sp, size_t size);
void STV_trim(struct storage *st, size_t size);
void STV_free(struct storage *st);
......
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