From: phk Date: Tue, 13 Jun 2006 20:06:45 +0000 (+0000) Subject: Be more aggressive about mmap'ing memory. The size_t thing is a bogus X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e7d2a064ae5df12fbd0e067d7e43acd10073882;p=varnish Be more aggressive about mmap'ing memory. The size_t thing is a bogus constraint in FreeBSD and we shouldn't really listen to it. On my laptop I can mmap 2422MB file this way. This may be so aggressive that it leaves insufficient address space for malloc/threadstacks and other issues. If we find a way to pick up a platform/architecture specific limit, we can enforce that along the way. For now people can just specify a saner and smaller "-sfile" size. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@177 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index 1473b606..23c86fe5 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -238,31 +238,40 @@ smf_init(struct stevedore *parent, const char *spec) /*--------------------------------------------------------------------*/ +/* + * XXX: This may be too aggressive and soak up too much address room. + * XXX: On the other hand, the user, directly or implicitly asked us to + * XXX: use this much storage, so we should make a decent effort. + * XXX: worst case (I think), malloc will fail. + */ + static void -smf_open_chunk(struct smf_sc *sc, size_t sz, size_t off, size_t *fail, size_t *sum) +smf_open_chunk(struct smf_sc *sc, off_t sz, off_t off, off_t *fail, off_t *sum) { void *p; - size_t h; - - if (sz < getpagesize() * MINPAGES) - return; + off_t h; - if (sz > *fail) + if (*fail < getpagesize() * MINPAGES) return; - printf("%s(%ju, %ju)\n", __func__, (uintmax_t)sz, (uintmax_t)off); - p = mmap(NULL, sz, PROT_READ|PROT_WRITE, - MAP_NOCORE | MAP_NOSYNC | MAP_PRIVATE, sc->fd, off); - printf("mmap = %p\n", p); - if (p != MAP_FAILED) { - (*sum) += sz; - return; + if (sz < *fail && sz < SIZE_T_MAX) { + p = mmap(NULL, sz, PROT_READ|PROT_WRITE, + MAP_NOCORE | MAP_NOSYNC | MAP_PRIVATE, sc->fd, off); + if (p != MAP_FAILED) { + printf("%12p...%12p %12jx...%12jx %12jx\n", + p, (u_char *)p + sz, + off, off + sz, sz); + (*sum) += sz; + return; + } } if (sz < *fail) *fail = sz; h = sz / 2; + if (h > SIZE_T_MAX) + h = SIZE_T_MAX; h -= (h % getpagesize()); smf_open_chunk(sc, h, off, fail, sum); @@ -273,17 +282,11 @@ static void smf_open(struct stevedore *st) { struct smf_sc *sc; - size_t fail = SIZE_T_MAX; - size_t sum = 0; + off_t fail = SIZE_T_MAX; + off_t sum = 0; sc = st->priv; - if (sc->filesize > SIZE_T_MAX) { - sc->filesize = SIZE_T_MAX; - fprintf(stderr, "Truncating %s to SIZE_T_MAX %ju\n", - sc->filename, sc->filesize); - } - smf_open_chunk(sc, sc->filesize, 0, &fail, &sum); printf("managed to mmap %ju bytes of %ju\n", (uintmax_t)sum, sc->filesize);