Commit 96bdc84c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Lift the object refcount up to the objcore structure.



git-svn-id: http://www.varnish-cache.org/svn/trunk@4513 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent f9ec640f
......@@ -284,6 +284,7 @@ struct storage {
struct objcore {
unsigned magic;
#define OBJCORE_MAGIC 0x4d301302
unsigned refcnt;
struct object *obj;
struct objhead *objhead;
double timer_when;
......@@ -315,7 +316,6 @@ struct lru {
struct object {
unsigned magic;
#define OBJECT_MAGIC 0x32851d42
unsigned refcnt;
unsigned xid;
struct storage *objstore;
struct objcore *objcore;
......
......@@ -345,7 +345,7 @@ EXP_NukeOne(const struct sess *sp, const struct lru *lru)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (oc->timer_idx == BINHEAP_NOIDX) /* exp_timer has it */
continue;
if (oc->obj->refcnt == 1)
if (oc->refcnt == 1)
break;
}
if (oc != NULL) {
......
......@@ -294,6 +294,7 @@ HSH_Insert(const struct sess *sp)
/* Insert (precreated) objcore in objecthead */
oc = w->nobjcore;
w->nobjcore = NULL;
oc->refcnt = 1;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
AZ(oc->flags & OC_F_BUSY);
......@@ -409,7 +410,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
assert(oc->objhead == oh);
/* We found an object we like */
o->refcnt++;
oc->refcnt++;
if (o->hits < INT_MAX)
o->hits++;
assert(oh->refcnt > 1);
......@@ -437,6 +438,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
oc = w->nobjcore;
w->nobjcore = NULL;
AN(oc->flags & OC_F_BUSY);
oc->refcnt = 1;
/* XXX: Should this not be ..._HEAD now ? */
VTAILQ_INSERT_TAIL(&oh->objcs, oc, list);
......@@ -474,6 +476,12 @@ hsh_rush(struct objhead *oh)
}
}
/**********************************************************************
* Kill a busy object we don't need anyway.
* There may be sessions on the waiting list, so we cannot just blow
* it out of the water.
*/
void
HSH_Drop(struct sess *sp)
{
......@@ -482,8 +490,8 @@ HSH_Drop(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
o = sp->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
assert(o->refcnt > 0);
if (o->objcore != NULL) { /* Pass has no objcore */
assert(o->objcore->refcnt > 0);
AN(ObjIsBusy(o));
o->ttl = 0;
}
......@@ -509,7 +517,7 @@ HSH_Unbusy(const struct sess *sp)
AN(ObjIsBusy(o));
AN(o->ban);
assert(o->objcore->obj == o);
assert(o->refcnt > 0);
assert(o->objcore->refcnt > 0);
assert(oh->refcnt > 0);
if (o->ws_o->overflow)
sp->wrk->stats.n_objoverflow++;
......@@ -534,8 +542,8 @@ HSH_Ref(struct object *o)
oh = o->objcore->objhead;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_Lock(&oh->mtx);
assert(o->refcnt > 0);
o->refcnt++;
assert(o->objcore->refcnt > 0);
o->objcore->refcnt++;
Lck_Unlock(&oh->mtx);
}
......@@ -593,7 +601,7 @@ HSH_FindBan(struct sess *sp, struct objcore **oc)
if (oc2 != NULL && oc2->flags & OC_F_PERSISTENT)
SMP_Fixup(sp, oh, oc2);
if (oc2 != NULL)
oc2->obj->refcnt++;
oc2->refcnt++;
Lck_Unlock(&oh->mtx);
*oc = oc2;
}
......@@ -612,8 +620,7 @@ HSH_Deref(struct worker *w, struct object **oo)
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
oc = o->objcore;
if (oc == NULL) {
assert(o->refcnt > 0);
r = --o->refcnt;
r = 0;
oh = NULL;
} else {
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
......@@ -622,8 +629,8 @@ HSH_Deref(struct worker *w, struct object **oo)
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
assert(o->refcnt > 0);
r = --o->refcnt;
assert(oc->refcnt > 0);
r = --oc->refcnt;
if (!r)
VTAILQ_REMOVE(&oh->objcs, oc, list);
hsh_rush(oh);
......
......@@ -163,7 +163,7 @@ pan_object(const struct object *o)
const struct storage *st;
vsb_printf(vsp, " obj = %p {\n", o);
vsb_printf(vsp, " refcnt = %u, xid = %u,\n", o->refcnt, o->xid);
vsb_printf(vsp, " xid = %u,\n", o->xid);
pan_ws(o->ws_o, 4);
pan_http("obj", o->http, 4);
vsb_printf(vsp, " len = %u,\n", o->len);
......
......@@ -101,7 +101,6 @@ STV_InitObj(struct sess *sp, struct object *o, unsigned wsl, unsigned lhttp,
http_Setup(o->http, o->ws_o);
o->http->magic = HTTP_MAGIC;
o->refcnt = 1;
o->grace = NAN;
o->entered = NAN;
VTAILQ_INIT(&o->store);
......
......@@ -672,7 +672,6 @@ SMP_Fixup(struct sess *sp, struct objhead *oh, struct objcore *oc)
oc->flags &= ~OC_F_PERSISTENT;
/* refcnt is one because the object is in the hash */
oc->obj->refcnt = 1;
oc->obj->objcore = oc;
oc->obj->ban = oc->ban;
......
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