Commit 0802050a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move vsl handles out of heritage, they do no good there.

Change -l argument processing, to take up to three parts:

	-l<shmlog>,<space>,<fill>

<shmlog> is size of space for VSL records.
	default is 80m

<space> is size of space for other allocations (more later)
	default is 1m

<fill> is '+' or '-' to control preallocation of the shmfile,
	default to on (+), which reduces risk of fragmentation.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4797 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 63c758a4
......@@ -55,10 +55,6 @@ struct heritage {
struct listen_sock_head socks;
unsigned nsocks;
/* Share memory log fd and size (incl header) */
int vsl_fd;
unsigned vsl_size;
/* Hash method */
struct hash_slinger *hash;
......
......@@ -56,6 +56,8 @@ struct varnish_stats *VSL_stats;
struct shmloghead *loghead;
unsigned char *logstart;
static int vsl_fd = -1;
static unsigned vsl_size;
/*--------------------------------------------------------------------*/
......@@ -95,19 +97,21 @@ vsl_goodold(int fd)
}
/* XXX more checks */
heritage.vsl_size = slh.size + slh.start;
vsl_size = slh.size + slh.start;
return (1);
}
static void
vsl_buildnew(const char *fn, unsigned size)
vsl_buildnew(const char *fn, unsigned size, int fill)
{
struct shmloghead slh;
int i;
unsigned u;
char buf[64*1024];
(void)unlink(fn);
heritage.vsl_fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0644);
if (heritage.vsl_fd < 0) {
vsl_fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0644);
if (vsl_fd < 0) {
fprintf(stderr, "Could not open %s: %s\n",
fn, strerror(errno));
exit (1);
......@@ -119,48 +123,108 @@ vsl_buildnew(const char *fn, unsigned size)
slh.size = size;
slh.ptr = 0;
slh.start = sizeof slh + sizeof *params;
i = write(heritage.vsl_fd, &slh, sizeof slh);
i = write(vsl_fd, &slh, sizeof slh);
xxxassert(i == sizeof slh);
heritage.vsl_size = slh.start + size;
AZ(ftruncate(heritage.vsl_fd, (off_t)heritage.vsl_size));
vsl_size = slh.start + size;
if (fill) {
memset(buf, 0, sizeof buf);
for (u = sizeof slh; u < size; ) {
i = write(vsl_fd, buf, sizeof buf);
if (i <= 0) {
fprintf(stderr, "Write error %s: %s\n",
fn, strerror(errno));
exit (1);
}
u += i;
}
}
AZ(ftruncate(vsl_fd, (off_t)vsl_size));
}
void
mgt_SHM_Init(const char *fn, const char *l_arg)
{
int i;
int i, fill;
struct params *pp;
const char *arg_default = "80m";
const char *q;
uintmax_t size;
uintmax_t size, s1, s2;
char **av, **ap;
if (l_arg == NULL)
l_arg = arg_default;
l_arg = "";
q = str2bytes(l_arg, &size, 0);
if (q != NULL) {
fprintf(stderr, "Parameter error:\n");
fprintf(stderr, "\t-l ...: %s\n", q);
exit (1);
av = ParseArgv(l_arg, ARGV_COMMA);
AN(av);
if (av[0] != NULL)
ARGV_ERR("\t-l ...: %s", av[0]);
printf("<%s> <%s> <%s>\n", av[1], av[2], av[3]);
ap = av + 1;
/* Size of SHMLOG */
if (*ap != NULL && **ap != '\0') {
q = str2bytes(*ap, &s1, 0);
if (q != NULL)
ARGV_ERR("\t-l[1] ...: %s\n", q);
} else {
s1 = 80 * 1024 * 1024;
}
if (*ap != NULL)
ap++;
/* Size of space for other stuff */
if (*ap != NULL && **ap != '\0') {
q = str2bytes(*ap, &s2, 0);
if (q != NULL)
ARGV_ERR("\t-l[2] ...: %s\n", q);
} else {
s2 = 1024 * 1024;
}
if (*ap != NULL)
ap++;
/* Fill or not ? */
if (*ap != NULL) {
if (*ap == '\0')
fill = 1;
else if (!strcmp(*ap, "-"))
fill = 0;
else if (!strcmp(*ap, "+"))
fill = 1;
else
ARGV_ERR("\t-l[3] ...: Must be \"-\" or \"+\"\n");
ap++;
} else {
fill = 1;
}
FreeArgv(av);
size = s1 + s2;
if (av[2] == NULL)
q = str2bytes(av[2], &size, 0);
i = open(fn, O_RDWR, 0644);
if (i >= 0 && vsl_goodold(i)) {
fprintf(stderr, "Using old SHMFILE\n");
heritage.vsl_fd = i;
vsl_fd = i;
} else {
fprintf(stderr, "Creating new SHMFILE\n");
(void)close(i);
vsl_buildnew(fn, size);
vsl_buildnew(fn, size, fill);
}
loghead = (void *)mmap(NULL, heritage.vsl_size,
loghead = (void *)mmap(NULL, vsl_size,
PROT_READ|PROT_WRITE,
MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED,
heritage.vsl_fd, 0);
vsl_fd, 0);
loghead->master_pid = getpid();
xxxassert(loghead != MAP_FAILED);
(void)mlock((void*)loghead, heritage.vsl_size);
(void)mlock((void*)loghead, vsl_size);
VSL_stats = &loghead->stats;
pp = (void *)(loghead + 1);
*pp = *params;
......
......@@ -276,6 +276,7 @@ varnish_launch(struct varnish *v)
AN(vsb);
vsb_printf(vsb, "cd ../varnishd &&");
vsb_printf(vsb, " ./varnishd -d -d -n %s", v->workdir);
vsb_printf(vsb, " -l 10m,1m,-");
vsb_printf(vsb, " -p auto_restart=off");
vsb_printf(vsb, " -p syslog_cli_traffic=off");
vsb_printf(vsb, " -a '%s'", "127.0.0.1:0");
......
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