[master] 1f172c7 Round to page sizes on signature syncs

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


commit 1f172c75d589197206f92517e9edfccd230e4580
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Sep 26 16:35:03 2012 +0200

    Round to page sizes on signature syncs

diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index c4837b9..aceb996 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -210,6 +210,7 @@ void smp_reset_signspace(struct smp_signspace *spc);
 void smp_copy_signspace(struct smp_signspace *dst,
 			const struct smp_signspace *src);
 void smp_trunc_signspace(struct smp_signspace *spc, uint32_t len);
+void smp_msync(void *addr, size_t length);
 
 void smp_newsilo(struct smp_sc *sc);
 int smp_valid_silo(struct smp_sc *sc);
diff --git a/bin/varnishd/storage/storage_persistent_subr.c b/bin/varnishd/storage/storage_persistent_subr.c
index 9933541..f73ae06 100644
--- a/bin/varnishd/storage/storage_persistent_subr.c
+++ b/bin/varnishd/storage/storage_persistent_subr.c
@@ -156,13 +156,7 @@ smp_reset_sign(struct smp_signctx *ctx)
 void
 smp_sync_sign(const struct smp_signctx *ctx)
 {
-	int i;
-
-	/* XXX: round to pages */
-	i = msync((void*)ctx->ss, ctx->ss->length + SMP_SIGN_SPACE, MS_SYNC);
-	if (i && 0)
-		fprintf(stderr, "SyncSign(%p %s) = %d %s\n",
-		    ctx->ss, ctx->id, i, strerror(errno));
+	smp_msync(ctx->ss, SMP_SIGN_SPACE + ctx->ss->length);
 }
 
 /*--------------------------------------------------------------------
@@ -268,6 +262,25 @@ smp_new_signspace(const struct smp_sc *sc, struct smp_signspace *spc,
 }
 
 /*--------------------------------------------------------------------
+ * Force a write of a memory block (rounded to nearest pages) to
+ * the backing store.
+ */
+
+void
+smp_msync(void *addr, size_t length)
+{
+	uintptr_t start, end;
+	int pagesize;
+
+	pagesize = getpagesize();
+	assert(pagesize > 0 && PWR2(pagesize));
+	start = RDN2((uintptr_t)addr, pagesize);
+	end = RUP2((uintptr_t)addr + length, pagesize);
+	assert(start < end);
+	AZ(msync((void *)start, end - start, MS_SYNC));
+}
+
+/*--------------------------------------------------------------------
  * Initialize a Silo with a valid but empty structure.
  *
  * XXX: more intelligent sizing of things.



More information about the varnish-commit mailing list