]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Optimize cache file reads with MAIL_INDEX_OPEN_FLAG_SAVEONLY
authorTimo Sirainen <tss@iki.fi>
Fri, 26 Oct 2012 08:43:05 +0000 (11:43 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 26 Oct 2012 08:43:05 +0000 (11:43 +0300)
src/lib-index/mail-cache-fields.c
src/lib-index/mail-cache.c

index 6b0944aa7facb2f67f4a126c97694c21598feef9..531a5f05d2bd08d7a21b85123164fe7617e65a60 100644 (file)
@@ -232,7 +232,7 @@ mail_cache_header_fields_get_offset(struct mail_cache *cache,
                offset = next_offset;
                invalidate = TRUE;
 
-               if (cache->mmap_base != NULL) {
+               if (cache->mmap_base != NULL || cache->map_with_read) {
                        ret = mail_cache_map(cache, offset, sizeof(*field_hdr),
                                             &data);
                        if (ret <= 0) {
index 4bf118a528f30c2c2c6b06bd87a4cb90f4c0727f..75ebea995a4ba858c46b57aa632f7adcc01ce975 100644 (file)
@@ -13,6 +13,8 @@
 
 #include <unistd.h>
 
+#define MAIL_CACHE_MIN_HEADER_READ_SIZE 4096
+
 void mail_cache_set_syscall_error(struct mail_cache *cache,
                                  const char *function)
 {
@@ -321,6 +323,13 @@ mail_cache_map_with_read(struct mail_cache *cache, size_t offset, size_t size,
        } else {
                buffer_set_used_size(cache->read_buf, 0);
        }
+       if (offset == 0 && size < MAIL_CACHE_MIN_HEADER_READ_SIZE) {
+               /* we can usually read the fields header after the cache
+                  header. we need them both, so try to read them all with one
+                  pread() call. */
+               size = MAIL_CACHE_MIN_HEADER_READ_SIZE;
+       }
+
        data = buffer_append_space_unsafe(cache->read_buf, size);
        ret = pread(cache->fd, data, size, offset);
        if (ret < 0) {