Commit 9917c26f authored by gquintard's avatar gquintard Committed by GitHub

Merge pull request #1997 from gquintard/advice

Tunable madvise for file storage
parents eb0b073f 45150f2c
......@@ -238,6 +238,8 @@ usage(void)
fprintf(stderr, FMT, "", " -s file,<dir_or_file>,<size>");
fprintf(stderr, FMT, "",
" -s file,<dir_or_file>,<size>,<granularity>");
fprintf(stderr, FMT, "",
" -s file,<dir_or_file>,<size>,<granularity>,<advice>");
fprintf(stderr, FMT, "", " -s persistent (experimental)");
fprintf(stderr, FMT, "-T address:port",
"Telnet listen address and port");
......
......@@ -96,6 +96,7 @@ struct smf_sc {
int fd;
unsigned pagesize;
uintmax_t filesize;
int advice;
struct smfhead order;
struct smfhead free[NBUCKET];
struct smfhead used;
......@@ -110,13 +111,14 @@ smf_init(struct stevedore *parent, int ac, char * const *av)
struct smf_sc *sc;
unsigned u;
uintmax_t page_size;
int advice = MADV_RANDOM;
AZ(av[ac]);
size = NULL;
page_size = getpagesize();
if (ac > 3)
if (ac > 4)
ARGV_ERR("(-sfile) too many arguments\n");
if (ac < 1 || *av[0] == '\0')
ARGV_ERR("(-sfile) path is mandatory\n");
......@@ -129,6 +131,16 @@ smf_init(struct stevedore *parent, int ac, char * const *av)
if (r != NULL)
ARGV_ERR("(-sfile) granularity \"%s\": %s\n", av[2], r);
}
if (ac > 3) {
if (!strcmp(av[3], "normal"))
advice = MADV_NORMAL;
else if (!strcmp(av[3], "random"))
advice = MADV_RANDOM;
else if (!strcmp(av[3], "sequential"))
advice = MADV_SEQUENTIAL;
else
ARGV_ERR("(-s file) invalid advice: \"%s\"", av[3]);
}
AN(fn);
......@@ -139,7 +151,7 @@ smf_init(struct stevedore *parent, int ac, char * const *av)
VTAILQ_INIT(&sc->free[u]);
VTAILQ_INIT(&sc->used);
sc->pagesize = page_size;
sc->advice = advice;
parent->priv = sc;
(void)STV_GetFile(fn, &sc->fd, &sc->filename, "-sfile");
......@@ -366,7 +378,7 @@ smf_open_chunk(struct smf_sc *sc, off_t sz, off_t off, off_t *fail, off_t *sum)
p = mmap(NULL, sz, PROT_READ|PROT_WRITE,
MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, off);
if (p != MAP_FAILED) {
(void) madvise(p, sz, MADV_RANDOM);
(void) madvise(p, sz, sc->advice);
(*sum) += sz;
new_smf(sc, p, off, sz);
return;
......
......@@ -48,7 +48,7 @@ depend on the operating systems ability to page effectively.
file
~~~~
syntax: file[,path[,size[,granularity]]]
syntax: file[,path[,size[,granularity,[advice]]]]
The file backend stores objects in memory backed by an unlinked file on disk
with `mmap`.
......@@ -94,6 +94,13 @@ have many small objects.
File performance is typically limited to the write speed of the
device, and depending on use, the seek time.
'advice' dictates what Varnish tells the system to optimize reads. Depending
on your OS, disks and object sizes, it can be beneficial to tweak this. The
three possible values are "normal", "random" (default) and "sequential" and
correspond to MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL, respectively.
For example, large objects and rotational disk should profit from "sequential"
on Linux.
persistent (experimental)
~~~~~~~~~~~~~~~~~~~~~~~~~
......
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