[PATCH 2/2] Start forcing out bans when less than 10% of the maximum available ban space is left.

Martin Blix Grydeland martin at varnish-software.com
Fri Feb 15 15:37:26 CET 2013


---
 bin/varnishd/cache/cache.h                |    1 +
 bin/varnishd/cache/cache_ban.c            |   25 +++++++++++++++++++++++++
 bin/varnishd/storage/storage_persistent.c |    1 +
 3 files changed, 27 insertions(+)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 6be2c73..7632bd9 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -763,6 +763,7 @@ void BAN_Compile(void);
 struct ban *BAN_RefBan(struct objcore *oc, double t0, const struct ban *tail);
 void BAN_TailDeref(struct ban **ban);
 double BAN_Time(const struct ban *ban);
+void BAN_SetMaxBytes(unsigned bytes);
 
 /* cache_busyobj.c */
 void VBO_Init(void);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 79eb9cf..9f918c2 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -108,6 +108,8 @@ static struct ban * volatile ban_start;
 static bgthread_t ban_lurker;
 static int ban_shutdown = 0;
 
+static unsigned ban_maxbytes = UINT_MAX;
+
 /*--------------------------------------------------------------------
  * BAN string defines & magic markers
  */
@@ -145,6 +147,18 @@ static const struct pvar {
 };
 
 /*--------------------------------------------------------------------
+ * Allow persisted stevedores to report the maximum size of bans they
+ * support
+ */
+
+void
+BAN_SetMaxBytes(unsigned bytes)
+{
+	if (bytes < ban_maxbytes)
+		ban_maxbytes = bytes;
+}
+
+/*--------------------------------------------------------------------
  * Storage handling of bans
  */
 
@@ -1121,6 +1135,17 @@ ban_lurker(struct worker *wrk, void *priv)
 		force = VSC_C_main->bans - cache_param->ban_max;
 		if (force < 0)
 			force = 0;
+		if (!force &&
+		    (VSC_C_main->bans_persisted_bytes -
+			VSC_C_main->bans_persisted_fragmentation) >
+		    ban_maxbytes * 0.9) {
+			/*
+			 * We are getting close to (less than 10% left)
+			 * the maximum persisted ban space. Start forcing
+			 * out bans.
+			 */
+			force = 10;
+		}
 		if (d > 0.0 || force) {
 			i = ban_lurker_work(wrk, &vsl, force);
 			VSL_Flush(&vsl, 0);
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 55279c8..46ab683 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -144,6 +144,7 @@ smp_open_bans(struct smp_sc *sc, struct smp_signspace *spc)
 
 	ptr = SIGNSPACE_DATA(spc);
 	pe = SIGNSPACE_FRONT(spc);
+	BAN_SetMaxBytes(spc->size);
 	BAN_Reload(ptr, pe - ptr);
 
 	return (0);
-- 
1.7.10.4




More information about the varnish-dev mailing list