r4213 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Thu Aug 27 18:34:23 CEST 2009
Author: phk
Date: 2009-08-27 18:34:23 +0200 (Thu, 27 Aug 2009)
New Revision: 4213
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_expire.c
trunk/varnish-cache/bin/varnishd/common.h
trunk/varnish-cache/bin/varnishd/stevedore.c
trunk/varnish-cache/bin/varnishd/stevedore.h
trunk/varnish-cache/bin/varnishd/storage_persistent.c
Log:
Clean up the LRU stuff a bit, wrap the senteniel with the list head etc.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2009-08-26 23:01:06 UTC (rev 4212)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2009-08-27 16:34:23 UTC (rev 4213)
@@ -296,6 +296,15 @@
struct ban *ban;
};
+/*--------------------------------------------------------------------*/
+
+struct lru {
+ unsigned magic;
+#define LRU_MAGIC 0x3fec7bb0
+ VLIST_HEAD(,objcore) lru_head;
+ struct objcore senteniel;
+};
+
/* Object structure --------------------------------------------------*/
struct object {
@@ -488,11 +497,11 @@
/* cache_expiry.c */
void EXP_Insert(struct object *o);
-void EXP_Inject(struct objcore *oc, struct objcore *lrut, double ttl);
+void EXP_Inject(struct objcore *oc, struct lru *lru, double ttl);
void EXP_Init(void);
void EXP_Rearm(const struct object *o);
int EXP_Touch(const struct object *o);
-int EXP_NukeOne(struct sess *sp, const struct objcore_head *lru);
+int EXP_NukeOne(struct sess *sp, const struct lru *lru);
/* cache_fetch.c */
int FetchHdr(struct sess *sp);
Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-08-26 23:01:06 UTC (rev 4212)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-08-27 16:34:23 UTC (rev 4213)
@@ -97,18 +97,18 @@
*/
void
-EXP_Inject(struct objcore *oc, struct objcore *lrut, double ttl)
+EXP_Inject(struct objcore *oc, struct lru *lru, double ttl)
{
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
- CHECK_OBJ_NOTNULL(lrut, OBJCORE_MAGIC);
+ CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
Lck_Lock(&exp_mtx);
assert(oc->timer_idx == BINHEAP_NOIDX);
oc->timer_when = ttl;
binheap_insert(exp_heap, oc);
assert(oc->timer_idx != BINHEAP_NOIDX);
- VLIST_INSERT_BEFORE(lrut, oc, lru_list);
+ VLIST_INSERT_BEFORE(&lru->senteniel, oc, lru_list);
oc->flags |= OC_F_ONLRU;
Lck_Unlock(&exp_mtx);
}
@@ -123,7 +123,8 @@
void
EXP_Insert(struct object *o)
{
- struct objcore *oc, *lrut;
+ struct objcore *oc;
+ struct lru *lru;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC);
@@ -134,15 +135,15 @@
assert(o->entered != 0 && !isnan(o->entered));
o->last_lru = o->entered;
- lrut = STV_lru(o->objstore);
Lck_Lock(&exp_mtx);
assert(oc->timer_idx == BINHEAP_NOIDX);
(void)update_object_when(o);
binheap_insert(exp_heap, oc);
assert(oc->timer_idx != BINHEAP_NOIDX);
if (o->objstore != NULL) {
- CHECK_OBJ_NOTNULL(lrut, OBJCORE_MAGIC);
- VLIST_INSERT_BEFORE(lrut, oc, lru_list);
+ lru = STV_lru(o->objstore);
+ CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
+ VLIST_INSERT_BEFORE(&lru->senteniel, oc, lru_list);
oc->flags |= OC_F_ONLRU;
}
Lck_Unlock(&exp_mtx);
@@ -163,7 +164,8 @@
EXP_Touch(const struct object *o)
{
int retval = 0;
- struct objcore *oc, *lrut;
+ struct objcore *oc;
+ struct lru *lru;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
oc = o->objcore;
@@ -174,13 +176,13 @@
CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
if (o->objstore == NULL) /* XXX ?? */
return (retval);
- lrut = STV_lru(o->objstore);
- CHECK_OBJ_NOTNULL(lrut, OBJCORE_MAGIC);
+ lru = STV_lru(o->objstore);
+ CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
if (Lck_Trylock(&exp_mtx))
return (retval);
if (oc->flags & OC_F_ONLRU) { /* XXX ?? */
VLIST_REMOVE(oc, lru_list);
- VLIST_INSERT_BEFORE(lrut, oc, lru_list);
+ VLIST_INSERT_BEFORE(&lru->senteniel, oc, lru_list);
VSL_stats->n_lru_moved++;
retval = 1;
}
@@ -303,7 +305,7 @@
*/
int
-EXP_NukeOne(struct sess *sp, const struct objcore_head *lru)
+EXP_NukeOne(struct sess *sp, const struct lru *lru)
{
struct objcore *oc;
@@ -318,7 +320,12 @@
*
*/
Lck_Lock(&exp_mtx);
- VLIST_FOREACH(oc, lru, lru_list) {
+ VLIST_FOREACH(oc, &lru->lru_head, lru_list) {
+ if (oc == &lru->senteniel) {
+ AZ(VLIST_NEXT(oc, lru_list));
+ oc = NULL;
+ break;
+ }
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (oc->timer_idx == BINHEAP_NOIDX) /* exp_timer has it */
continue;
Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h 2009-08-26 23:01:06 UTC (rev 4212)
+++ trunk/varnish-cache/bin/varnishd/common.h 2009-08-27 16:34:23 UTC (rev 4213)
@@ -64,8 +64,3 @@
const char *name;
void *ptr;
};
-
-/* Sort of hack-ish... */
-struct objcore;
-VLIST_HEAD(objcore_head, objcore);
-
Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c 2009-08-26 23:01:06 UTC (rev 4212)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c 2009-08-27 16:34:23 UTC (rev 4213)
@@ -43,6 +43,18 @@
static const struct stevedore * volatile stv_next;
+static struct lru *
+LRU_Alloc(void)
+{
+ struct lru *l;
+
+ ALLOC_OBJ(l, LRU_MAGIC);
+ AN(l);
+ VLIST_INIT(&l->lru_head);
+ VLIST_INSERT_HEAD(&l->lru_head, &l->senteniel, lru_list);
+ return (l);
+}
+
struct storage *
STV_alloc(struct sess *sp, size_t size)
{
@@ -81,7 +93,7 @@
break;
/* no luck; try to free some space and keep trying */
- if (EXP_NukeOne(sp, &stv->lru) == -1)
+ if (EXP_NukeOne(sp, stv->lru) == -1)
break;
/* Enough is enough: try another if we have one */
@@ -124,9 +136,7 @@
*stv = *stv2;
AN(stv->name);
AN(stv->alloc);
- ALLOC_OBJ(stv->lru_tail, OBJCORE_MAGIC);
- VLIST_INIT(&stv->lru);
- VLIST_INSERT_HEAD(&stv->lru, stv->lru_tail, lru_list);
+ stv->lru = LRU_Alloc();
if (stv->init != NULL)
stv->init(stv, ac, av);
@@ -161,12 +171,12 @@
}
}
-struct objcore *
-STV_lru(struct storage *st)
+struct lru *
+STV_lru(const struct storage *st)
{
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
- return (st->stevedore->lru_tail);
+ return (st->stevedore->lru);
}
const struct choice STV_choice[] = {
Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h 2009-08-26 23:01:06 UTC (rev 4212)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h 2009-08-27 16:34:23 UTC (rev 4213)
@@ -42,6 +42,7 @@
typedef void storage_object_f(const struct sess *sp);
typedef void storage_close_f(const struct stevedore *);
+
struct stevedore {
unsigned magic;
#define STEVEDORE_MAGIC 0x4baf43db
@@ -54,8 +55,7 @@
storage_object_f *object;
storage_close_f *close;
- struct objcore_head lru;
- struct objcore *lru_tail;
+ struct lru *lru;
/* private fields */
void *priv;
@@ -69,7 +69,7 @@
void STV_add(const struct stevedore *stv, int ac, char * const *av);
void STV_open(void);
void STV_close(void);
-struct objcore *STV_lru(struct storage *st);
+struct lru *STV_lru(const struct storage *st);
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-08-26 23:01:06 UTC (rev 4212)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-08-27 16:34:23 UTC (rev 4213)
@@ -837,7 +837,7 @@
memcpy(sp->wrk->nobjhead->digest, so->hash, SHA256_LEN);
(void)HSH_Insert(sp);
AZ(sp->wrk->nobjcore);
- EXP_Inject(oc, sc->parent->lru_tail, so->ttl);
+ EXP_Inject(oc, sc->parent->lru, so->ttl);
sg->nalloc++;
}
WRK_SumStat(sp->wrk);
More information about the varnish-commit
mailing list