r4927 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Tue Jun 8 11:09:50 CEST 2010


Author: phk
Date: 2010-06-08 11:09:49 +0200 (Tue, 08 Jun 2010)
New Revision: 4927

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/common.h
   trunk/varnish-cache/bin/varnishd/mgt_shmem.c
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/include/shmlog.h
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnish/vin.c
   trunk/varnish-cache/lib/libvarnishapi/vsl.c
   trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
   trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
   trunk/varnish-cache/lib/libvarnishapi/vslapi.h
Log:
Begin splitting shared memory log stuff into its three distinct parts:

VSM handling of the shared memory, allocations etc.
VSL Shared memory Log
VSC Shared memory Counters



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-06-08 09:09:49 UTC (rev 4927)
@@ -634,7 +634,7 @@
 
 /* cache_shmlog.c */
 void VSL_Init(void);
-#ifdef SHMLOGHEAD_MAGIC
+#ifdef VSM_HEAD_MAGIC
 void VSL(enum shmlogtag tag, int id, const char *fmt, ...);
 void WSLR(struct worker *w, enum shmlogtag tag, int id, txt t);
 void WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...);

Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/bin/varnishd/common.h	2010-06-08 09:09:49 UTC (rev 4927)
@@ -41,7 +41,7 @@
 /* mgt_shmem.c */
 void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident);
 extern struct varnish_stats *VSL_stats;
-extern struct shmloghead *loghead;
+extern struct vsm_head *loghead;
 extern uint32_t			*vsl_log_start;
 extern uint32_t			*vsl_log_end;
 extern uint32_t			*vsl_log_nxt;

Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -55,7 +55,7 @@
 #endif
 
 struct varnish_stats	*VSL_stats;
-struct shmloghead	*loghead;
+struct vsm_head	*loghead;
 uint32_t		*vsl_log_start;
 uint32_t		*vsl_log_end;
 uint32_t		*vsl_log_nxt;
@@ -67,7 +67,7 @@
 void *
 mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
 {
-	struct shmalloc *sha, *sha2;
+	struct vsm_chunk *sha, *sha2;
 	unsigned seq;
 
 	ASSERT_MGT();
@@ -79,10 +79,10 @@
 	size += sizeof *sha;
 	sha = &loghead->head;
 	while (1) {
-		CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
+		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
 
 		if (strcmp(sha->class, "Free")) {
-			sha = SHA_NEXT(sha);
+			sha = VSM_NEXT(sha);
 			continue;
 		}
 		assert(size <= sha->len);
@@ -94,7 +94,7 @@
 		VWMB();
 
 		memset(sha2, 0, sizeof *sha2);
-		sha2->magic = SHMALLOC_MAGIC;
+		sha2->magic = VSM_CHUNK_MAGIC;
 		sha2->len = sha->len - size;
 		bprintf(sha2->class, "%s", "Free");
 
@@ -109,7 +109,7 @@
 				loghead->alloc_seq = seq++;
 			while (loghead->alloc_seq == 0);
 
-		return (SHA_PTR(sha));
+		return (VSM_PTR(sha));
 	}
 	return (NULL);
 }
@@ -122,7 +122,7 @@
 static void
 vsl_n_check(int fd)
 {
-	struct shmloghead slh;
+	struct vsm_head slh;
 	int i;
 	struct stat st;
 
@@ -134,7 +134,7 @@
 	i = read(fd, &slh, sizeof slh);
 	if (i != sizeof slh)
 		return;
-	if (slh.magic != SHMLOGHEAD_MAGIC)
+	if (slh.magic != VSM_HEAD_MAGIC)
 		return;
 	if (slh.hdrsize != sizeof slh)
 		return;
@@ -157,7 +157,7 @@
 static void
 vsl_buildnew(const char *fn, unsigned size, int fill)
 {
-	struct shmloghead slh;
+	struct vsm_head slh;
 	int i;
 	unsigned u;
 	char buf[64*1024];
@@ -171,7 +171,7 @@
 	}
 
 	memset(&slh, 0, sizeof slh);
-	slh.magic = SHMLOGHEAD_MAGIC;
+	slh.magic = VSM_HEAD_MAGIC;
 	slh.hdrsize = sizeof slh;
 	slh.shm_size = size;
 	i = write(vsl_fd, &slh, sizeof slh);
@@ -276,14 +276,14 @@
 	(void)mlock((void*)loghead, size);
 
 	memset(&loghead->head, 0, sizeof loghead->head);
-	loghead->head.magic = SHMALLOC_MAGIC;
+	loghead->head.magic = VSM_CHUNK_MAGIC;
 	loghead->head.len =
 	    (uint8_t*)(loghead) + size - (uint8_t*)&loghead->head;
 	bprintf(loghead->head.class, "%s", "Free");
 	VWMB();
 
 	VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats,
-	    VSL_CLASS_STAT, VSL_TYPE_STAT, "");
+	    VSM_CLASS_STAT, VSL_TYPE_STAT, "");
 	AN(VSL_stats);
 
 	pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", "");
@@ -291,7 +291,7 @@
 	*pp = *params;
 	params = pp;
 
-	vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS_LOG, "", "");
+	vsl_log_start = mgt_SHM_Alloc(s1, VSM_CLASS_LOG, "", "");
 	AN(vsl_log_start);
 	vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1);
 	vsl_log_nxt = vsl_log_start + 1;

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -189,7 +189,7 @@
 
 	CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
 	sma_sc->stats = mgt_SHM_Alloc(sizeof *sma_sc->stats,
-	    VSL_CLASS_STAT, VSL_TYPE_STAT_SMA, st->ident);
+	    VSM_CLASS_STAT, VSL_TYPE_STAT_SMA, st->ident);
 	memset(sma_sc->stats, 0, sizeof *sma_sc->stats);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -623,7 +623,7 @@
 
 	HSH_config(h_arg);
 
-	mgt_SHM_Init(SHMLOG_FILENAME, l_arg);
+	mgt_SHM_Init(VSM_FILENAME, l_arg);
 
 	vsb_finish(vident);
 	AZ(vsb_overflowed(vident));

Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/include/shmlog.h	2010-06-08 09:09:49 UTC (rev 4927)
@@ -36,7 +36,7 @@
 #ifndef SHMLOG_H_INCLUDED
 #define SHMLOG_H_INCLUDED
 
-#define SHMLOG_FILENAME		"_.vsl"
+#define VSM_FILENAME		"_.vsm"
 
 #include <time.h>
 #include <sys/types.h>
@@ -47,8 +47,8 @@
  * This structure describes each allocation from the shmlog
  */
 
-struct shmalloc {
-#define SHMALLOC_MAGIC		0x43907b6e	/* From /dev/random */
+struct vsm_chunk {
+#define VSM_CHUNK_MAGIC		0x43907b6e	/* From /dev/random */
 	unsigned		magic;
 	unsigned		len;
 	char			class[8];
@@ -56,11 +56,11 @@
 	char			ident[16];
 };
 
-#define SHA_NEXT(sha)		((void*)((uintptr_t)(sha) + (sha)->len))
-#define SHA_PTR(sha)		((void*)((uintptr_t)((sha) + 1)))
+#define VSM_NEXT(sha)		((void*)((uintptr_t)(sha) + (sha)->len))
+#define VSM_PTR(sha)		((void*)((uintptr_t)((sha) + 1)))
 
-struct shmloghead {
-#define SHMLOGHEAD_MAGIC	4185512502U	/* From /dev/random */
+struct vsm_head {
+#define VSM_HEAD_MAGIC		4185512502U	/* From /dev/random */
 	unsigned		magic;
 
 	unsigned		hdrsize;
@@ -76,11 +76,11 @@
 
 	unsigned		alloc_seq;
 	/* Must be last element */
-	struct shmalloc		head;
+	struct vsm_chunk	head;
 };
 
-#define VSL_CLASS_LOG		"Log"
-#define VSL_CLASS_STAT		"Stat"
+#define VSM_CLASS_LOG		"Log"
+#define VSM_CLASS_STAT		"Stat"
 
 /*
  * Shared memory log format

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/include/varnishapi.h	2010-06-08 09:09:49 UTC (rev 4927)
@@ -137,8 +137,8 @@
 extern const char *VSL_tags[256];
 
 
-struct shmalloc *vsl_iter0(const struct VSL_data *vd);
-void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp);
+struct vsm_chunk *vsl_iter0(const struct VSL_data *vd);
+void vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp);
 
 #define VSL_FOREACH(var, vd) \
 	for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var)))

Modified: trunk/varnish-cache/lib/libvarnish/vin.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/vin.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/lib/libvarnish/vin.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -75,7 +75,7 @@
 	}
 
 	/* Definitive length check */
-	if (strlen(dn) + 1 + strlen(SHMLOG_FILENAME) >= sizeof dn) {
+	if (strlen(dn) + 1 + strlen(VSM_FILENAME) >= sizeof dn) {
 		errno = ENAMETOOLONG;
 		return (-1);
 	}
@@ -93,7 +93,7 @@
 			return (-1);
 	}
 	if (vsl != NULL) {
-		bprintf(nm, "%s%s", dn, SHMLOG_FILENAME);
+		bprintf(nm, "%s%s", dn, VSM_FILENAME);
 		*vsl = strdup(nm);
 		if (*vsl == NULL)
 			return (-1);

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -168,7 +168,7 @@
 vsl_open(struct VSL_data *vd, int diag)
 {
 	int i;
-	struct shmloghead slh;
+	struct vsm_head slh;
 
 	if (vd->vsl_lh != NULL)
 		return (0);
@@ -196,7 +196,7 @@
 			    vd->fname, strerror(errno));
 		return (1);
 	}
-	if (slh.magic != SHMLOGHEAD_MAGIC) {
+	if (slh.magic != VSM_HEAD_MAGIC) {
 		if (diag)
 			vd->diag(vd->priv, "Wrong magic number in file %s\n",
 			    vd->fname);
@@ -271,19 +271,19 @@
 
 /*--------------------------------------------------------------------*/
 
-struct shmalloc *
+struct vsm_chunk *
 vsl_iter0(const struct VSL_data *vd)
 {
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
 	if (vd->alloc_seq != vd->vsl_lh->alloc_seq)
 		return(NULL);
-	CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, SHMALLOC_MAGIC);
+	CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC);
 	return (&vd->vsl_lh->head);
 }
 
 void
-vsl_itern(const struct VSL_data *vd, struct shmalloc **pp)
+vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp)
 {
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
@@ -291,25 +291,25 @@
 		*pp = NULL;
 		return;
 	}
-	CHECK_OBJ_NOTNULL(*pp, SHMALLOC_MAGIC);
-	*pp = SHA_NEXT(*pp);
+	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
+	*pp = VSM_NEXT(*pp);
 	if ((void*)(*pp) >= vd->vsl_end) {
 		*pp = NULL;
 		return;
 	}
-	CHECK_OBJ_NOTNULL(*pp, SHMALLOC_MAGIC);
+	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
 }
 
 /*--------------------------------------------------------------------*/
 
-struct shmalloc *
+struct vsm_chunk *
 vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident)
 {
-	struct shmalloc *sha;
+	struct vsm_chunk *sha;
 
 	assert (vd->vsl_lh != NULL);
 	VSL_FOREACH(sha, vd) {
-		CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
+		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
 		if (strcmp(sha->class, class))
 			continue;
 		if (type != NULL && strcmp(sha->type, type))
@@ -327,7 +327,7 @@
 VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident,
     unsigned *lenp)
 {
-	struct shmalloc *sha;
+	struct vsm_chunk *sha;
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
 	sha = vsl_find_alloc(vd, class, type, ident);
@@ -335,5 +335,5 @@
 		return (NULL);
 	if (lenp != NULL)
 		*lenp = sha->len - sizeof *sha;
-	return (SHA_PTR(sha));
+	return (VSM_PTR(sha));
 }

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -261,14 +261,14 @@
 int
 VSL_OpenLog(struct VSL_data *vd)
 {
-	struct shmalloc *sha;
+	struct vsm_chunk *sha;
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	sha = vsl_find_alloc(vd, VSL_CLASS_LOG, "", "");
+	sha = vsl_find_alloc(vd, VSM_CLASS_LOG, "", "");
 	assert(sha != NULL);
 
-	vd->log_start = SHA_PTR(sha);
-	vd->log_end = SHA_NEXT(sha);
+	vd->log_start = VSM_PTR(sha);
+	vd->log_end = VSM_NEXT(sha);
 	vd->log_ptr = vd->log_start + 1;
 
 	vd->last_seq = vd->log_start[0];

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c	2010-06-08 09:09:49 UTC (rev 4927)
@@ -50,13 +50,13 @@
 struct varnish_stats *
 VSL_OpenStats(struct VSL_data *vd)
 {
-	struct shmalloc *sha;
+	struct vsm_chunk *sha;
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
 
-	sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", "");
+	sha = vsl_find_alloc(vd, VSM_CLASS_STAT, "", "");
 	assert(sha != NULL);
-	return (SHA_PTR(sha));
+	return (VSM_PTR(sha));
 }
 
 /*--------------------------------------------------------------------
@@ -104,10 +104,10 @@
 }
 
 static int
-iter_main(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func,
+iter_main(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
     void *priv)
 {
-	struct varnish_stats *st = SHA_PTR(sha);
+	struct varnish_stats *st = VSM_PTR(sha);
 	struct vsl_statpt sp;
 	int i;
 
@@ -128,10 +128,10 @@
 }
 
 static int
-iter_sma(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func,
+iter_sma(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
     void *priv)
 {
-	struct varnish_stats_sma *st = SHA_PTR(sha);
+	struct varnish_stats_sma *st = VSM_PTR(sha);
 	struct vsl_statpt sp;
 	int i;
 
@@ -154,13 +154,13 @@
 int
 VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv)
 {
-	struct shmalloc *sha;
+	struct vsm_chunk *sha;
 	int i;
 
 	i = 0;
 	VSL_FOREACH(sha, vd) {
-		CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
-		if (strcmp(sha->class, VSL_CLASS_STAT))
+		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+		if (strcmp(sha->class, VSM_CLASS_STAT))
 			continue;
 		if (!strcmp(sha->type, VSL_TYPE_STAT))
 			i = iter_main(vd, sha, func, priv);

Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vslapi.h	2010-06-08 08:46:15 UTC (rev 4926)
+++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h	2010-06-08 09:09:49 UTC (rev 4927)
@@ -61,7 +61,7 @@
 	struct stat		fstat;
 
 	int			vsl_fd;
-	struct shmloghead	*vsl_lh;
+	struct vsm_head	*vsl_lh;
 	void			*vsl_end;
 	unsigned		alloc_seq;
 
@@ -117,5 +117,5 @@
 	unsigned long		keep;
 };
 
-struct shmalloc *vsl_find_alloc(const struct VSL_data *vd, const char *class,
+struct vsm_chunk *vsl_find_alloc(const struct VSL_data *vd, const char *class,
     const char *type, const char *ident);




More information about the varnish-commit mailing list