[3.0] 6a0e8fd A minor preemptive cleanup before the ban-lurker gets remodelled.

Tollef Fog Heen tfheen at varnish-cache.org
Mon Apr 16 10:20:35 CEST 2012


commit 6a0e8fd44b6cdb89381daeb5c231148726aac0c6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Nov 8 10:03:43 2011 +0000

    A minor preemptive cleanup before the ban-lurker gets remodelled.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 7177f9f..04ff2d0 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -437,6 +437,7 @@ struct objcore {
 #define OC_F_PASS		(1<<2)
 #define OC_F_LRUDONTMOVE	(1<<4)
 #define OC_F_PRIV		(1<<5)		/* Stevedore private flag */
+#define OC_F_LURK		(3<<6)		/* Ban-lurker-color */
 	unsigned		timer_idx;
 	VTAILQ_ENTRY(objcore)	list;
 	VTAILQ_ENTRY(objcore)	lru_list;
diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c
index 7fbeffd..3a6ac36 100644
--- a/bin/varnishd/cache_ban.c
+++ b/bin/varnishd/cache_ban.c
@@ -65,6 +65,7 @@ struct ban {
 	unsigned		flags;
 #define BAN_F_GONE		(1 << 0)
 #define BAN_F_REQ		(1 << 2)
+#define BAN_F_LURK		(3 << 3)	/* ban-lurker-color */
 	VTAILQ_HEAD(,objcore)	objcore;
 	struct vsb		*vsb;
 	uint8_t			*spec;
@@ -148,23 +149,6 @@ BAN_Free(struct ban *b)
 	FREE_OBJ(b);
 }
 
-static struct ban *
-ban_CheckLast(void)
-{
-	struct ban *b;
-
-	Lck_AssertHeld(&ban_mtx);
-	b = VTAILQ_LAST(&ban_head, banhead_s);
-	if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
-		VSC_C_main->n_ban--;
-		VSC_C_main->n_ban_retire++;
-		VTAILQ_REMOVE(&ban_head, b, list);
-	} else {
-		b = NULL;
-	}
-	return (b);
-}
-
 /*--------------------------------------------------------------------
  * Get & Release a tail reference, used to hold the list stable for
  * traversals etc.
@@ -457,7 +441,6 @@ BAN_NewObjCore(struct objcore *oc)
 void
 BAN_DestroyObj(struct objcore *oc)
 {
-	struct ban *b;
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	if (oc->ban == NULL)
@@ -468,12 +451,7 @@ BAN_DestroyObj(struct objcore *oc)
 	oc->ban->refcount--;
 	VTAILQ_REMOVE(&oc->ban->objcore, oc, ban_list);
 	oc->ban = NULL;
-
-	/* Attempt to purge last ban entry */
-	b = ban_CheckLast();
 	Lck_Unlock(&ban_mtx);
-	if (b != NULL)
-		BAN_Free(b);
 }
 
 /*--------------------------------------------------------------------
@@ -734,6 +712,23 @@ BAN_CheckObject(struct object *o, const struct sess *sp)
 	return (ban_check_object(o, sp, 1));
 }
 
+static struct ban *
+ban_CheckLast(void)
+{
+	struct ban *b;
+
+	Lck_AssertHeld(&ban_mtx);
+	b = VTAILQ_LAST(&ban_head, banhead_s);
+	if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
+		VSC_C_main->n_ban--;
+		VSC_C_main->n_ban_retire++;
+		VTAILQ_REMOVE(&ban_head, b, list);
+	} else {
+		b = NULL;
+	}
+	return (b);
+}
+
 /*--------------------------------------------------------------------
  * Ban tail lurker thread
  */
@@ -747,9 +742,6 @@ ban_lurker_work(const struct sess *sp)
 	struct object *o;
 	int i;
 
-	WSL_Flush(sp->wrk, 0);
-	WRK_SumStat(sp->wrk);
-
 	Lck_Lock(&ban_mtx);
 
 	/* First try to route the last ban */
@@ -815,21 +807,34 @@ ban_lurker_work(const struct sess *sp)
 static void * __match_proto__(bgthread_t)
 ban_lurker(struct sess *sp, void *priv)
 {
+	struct ban *bf;
+
 	int i = 0;
 	(void)priv;
 	while (1) {
-		if (params->ban_lurker_sleep == 0.0) {
-			/* Lurker is disabled.  */
-			TIM_sleep(1.0);
-			continue;
+
+		while (params->ban_lurker_sleep == 0.0) {
+			/*
+			 * Ban-lurker is disabled:
+			 * Clean the last ban, if possible, and sleep
+			 */
+			Lck_Lock(&ban_mtx);
+			bf = ban_CheckLast();
+			Lck_Unlock(&ban_mtx);
+			if (bf != NULL)
+				BAN_Free(bf);
+			else
+				TIM_sleep(1.0);
 		}
+
+		i = ban_lurker_work(sp);
+		WSL_Flush(sp->wrk, 0);
+		WRK_SumStat(sp->wrk);
+
 		if (i != 0)
 			TIM_sleep(params->ban_lurker_sleep);
 		else
 			TIM_sleep(1.0);
-		i = ban_lurker_work(sp);
-		WSL_Flush(sp->wrk, 0);
-		WRK_SumStat(sp->wrk);
 	}
 	NEEDLESS_RETURN(NULL);
 }
@@ -941,10 +946,11 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
 	/* Get a reference so we are safe to traverse the list */
 	bl = BAN_TailRef();
 
+	VCLI_Out(cli, "Present bans:\n");
 	VTAILQ_FOREACH(b, &ban_head, list) {
 		if (b == bl)
 			break;
-		VCLI_Out(cli, "%p %10.6f %5u%s\t", b, ban_time(b->spec),
+		VCLI_Out(cli, "%10.6f %5u%s\t", ban_time(b->spec),
 		    bl == b ? b->refcount - 1 : b->refcount,
 		    b->flags & BAN_F_GONE ? "G" : " ");
 		ban_render(cli, b->spec);



More information about the varnish-commit mailing list