[master] 47f4078 Add a EXP_NukeLRU() function to nuke an entire LRU structure at a time.

Martin Blix Grydeland martin at varnish-cache.org
Wed Oct 10 09:49:17 CEST 2012


commit 47f4078d0239f8016f2ebaefa26467dfa0f1286f
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Fri May 18 12:30:30 2012 +0200

    Add a EXP_NukeLRU() function to nuke an entire LRU structure at a time.

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..6e27c08 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	/* XXX: Randomly chosen to be bigger than one */
+
+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.
  */
 



More information about the varnish-commit mailing list