From f41e9e3d488a55664ec1800196eff608c441967d Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 12 Feb 2009 22:26:44 +0000 Subject: [PATCH] Move the LRU timestamp from the objcore to the object, we only access it when we have used the object anyway. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3757 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 ++-- varnish-cache/bin/varnishd/cache_center.c | 4 +++- varnish-cache/bin/varnishd/cache_expire.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e8486542..0101ee34 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -267,7 +267,6 @@ struct objcore { VTAILQ_ENTRY(objcore) list; VTAILQ_ENTRY(objcore) lru_list; int on_lru; - double lru_stamp; }; /* Object structure --------------------------------------------------*/ @@ -302,6 +301,7 @@ struct object { double prefetch; double last_modified; + double last_lru; struct http http[1]; @@ -463,7 +463,7 @@ extern pthread_t cli_thread; void EXP_Insert(struct object *o); void EXP_Init(void); void EXP_Rearm(const struct object *o); -void EXP_Touch(const struct object *o, double now); +int EXP_Touch(const struct object *o); int EXP_NukeOne(struct sess *sp); /* cache_fetch.c */ diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index fea97a13..895c2061 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -159,8 +159,10 @@ cnt_deliver(struct sess *sp) sp->t_resp = TIM_real(); if (sp->obj->objhead != NULL) { + if ((sp->t_resp - sp->obj->last_lru) > params->lru_timeout && + EXP_Touch(sp->obj)) + sp->obj->last_lru = sp->t_resp; /* XXX: locking ? */ sp->obj->last_use = sp->t_resp; /* XXX: locking ? */ - EXP_Touch(sp->obj, sp->t_resp); } RES_BuildHttp(sp); VCL_deliver_method(sp); diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index 315b65ea..8d14e89a 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -133,7 +133,7 @@ EXP_Insert(struct object *o) oc = o->objcore; assert(o->entered != 0 && !isnan(o->entered)); - oc->lru_stamp = o->entered; + o->last_lru = o->entered; Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); @@ -153,27 +153,27 @@ EXP_Insert(struct object *o) * that can be worked around by examining obj.last_use in vcl_discard{} */ -void -EXP_Touch(const struct object *o, double now) +int +EXP_Touch(const struct object *o) { struct objcore *oc; + int retval = 0; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oc = o->objcore; if (oc == NULL) - return; + return (retval); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); - if (oc->lru_stamp + params->lru_timeout > now) - return; if (Lck_Trylock(&exp_mtx)) - return; + return (retval); if (oc->on_lru) { VTAILQ_REMOVE(&lru, oc, lru_list); VTAILQ_INSERT_TAIL(&lru, oc, lru_list); - oc->lru_stamp = now; VSL_stats->n_lru_moved++; + retval = 1; } Lck_Unlock(&exp_mtx); + return (retval); } /*-------------------------------------------------------------------- -- 2.39.5