[master] 9c9ce2a Make the power-of-two rounding functions generally available and use them for VSM allocation
Poul-Henning Kamp
phk at varnish-cache.org
Fri Mar 11 21:06:25 CET 2011
commit 9c9ce2a61d3efc9084663b8b801988bf6398c393
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Mar 11 19:55:05 2011 +0000
Make the power-of-two rounding functions generally available and
use them for VSM allocation
diff --git a/bin/varnishd/common.h b/bin/varnishd/common.h
index 6cbbfd7..bccac52 100644
--- a/bin/varnishd/common.h
+++ b/bin/varnishd/common.h
@@ -93,3 +93,11 @@ void vsm_iter_n(struct vsm_chunk **pp);
/* cache_lck.c */
struct lock { void *priv; }; // Opaque
+
+/*---------------------------------------------------------------------
+ * Generic power-2 rounding macros
+ */
+
+#define PWR2(x) ((((x)-1)&(x))==0) /* Is a power of two */
+#define RDN2(x, y) ((x)&(~((y)-1))) /* if y is powers of two */
+#define RUP2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
diff --git a/bin/varnishd/storage_persistent.h b/bin/varnishd/storage_persistent.h
index 4841a2d..e7c7344 100644
--- a/bin/varnishd/storage_persistent.h
+++ b/bin/varnishd/storage_persistent.h
@@ -148,11 +148,6 @@ struct smp_sc {
/*--------------------------------------------------------------------*/
-/* Generic power-2 rounding */
-#define PWR2(x) ((((x)-1)&(x))==0) /* Is a power of two */
-#define RDN2(x, y) ((x)&(~((y)-1))) /* if y is powers of two */
-#define RUP2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
-
/* Pointer round up/down & assert */
#define PRNDN(sc, x) ((void*)RDN2((uintptr_t)(x), sc->align))
#define PRNUP(sc, x) ((void*)RUP2((uintptr_t)(x), sc->align))
diff --git a/bin/varnishd/vsm.c b/bin/varnishd/vsm.c
index 7585bee..ccdfa38 100644
--- a/bin/varnishd/vsm.c
+++ b/bin/varnishd/vsm.c
@@ -165,8 +165,7 @@ VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
vsm_cleanup();
/* Round up to pointersize */
- size += sizeof(void *) - 1;
- size &= ~(sizeof(void *) - 1);
+ size = RUP2(size, sizeof(void*));
size += sizeof *sha; /* Make space for the header */
More information about the varnish-commit
mailing list