r4228 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Fri Sep 4 12:08:24 CEST 2009
Author: phk
Date: 2009-09-04 12:08:23 +0200 (Fri, 04 Sep 2009)
New Revision: 4228
Modified:
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/stevedore.c
trunk/varnish-cache/bin/varnishd/stevedore.h
Log:
Polish the object/storage allocation code a bit, in preparation for
some significant changes to the policy.
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-09-04 09:07:27 UTC (rev 4227)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-09-04 10:08:23 UTC (rev 4228)
@@ -335,7 +335,7 @@
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,8 +526,9 @@
* 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);
CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c 2009-09-04 09:07:27 UTC (rev 4227)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c 2009-09-04 10:08:23 UTC (rev 4228)
@@ -65,42 +65,60 @@
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);
+ xxxassert(st->space >= (sizeof *o + l));
+
+ st->len = st->space;
+ l = 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;
}
+ 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 @@
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;
}
Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h 2009-09-04 09:07:27 UTC (rev 4227)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h 2009-09-04 10:08:23 UTC (rev 4228)
@@ -37,6 +37,7 @@
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 @@
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 @@
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);
More information about the varnish-commit
mailing list