dovecot-2.2: lib-index: Optimize cache file reads with MAIL_INDE...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 29 17:55:55 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/0efb98659a1f
changeset: 15333:0efb98659a1f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 26 11:43:05 2012 +0300
description:
lib-index: Optimize cache file reads with MAIL_INDEX_OPEN_FLAG_SAVEONLY

diffstat:

 src/lib-index/mail-cache-fields.c |  2 +-
 src/lib-index/mail-cache.c        |  9 +++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diffs (38 lines):

diff -r 3700fb6f8a42 -r 0efb98659a1f src/lib-index/mail-cache-fields.c
--- a/src/lib-index/mail-cache-fields.c	Fri Oct 26 11:37:07 2012 +0300
+++ b/src/lib-index/mail-cache-fields.c	Fri Oct 26 11:43:05 2012 +0300
@@ -232,7 +232,7 @@
 		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) {
diff -r 3700fb6f8a42 -r 0efb98659a1f src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Fri Oct 26 11:37:07 2012 +0300
+++ b/src/lib-index/mail-cache.c	Fri Oct 26 11:43:05 2012 +0300
@@ -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 @@
 	} 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) {


More information about the dovecot-cvs mailing list