Commit 22f0b084 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Be more defensive around objhead retirement.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3791 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 600a82b4
...@@ -469,6 +469,7 @@ BAN_DestroyObj(struct object *o) ...@@ -469,6 +469,7 @@ BAN_DestroyObj(struct object *o)
return; return;
CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC);
Lck_Lock(&ban_mtx); Lck_Lock(&ban_mtx);
assert(o->ban->refcount > 0);
o->ban->refcount--; o->ban->refcount--;
o->ban = NULL; o->ban = NULL;
...@@ -477,7 +478,6 @@ BAN_DestroyObj(struct object *o) ...@@ -477,7 +478,6 @@ BAN_DestroyObj(struct object *o)
Lck_Unlock(&ban_mtx); Lck_Unlock(&ban_mtx);
if (b != NULL) if (b != NULL)
BAN_Free(b); BAN_Free(b);
} }
......
...@@ -272,6 +272,7 @@ exp_timer(void *arg) ...@@ -272,6 +272,7 @@ exp_timer(void *arg)
"%u %d", o->xid, (int)(o->ttl - t)); "%u %d", o->xid, (int)(o->ttl - t));
Lck_Lock(&exp_mtx); Lck_Lock(&exp_mtx);
assert(oc->timer_idx == BINHEAP_NOIDX); assert(oc->timer_idx == BINHEAP_NOIDX);
assert(oc->flags & OC_F_ONLRU);
VTAILQ_REMOVE(&lru, o->objcore, lru_list); VTAILQ_REMOVE(&lru, o->objcore, lru_list);
oc->flags &= ~OC_F_ONLRU; oc->flags &= ~OC_F_ONLRU;
VSL_stats->n_expired++; VSL_stats->n_expired++;
......
...@@ -140,6 +140,18 @@ HSH_Prealloc(struct sess *sp) ...@@ -140,6 +140,18 @@ HSH_Prealloc(struct sess *sp)
CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC);
} }
void
HSH_DeleteObjHead(struct objhead *oh)
{
AZ(oh->refcnt);
assert(VTAILQ_EMPTY(&oh->objcs));
Lck_Delete(&oh->mtx);
VSL_stats->n_objecthead--;
free(oh->hash);
FREE_OBJ(oh);
}
void void
HSH_Freestore(struct object *o) HSH_Freestore(struct object *o)
{ {
...@@ -311,7 +323,7 @@ HSH_Lookup(struct sess *sp) ...@@ -311,7 +323,7 @@ HSH_Lookup(struct sess *sp)
if (o->hits < INT_MAX) if (o->hits < INT_MAX)
o->hits++; o->hits++;
Lck_Unlock(&oh->mtx); Lck_Unlock(&oh->mtx);
(void)hash->deref(oh); assert(hash->deref(oh));
return (o); return (o);
} }
...@@ -476,6 +488,7 @@ HSH_Deref(struct object **oo) ...@@ -476,6 +488,7 @@ HSH_Deref(struct object **oo)
return; return;
BAN_DestroyObj(o); BAN_DestroyObj(o);
AZ(o->ban);
DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u", DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u",
o->xid, WS_Free(o->ws_o)); o->xid, WS_Free(o->ws_o));
...@@ -494,13 +507,10 @@ HSH_Deref(struct object **oo) ...@@ -494,13 +507,10 @@ HSH_Deref(struct object **oo)
AN(oc); AN(oc);
FREE_OBJ(oc); FREE_OBJ(oc);
/* Drop our ref on the objhead */ /* Drop our ref on the objhead */
assert(oh->refcnt > 0);
if (hash->deref(oh)) if (hash->deref(oh))
return; return;
assert(VTAILQ_EMPTY(&oh->objcs)); HSH_DeleteObjHead(oh);
Lck_Delete(&oh->mtx);
VSL_stats->n_objecthead--;
free(oh->hash);
FREE_OBJ(oh);
} }
void void
......
...@@ -323,7 +323,7 @@ dump(const struct hcb_root *root, FILE *fd) ...@@ -323,7 +323,7 @@ dump(const struct hcb_root *root, FILE *fd)
/**********************************************************************/ /**********************************************************************/
#define COOL_DURATION 15 /* seconds */ #define COOL_DURATION 60 /* seconds */
static void * static void *
hcb_cleaner(void *priv) hcb_cleaner(void *priv)
...@@ -337,10 +337,6 @@ hcb_cleaner(void *priv) ...@@ -337,10 +337,6 @@ hcb_cleaner(void *priv)
(void)sleep(1); (void)sleep(1);
Lck_Lock(&hcb_mtx); Lck_Lock(&hcb_mtx);
VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) { VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) {
if (oh->hash != NULL) {
free(oh->hash);
oh->hash = NULL;
}
y = (void *)&oh->u; y = (void *)&oh->u;
if (y->leaf[0] || y->leaf[1]) if (y->leaf[0] || y->leaf[1])
continue; continue;
...@@ -349,8 +345,8 @@ hcb_cleaner(void *priv) ...@@ -349,8 +345,8 @@ hcb_cleaner(void *priv)
#ifdef PHK #ifdef PHK
fprintf(stderr, "OH %p is cold enough\n", oh); fprintf(stderr, "OH %p is cold enough\n", oh);
#endif #endif
free(oh); oh->refcnt = 0;
VSL_stats->n_objecthead--; HSH_DeleteObjHead(oh);
} }
} }
Lck_Unlock(&hcb_mtx); Lck_Unlock(&hcb_mtx);
...@@ -381,6 +377,7 @@ hcb_deref(struct objhead *oh) ...@@ -381,6 +377,7 @@ hcb_deref(struct objhead *oh)
r = 1; r = 1;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_Lock(&oh->mtx); Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
if (--oh->refcnt == 0) { if (--oh->refcnt == 0) {
Lck_Lock(&hcb_mtx); Lck_Lock(&hcb_mtx);
hcb_delete(&hcb_root, oh); hcb_delete(&hcb_root, oh);
......
...@@ -50,6 +50,7 @@ struct hash_slinger { ...@@ -50,6 +50,7 @@ struct hash_slinger {
/* cache_hash.c */ /* cache_hash.c */
void HSH_Prealloc(struct sess *sp); void HSH_Prealloc(struct sess *sp);
void HSH_DeleteObjHead(struct objhead *oh);
void HSH_Freestore(struct object *o); void HSH_Freestore(struct object *o);
void HSH_Copy(const struct sess *sp, struct objhead *o); void HSH_Copy(const struct sess *sp, struct objhead *o);
struct object *HSH_Lookup(struct sess *sp); struct object *HSH_Lookup(struct sess *sp);
......
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