[PATCH 01/13] Add a EXP_NukeLRU() function to nuke an entire LRU structure at a time.

Martin Blix Grydeland martin at varnish-software.com
Mon Oct 1 12:26:08 CEST 2012


---
 bin/varnishd/cache/cache.h        |    1 +
 bin/varnishd/cache/cache_expire.c |   59 +++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 15db84c..7533782 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -790,6 +790,7 @@ void EXP_Init(void);
 void EXP_Rearm(const struct object *o);
 int EXP_Touch(struct objcore *oc);
 int EXP_NukeOne(struct busyobj *, struct lru *lru);
+void EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru);
 
 /* cache_fetch.c */
 struct storage *FetchStorage(struct busyobj *, ssize_t sz);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 3d18d78..524d565 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -460,6 +460,65 @@ EXP_NukeOne(struct busyobj *bo, struct lru *lru)
 }
 
 /*--------------------------------------------------------------------
+ * Nukes an entire LRU
+ */
+
+#define NUKEBUF 10
+
+void
+EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru)
+{
+	struct objcore *oc;
+	struct objcore *oc_array[NUKEBUF];
+	struct object *o;
+	int i, n;
+	double t;
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
+
+	t = VTIM_real();
+	Lck_Lock(&lru->mtx);
+	while (!VTAILQ_EMPTY(&lru->lru_head)) {
+		Lck_Lock(&exp_mtx);
+		n = 0;
+		while (n < NUKEBUF) {
+			oc = VTAILQ_FIRST(&lru->lru_head);
+			if (oc == NULL)
+				break;
+			CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+			assert(oc_getlru(oc) == lru);
+
+			/* Remove from the LRU and binheap */
+			VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
+			assert(oc->timer_idx != BINHEAP_NOIDX);
+			binheap_delete(exp_heap, oc->timer_idx);
+			assert(oc->timer_idx == BINHEAP_NOIDX);
+
+			oc_array[n++] = oc;
+			VSC_C_main->n_lru_nuked++;
+		}
+		assert(n > 0);
+		Lck_Unlock(&exp_mtx);
+		Lck_Unlock(&lru->mtx);
+
+		for (i = 0; i < n; i++) {
+			oc = oc_array[i];
+			o = oc_getobj(&wrk->stats, oc);
+			VSLb(vsl, SLT_ExpKill, "%u %.0f LRU",
+			     oc_getxid(&wrk->stats, oc), EXP_Ttl(NULL, o) - t);
+			EXP_Set_ttl(&o->exp, 0.);
+			(void)HSH_Deref(&wrk->stats, oc, NULL);
+		}
+
+		Lck_Lock(&lru->mtx);
+	}
+	Lck_Unlock(&lru->mtx);
+
+	WRK_SumStat(wrk);
+}
+
+/*--------------------------------------------------------------------
  * BinHeap helper functions for objcore.
  */
 
-- 
1.7.9.5




More information about the varnish-dev mailing list