r235 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jun 26 16:33:50 CEST 2006
Author: phk
Date: 2006-06-26 16:33:49 +0200 (Mon, 26 Jun 2006)
New Revision: 235
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_expire.c
trunk/varnish-cache/bin/varnishd/cache_fetch.c
trunk/varnish-cache/bin/varnishd/cache_hash.c
trunk/varnish-cache/bin/varnishd/cache_pool.c
trunk/varnish-cache/bin/varnishd/hash_simple_list.c
Log:
Start releasing objects when they expire
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-06-26 14:00:40 UTC (rev 234)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-06-26 14:33:49 UTC (rev 235)
@@ -30,7 +30,7 @@
typedef void hash_init_f(void);
typedef struct objhead *hash_lookup_f(const char *key, struct objhead *nobj);
-typedef void hash_deref_f(struct objhead *obj);
+typedef int hash_deref_f(struct objhead *obj);
struct hash_slinger {
const char *name;
@@ -155,7 +155,7 @@
/* cache_hash.c */
struct object *HSH_Lookup(struct worker *w, struct http *h);
void HSH_Unbusy(struct object *o);
-void HSH_Unref(struct object *o);
+void HSH_Deref(struct object *o);
void HSH_Init(void);
/* cache_http.c */
Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c 2006-06-26 14:00:40 UTC (rev 234)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2006-06-26 14:33:49 UTC (rev 235)
@@ -52,6 +52,7 @@
printf("Root: %p %d (%d)\n", (void*)o, o->ttl, o->ttl - t);
binheap_delete(exp_heap, 0);
AZ(pthread_mutex_unlock(&expmtx));
+ HSH_Deref(o);
}
return ("FOOBAR");
Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-06-26 14:00:40 UTC (rev 234)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-06-26 14:33:49 UTC (rev 235)
@@ -271,10 +271,9 @@
else
VBE_RecycleFd(fd_token);
- /* XXX: unbusy, and kick other sessions into action */
- sp->obj->busy = 0;
+ HSH_Unbusy(sp->obj);
+ if (!sp->obj->cacheable)
+ HSH_Deref(sp->obj);
- /* XXX: if not cachable, destroy */
-
return (1);
}
Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c 2006-06-26 14:00:40 UTC (rev 234)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2006-06-26 14:33:49 UTC (rev 235)
@@ -16,7 +16,6 @@
static struct hash_slinger *hash;
-
struct object *
HSH_Lookup(struct worker *w, struct http *h)
{
@@ -25,18 +24,19 @@
char *b;
assert(hash != NULL);
- /* Make sure we have both a new objhead and object if we need them */
+ /* Precreate an objhead and object in case we need them */
if (w->nobjhead == NULL) {
w->nobjhead = calloc(sizeof *w->nobjhead, 1);
assert(w->nobjhead != NULL);
TAILQ_INIT(&w->nobjhead->objects);
+ AZ(pthread_mutex_init(&oh->mtx, NULL));
}
if (w->nobj == NULL) {
w->nobj = calloc(sizeof *w->nobj, 1);
assert(w->nobj != NULL);
w->nobj->busy = 1;
TAILQ_INIT(&w->nobj->store);
- pthread_cond_init(&w->nobj->cv, NULL);
+ AZ(pthread_cond_init(&w->nobj->cv, NULL));
}
assert(http_GetURL(h, &b));
@@ -53,11 +53,19 @@
break;
o->refcnt--;
}
- if (o == NULL) {
- o = w->nobj;
- w->nobj = NULL;
- TAILQ_INSERT_TAIL(&oh->objects, o, list);
+ if (o != NULL) {
+ AZ(pthread_mutex_unlock(&oh->mtx));
+ hash->deref(oh);
+ return (o);
}
+
+ /* Insert (precreated) object in objecthead */
+ o = w->nobj;
+ w->nobj = NULL;
+ o->refcnt = 1;
+ o->objhead = oh;
+ TAILQ_INSERT_TAIL(&oh->objects, o, list);
+ /* NB: do not deref objhead the new object inherits our reference */
AZ(pthread_mutex_unlock(&oh->mtx));
return (o);
}
@@ -73,12 +81,39 @@
}
void
-HSH_Unref(struct object *o)
+HSH_Deref(struct object *o)
{
+ struct objhead *oh;
+ struct storage *st, *stn;
- AZ(pthread_mutex_lock(&o->objhead->mtx));
- o->refcnt--;
- AZ(pthread_mutex_unlock(&o->objhead->mtx));
+ oh = o->objhead;
+
+ /* drop ref on object */
+ AZ(pthread_mutex_lock(&oh->mtx));
+ if (--o->refcnt == 0)
+ TAILQ_REMOVE(&oh->objects, o, list);
+ else
+ o = NULL;
+ AZ(pthread_mutex_unlock(&oh->mtx));
+
+ /* If still referenced, done */
+ if (o == NULL)
+ return;
+
+ AZ(pthread_cond_destroy(&o->cv));
+
+ TAILQ_FOREACH_SAFE(st, &o->store, list, stn) {
+ TAILQ_REMOVE(&o->store, st, list);
+ st->stevedore->free(st);
+ }
+ free(o);
+
+ /* Drop our ref on the objhead */
+ if (hash->deref(oh))
+ return;
+ assert(TAILQ_EMPTY(&oh->objects));
+ AZ(pthread_mutex_destroy(&oh->mtx));
+ free(oh);
}
void
Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-06-26 14:00:40 UTC (rev 234)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-06-26 14:33:49 UTC (rev 235)
@@ -49,6 +49,8 @@
"\r\n", sp->obj->header, sp->obj->len);
vca_write_obj(sp, w->sb);
+ HSH_Deref(sp->obj);
+ sp->obj = NULL;
return (1);
}
Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2006-06-26 14:00:40 UTC (rev 234)
+++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2006-06-26 14:33:49 UTC (rev 235)
@@ -88,10 +88,11 @@
* Dereference and if no references are left, free.
*/
-static void
+static int
hsl_deref(struct objhead *obj)
{
struct hsl_entry *he;
+ int ret;
assert(obj->hashpriv != NULL);
he = obj->hashpriv;
@@ -100,8 +101,11 @@
free(he->key);
TAILQ_REMOVE(&hsl_head, he, list);
free(he);
- }
+ ret = 0;
+ } else
+ ret = 1;
AZ(pthread_mutex_unlock(&hsl_mutex));
+ return (ret);
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list