]> err.no Git - varnish/commitdiff
Only move objects to the tail of the LRU queue if we can get the
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 23 Feb 2008 19:54:44 +0000 (19:54 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 23 Feb 2008 19:54:44 +0000 (19:54 +0000)
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

varnish-cache/bin/varnishd/cache_expire.c

index 0406d2ad21731dcbf698e99927b0b60b2209b09e..a870b0d40e6318e41dc984d991b485320f7b06d7 100644 (file)
@@ -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);
 }
 
 /*--------------------------------------------------------------------