From: phk Date: Sat, 23 Feb 2008 19:54:44 +0000 (+0000) Subject: Only move objects to the tail of the LRU queue if we can get the X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6cc14aea1c437b448c0eec4c955ec633ef284cc;p=varnish Only move objects to the tail of the LRU queue if we can get the expiry mutex without waiting. This is in addition to the already present "only if it have not been moved recently" check. This additional mutex-contestion reduction obviously might leave the LRU list badly out of order, but this can be worked around by examining obj.last_use in vcl_discard() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2534 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index 0406d2ad..a870b0d4 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -98,21 +98,33 @@ EXP_Insert(struct object *o) UNLOCK(&exp_mtx); } +/*-------------------------------------------------------------------- + * Object was used, move to tail of LRU list. + * + * To avoid the exp_mtx becoming a hotspot, we only attempt to move + * objects if they have not been moved recently and if the lock is available. + * This optimization obviously leaves the LRU list imperfectly sorted, but + * that can be worked around by examining obj.last_use in vcl_discard{} + */ + void EXP_Touch(struct object *o, double now) { + int i; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - if (o->lru_stamp + params->lru_timeout < now) { - LOCK(&exp_mtx); /* XXX: should be ..._TRY */ + if (o->lru_stamp + params->lru_timeout > now) + return; + TRYLOCK(&exp_mtx, i); + if (i) + return; + if (o->timer_idx != lru_target && o->timer_idx != 0) { + VTAILQ_REMOVE(&exp_lru, o, deathrow); + VTAILQ_INSERT_TAIL(&exp_lru, o, deathrow); + o->lru_stamp = now; VSL_stats->n_lru_moved++; - if (o->timer_idx != lru_target && o->timer_idx != 0) { - VTAILQ_REMOVE(&exp_lru, o, deathrow); - VTAILQ_INSERT_TAIL(&exp_lru, o, deathrow); - o->lru_stamp = now; - } - UNLOCK(&exp_mtx); } + UNLOCK(&exp_mtx); } /*--------------------------------------------------------------------