Commit 84a760b1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4927 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e82cbe87
......@@ -634,7 +634,7 @@ void SES_Charge(struct sess *sp);
/* 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, ...);
......
......@@ -41,7 +41,7 @@ void VCA_tweak_waiter(struct cli *cli, const char *arg);
/* 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;
......
......@@ -55,7 +55,7 @@ SVNID("$Id$")
#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 @@ static int vsl_fd = -1;
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 @@ mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *id
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 @@ mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *id
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 @@ mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *id
loghead->alloc_seq = seq++;
while (loghead->alloc_seq == 0);
return (SHA_PTR(sha));
return (VSM_PTR(sha));
}
return (NULL);
}
......@@ -122,7 +122,7 @@ mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *id
static void
vsl_n_check(int fd)
{
struct shmloghead slh;
struct vsm_head slh;
int i;
struct stat st;
......@@ -134,7 +134,7 @@ vsl_n_check(int fd)
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 @@ vsl_n_check(int fd)
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 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
}
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 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
(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 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
*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;
......
......@@ -189,7 +189,7 @@ sma_ready(struct stevedore *st)
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);
}
......
......@@ -623,7 +623,7 @@ main(int argc, char * const *argv)
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));
......
......@@ -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 @@ struct shmalloc {
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 @@ struct shmloghead {
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
......
......@@ -137,8 +137,8 @@ struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
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)))
......
......@@ -75,7 +75,7 @@ vin_n_arg(const char *n_arg, char **name, char **dir, char **vsl)
}
/* 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 @@ vin_n_arg(const char *n_arg, char **name, char **dir, char **vsl)
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);
......
......@@ -168,7 +168,7 @@ static int
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 @@ vsl_open(struct VSL_data *vd, int diag)
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 @@ VSL_ReOpen(struct VSL_data *vd, int diag)
/*--------------------------------------------------------------------*/
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 @@ vsl_itern(const struct VSL_data *vd, struct shmalloc **pp)
*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 @@ void *
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 @@ VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const c
return (NULL);
if (lenp != NULL)
*lenp = sha->len - sizeof *sha;
return (SHA_PTR(sha));
return (VSM_PTR(sha));
}
......@@ -261,14 +261,14 @@ VSL_H_Print(void *priv, enum shmlogtag tag, unsigned fd, unsigned len,
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];
......
......@@ -50,13 +50,13 @@ SVNID("$Id$")
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 @@ iter_call(const struct VSL_data *vd, vsl_stat_f *func, void *priv,
}
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 @@ iter_main(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func,
}
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 @@ iter_sma(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func,
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);
......
......@@ -61,7 +61,7 @@ struct VSL_data {
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 @@ struct VSL_data {
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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment