summaryrefslogtreecommitdiff
path: root/src/network_write_mmap.c
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2015-08-23 12:59:07 +0000
committerStefan Bühler <stbuehler@web.de>2015-08-23 12:59:07 +0000
commit912533cd685b63c468df9409a3739a3432c24a39 (patch)
treecb7c94532104236c54bde8fd6fbb123461cdc643 /src/network_write_mmap.c
parent6d6dbadb1436e38223b25605cda59f195c68f5e5 (diff)
downloadlighttpd1.4-912533cd685b63c468df9409a3739a3432c24a39.tar.gz
lighttpd1.4-912533cd685b63c468df9409a3739a3432c24a39.zip
[mmap] fix mmap alignment
From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3028 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src/network_write_mmap.c')
-rw-r--r--src/network_write_mmap.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/network_write_mmap.c b/src/network_write_mmap.c
index 9747d619..9ff3ae96 100644
--- a/src/network_write_mmap.c
+++ b/src/network_write_mmap.c
@@ -1,7 +1,5 @@
#include "network_backends.h"
-#if defined(USE_MMAP)
-
#include "network.h"
#include "log.h"
#include "sys-mmap.h"
@@ -11,6 +9,20 @@
#include <errno.h>
#include <string.h>
+#define MMAP_CHUNK_SIZE (512*1024)
+
+off_t mmap_align_offset(off_t start) {
+ static long pagesize = 0;
+ if (0 == pagesize) {
+ pagesize = sysconf(_SC_PAGESIZE);
+ force_assert(pagesize < MMAP_CHUNK_SIZE);
+ }
+ force_assert(start >= (start % pagesize));
+ return start - (start % pagesize);
+}
+
+#if defined(USE_MMAP)
+
#if 0
/* read mmap()ed data into local buffer */
#define LOCAL_BUFFERING 1
@@ -70,10 +82,10 @@ int network_write_file_chunk_mmap(server *srv, connection *con, int fd, chunkque
* 3. use non-blocking IO for file-transfers
* */
- c->file.mmap.offset = offset & ~(4095); /* align at 4kb */
+ c->file.mmap.offset = mmap_align_offset(offset);
- /* all mmap()ed areas are 512kb except the last which might be smaller */
- c->file.mmap.length = 512*1024;
+ /* all mmap()ed areas are MMAP_CHUNK_SIZE except the last which might be smaller */
+ c->file.mmap.length = MMAP_CHUNK_SIZE;
if (c->file.mmap.offset > file_end - (off_t)c->file.mmap.length) {
c->file.mmap.length = file_end - c->file.mmap.offset;
}