Commit 8053cd71 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Collapse the object allocation/creation to a 1-phase process which

simplifies stuff somewhat for the main code and remains the same
tricky business for -spersistent.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5562 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent d4e7ed24
......@@ -586,7 +586,6 @@ cnt_fetch(struct sess *sp)
sp->obj->xid = sp->xid;
sp->obj->response = sp->err_code;
sp->obj->cacheable = sp->wrk->cacheable;
sp->obj->ttl = sp->wrk->ttl;
sp->obj->grace = sp->wrk->grace;
if (sp->obj->ttl == 0. && sp->obj->grace == 0.)
sp->obj->cacheable = 0;
......@@ -594,6 +593,7 @@ cnt_fetch(struct sess *sp)
sp->obj->entered = sp->wrk->entered;
WS_Assert(sp->obj->ws_o);
/* Filter into object */
hp = sp->wrk->beresp;
hp2 = sp->obj->http;
......@@ -625,14 +625,6 @@ cnt_fetch(struct sess *sp)
return (0);
}
if (sp->wrk->cacheable) {
/*
* Needs ttl & ban to be in order.
* XXX call oc->updatemeta() instead ?
*/
STV_Object(sp);
}
if (sp->wrk->do_esi)
ESI_Parse(sp);
......
......@@ -96,7 +96,6 @@ HSH_Prealloc(const struct sess *sp)
ALLOC_OBJ(oc, OBJCORE_MAGIC);
XXXAN(oc);
w->nobjcore = oc;
oc->methods = &default_oc_methods;
w->stats.n_objectcore++;
oc->flags |= OC_F_BUSY;
}
......
......@@ -167,7 +167,7 @@ struct stv_objsecrets {
struct object *
STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
struct stv_objsecrets *soc)
const struct stv_objsecrets *soc)
{
struct object *o;
unsigned l;
......@@ -195,18 +195,22 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
o->http->magic = HTTP_MAGIC;
o->grace = NAN;
o->entered = NAN;
o->ttl = soc->ttl;
VTAILQ_INIT(&o->store);
sp->wrk->stats.n_object++;
if (sp->objhead != NULL) {
CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
sp->objcore->priv = o; /* XXX */
o->objcore = sp->objcore;
sp->objcore->objhead = sp->objhead;
sp->objhead = NULL; /* refcnt follows pointer. */
sp->objcore = NULL; /* refcnt follows pointer. */
BAN_NewObj(o);
o->objcore->methods = &default_oc_methods;
o->objcore->priv = o;
}
return (o);
}
......@@ -218,7 +222,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
static struct object *
stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
struct stv_objsecrets *soc)
const struct stv_objsecrets *soc)
{
struct object *o;
struct storage *st;
......@@ -304,17 +308,6 @@ struct objcore_methods default_oc_methods = {
.freeobj = default_oc_freeobj,
};
void
STV_Object(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objstore, STORAGE_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objstore->stevedore, STEVEDORE_MAGIC);
AssertObjBusy(sp->obj);
if (sp->obj->objstore->stevedore->object != NULL)
sp->obj->objstore->stevedore->object(sp);
}
/*********************************************************************/
struct storage *
......
......@@ -41,9 +41,8 @@ typedef void storage_open_f(const struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
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);
typedef struct object *storage_allocobj_f(struct stevedore *, struct sess *sp,
unsigned ltot, struct stv_objsecrets *);
unsigned ltot, const struct stv_objsecrets *);
typedef void storage_close_f(const struct stevedore *);
......@@ -57,7 +56,6 @@ struct stevedore {
storage_alloc_f *alloc; /* --//-- */
storage_trim_f *trim; /* --//-- */
storage_free_f *free; /* --//-- */
storage_object_f *object; /* --//-- */
storage_close_f *close; /* --//-- */
storage_allocobj_f *allocobj; /* --//-- */
......@@ -71,7 +69,7 @@ struct stevedore {
};
struct object *STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
struct stv_objsecrets *soc);
const struct stv_objsecrets *soc);
struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,
unsigned nhttp);
......@@ -83,7 +81,6 @@ void STV_close(void);
struct lru *STV_lru(const struct storage *st);
void STV_Config(const char *spec);
void STV_Config_Transient(void);
void STV_Object(const struct sess *sp);
struct lru *LRU_Alloc(void);
......
......@@ -1286,11 +1286,15 @@ smp_close(const struct stevedore *st)
}
/*--------------------------------------------------------------------
* Allocate a bite
* Allocate a bite, possibly for an object.
*
* if the segment pointer is provided, we are allocating for an object
* structure, and should reserve space for the smp_object structure in
* the index. This complicates things somewhat.
*/
static struct storage *
smp_allocx(struct stevedore *st, size_t size, struct objcore *oc)
smp_allocx(struct stevedore *st, size_t size, struct smp_seg **sgp)
{
struct smp_sc *sc;
struct storage *ss;
......@@ -1310,17 +1314,16 @@ smp_allocx(struct stevedore *st, size_t size, struct objcore *oc)
overhead = C_ALIGN(sizeof *ss);
overhead += SEG_SPACE * 2;
if (oc == NULL) {
if (sgp == NULL) {
overhead += C_ALIGN(sc->objreserv);
} else {
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
overhead +=
C_ALIGN(sizeof(struct smp_object) + sc->objreserv);
}
needed = overhead + size;
left = smp_spaceleft(sg);
if (oc == NULL && needed > left && (overhead + 4096) < left) {
if (sgp == NULL && needed > left && (overhead + 4096) < left) {
/* XXX: Also check the bit we cut off isn't silly
* short
*/
......@@ -1337,7 +1340,7 @@ smp_allocx(struct stevedore *st, size_t size, struct objcore *oc)
/* If there is space, fine */
if (needed <= left &&
(oc == NULL || sg->nalloc1 < sc->aim_nobj))
(sgp == NULL || sg->nalloc1 < sc->aim_nobj))
break;
smp_close_seg(sc, sc->cur_seg);
......@@ -1364,13 +1367,21 @@ smp_allocx(struct stevedore *st, size_t size, struct objcore *oc)
/* Paint our marker */
memcpy(sc->ptr + sg->next_addr, "HERE", 4);
if (oc != NULL) {
if (sgp != NULL) {
/* Make reservation in the index */
assert(sg->nalloc1 < sc->aim_nobj);
sg->nalloc1++;
sc->objreserv += sizeof (struct smp_object);
assert(sc->objreserv <= smp_spaceleft(sg));
oc->priv2 = sg;
/*
* NB: Tricky.
* We can not use the smp_getobj() method yet, because the
* smp_object's position is not finalized until the segment
* closes. Fortunately we don't need to either, because newly
* created objects will never regress into NEEDFIXUP state,
* so the default oc->methods, will do just fine.
*/
*sgp = sg;
}
sg->nalloc++;
......@@ -1398,57 +1409,52 @@ smp_allocx(struct stevedore *st, size_t size, struct objcore *oc)
static struct object *
smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
struct stv_objsecrets *soc)
const struct stv_objsecrets *soc)
{
struct object *o;
struct storage *st;
st = smp_allocx(stv, ltot, sp->objcore);
XXXAN(st);
xxxassert(st->space >= ltot);
ltot = st->len = st->space;
o = STV_MkObject(sp, st->ptr, ltot, soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
return (o);
}
/*--------------------------------------------------------------------
* Designate object
*/
static void
smp_object(const struct sess *sp)
{
struct smp_sc *sc;
struct smp_seg *sg;
struct smp_object *so;
struct objcore *oc;
CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
/* XXX: temporary sanity */
AN(sp->objhead);
AN(sp->wrk->cacheable);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objstore, STORAGE_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objstore->stevedore, STEVEDORE_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objcore, OBJCORE_MAGIC);
CAST_OBJ_NOTNULL(sg, sp->obj->objcore->priv2, SMP_SEG_MAGIC);
CAST_OBJ_NOTNULL(sc, sp->obj->objstore->priv, SMP_SC_MAGIC);
sg = NULL;
st = smp_allocx(stv, ltot, &sg);
if (st == NULL)
return (NULL);
sp->obj->objcore->flags |= OC_F_LRUDONTMOVE;
assert(st->space >= ltot);
ltot = st->len = st->space;
o = STV_MkObject(sp, st->ptr, ltot, soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
oc = o->objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
oc->flags |= OC_F_LRUDONTMOVE;
Lck_Lock(&sc->mtx);
assert(sg->nalloc2 < sg->nalloc1);
sp->obj->smp_index = sg->nalloc2++;
so = &sg->objs[sp->obj->smp_index];
o->smp_index = sg->nalloc2++;
so = &sg->objs[o->smp_index];
sg->nfixed++;
sg->nobj++;
assert(sizeof so->hash == DIGEST_LEN);
memcpy(so->hash, sp->obj->objcore->objhead->digest, DIGEST_LEN);
so->ttl = sp->obj->ttl;
so->ptr = sp->obj;
so->ban = sp->obj->ban_t;
memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
so->ttl = o->ttl;
so->ptr = o;
so->ban = o->ban_t;
Lck_Unlock(&sc->mtx);
return (o);
}
/*--------------------------------------------------------------------
......@@ -1538,7 +1544,6 @@ const struct stevedore smp_stevedore = {
.close = smp_close,
.alloc = smp_alloc,
.allocobj = smp_allocobj,
.object = smp_object,
.free = smp_free,
.trim = smp_trim,
};
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