r2534 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Feb 23 20:54:44 CET 2008


Author: phk
Date: 2008-02-23 20:54:44 +0100 (Sat, 23 Feb 2008)
New Revision: 2534

Modified:
   trunk/varnish-cache/bin/varnishd/cache_expire.c
Log:
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()



Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2008-02-23 19:48:11 UTC (rev 2533)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2008-02-23 19:54:44 UTC (rev 2534)
@@ -98,21 +98,33 @@
 	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);
 }
 
 /*--------------------------------------------------------------------




More information about the varnish-commit mailing list