[master] 8763a45 Never trust the values of VSC-counters: They are mmap'ed in other processes and therefore they are not trustworthy.

Poul-Henning Kamp phk at FreeBSD.org
Sat May 27 22:00:06 CEST 2017


commit 8763a45177b8c3b2f61a2416ea4b53466e0eb1e2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat May 27 19:57:45 2017 +0000

    Never trust the values of VSC-counters:  They are mmap'ed in other
    processes and therefore they are not trustworthy.

diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 2de444b..55932e8 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -47,6 +47,8 @@ struct ban * volatile ban_start;
 
 static pthread_t ban_thread;
 static int ban_holds;
+uint64_t bans_persisted_bytes;
+uint64_t bans_persisted_fragmentation;
 
 struct ban_test {
 	uint8_t			oper;
@@ -165,8 +167,9 @@ ban_mark_completed(struct ban *b)
 		VWMB();
 		vbe32enc(b->spec + BANS_LENGTH, BANS_HEAD_LEN);
 		VSC_C_main->bans_completed++;
-		VSC_C_main->bans_persisted_fragmentation +=
-		    ln - ban_len(b->spec);
+		bans_persisted_fragmentation += ln - ban_len(b->spec);
+		VSC_C_main->bans_persisted_fragmentation =
+		    bans_persisted_fragmentation;
 	}
 }
 
@@ -303,19 +306,19 @@ ban_export(void)
 	unsigned ln;
 
 	Lck_AssertHeld(&ban_mtx);
-	ln = VSC_C_main->bans_persisted_bytes -
-	    VSC_C_main->bans_persisted_fragmentation;
+	ln = bans_persisted_bytes - bans_persisted_fragmentation;
 	vsb = VSB_new_auto();
 	AN(vsb);
-	VTAILQ_FOREACH_REVERSE(b, &ban_head, banhead_s, list) {
+	VTAILQ_FOREACH_REVERSE(b, &ban_head, banhead_s, list)
 		AZ(VSB_bcat(vsb, b->spec, ban_len(b->spec)));
-	}
 	AZ(VSB_finish(vsb));
 	assert(VSB_len(vsb) == ln);
 	STV_BanExport((const uint8_t *)VSB_data(vsb), VSB_len(vsb));
 	VSB_destroy(&vsb);
-	VSC_C_main->bans_persisted_bytes = ln;
-	VSC_C_main->bans_persisted_fragmentation = 0;
+	VSC_C_main->bans_persisted_bytes =
+	    bans_persisted_bytes = ln;
+	VSC_C_main->bans_persisted_fragmentation =
+	    bans_persisted_fragmentation = 0;
 }
 
 /*
@@ -395,7 +398,8 @@ ban_reload(const uint8_t *ban, unsigned len)
 		VTAILQ_INSERT_TAIL(&ban_head, b2, list);
 	else
 		VTAILQ_INSERT_BEFORE(b, b2, list);
-	VSC_C_main->bans_persisted_bytes += len;
+	bans_persisted_bytes += len;
+	VSC_C_main->bans_persisted_bytes = bans_persisted_bytes;
 
 	/* Hunt down older duplicates */
 	for (b = VTAILQ_NEXT(b2, list); b != NULL; b = VTAILQ_NEXT(b, list)) {
diff --git a/bin/varnishd/cache/cache_ban.h b/bin/varnishd/cache/cache_ban.h
index f3992bb..6267c4e 100644
--- a/bin/varnishd/cache/cache_ban.h
+++ b/bin/varnishd/cache/cache_ban.h
@@ -106,6 +106,8 @@ extern int ban_shutdown;
 extern struct banhead_s ban_head;
 extern struct ban * volatile ban_start;
 extern pthread_cond_t	ban_lurker_cond;
+extern uint64_t bans_persisted_bytes;
+extern uint64_t bans_persisted_fragmentation;
 
 void ban_mark_completed(struct ban *b);
 unsigned ban_len(const uint8_t *banspec);
diff --git a/bin/varnishd/cache/cache_ban_build.c b/bin/varnishd/cache/cache_ban_build.c
index 0a3378a..c98baa6 100644
--- a/bin/varnishd/cache/cache_ban_build.c
+++ b/bin/varnishd/cache/cache_ban_build.c
@@ -296,7 +296,8 @@ BAN_Commit(struct ban_proto *bp)
 
 	VSC_C_main->bans++;
 	VSC_C_main->bans_added++;
-	VSC_C_main->bans_persisted_bytes += ln;
+	bans_persisted_bytes += ln;
+	VSC_C_main->bans_persisted_bytes = bans_persisted_bytes;
 
 	if (b->flags & BANS_FLAG_OBJ)
 		VSC_C_main->bans_obj++;
diff --git a/bin/varnishd/cache/cache_ban_lurker.c b/bin/varnishd/cache/cache_ban_lurker.c
index 9a5b43b..ad1bd12 100644
--- a/bin/varnishd/cache/cache_ban_lurker.c
+++ b/bin/varnishd/cache/cache_ban_lurker.c
@@ -86,8 +86,10 @@ ban_cleantail(const struct ban *victim)
 			VSC_C_main->bans_deleted++;
 			VTAILQ_REMOVE(&ban_head, b, list);
 			VTAILQ_INSERT_TAIL(&freelist, b, list);
-			VSC_C_main->bans_persisted_fragmentation +=
+			bans_persisted_fragmentation +=
 			    ban_len(b->spec);
+			VSC_C_main->bans_persisted_fragmentation =
+			    bans_persisted_fragmentation;
 			ban_info_drop(b->spec, ban_len(b->spec));
 		} else {
 			b = NULL;



More information about the varnish-commit mailing list