changeset 644:415498fa78d6 HEAD

mail_read_mmaped: Use mmap() instead of read() to read mail files. read() seems to be a bit faster with my Linux/x86 and it's better with NFS, so that's the default.
author Timo Sirainen <tss@iki.fi>
date Thu, 21 Nov 2002 22:31:02 +0200
parents da34bdd4e0c6
children 0834f1490e68
files dovecot-example.conf src/lib-index/mail-index-open.c src/lib-index/mail-index.h src/lib-index/maildir/maildir-open.c src/lib-index/maildir/maildir-update.c src/lib-index/mbox/mbox-index.c src/master/imap-process.c src/master/settings.c src/master/settings.h
diffstat 9 files changed, 41 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dovecot-example.conf	Thu Nov 21 22:13:32 2002 +0200
+++ b/dovecot-example.conf	Thu Nov 21 22:31:02 2002 +0200
@@ -165,6 +165,10 @@
 # But it also creates a bit more disk I/O which may just make it slower.
 #mail_save_crlf = no
 
+# Use mmap() instead of read() to read mail files. read() seems to be a bit
+# faster with my Linux/x86 and it's better with NFS, so that's the default.
+#mail_read_mmaped = no
+
 # Copy mail to another folders using hard links. This is much faster than
 # actually copying the file. Only problem with it is that if either of the
 # mails are modified directly both will change. This isn't a problem with
--- a/src/lib-index/mail-index-open.c	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/lib-index/mail-index-open.c	Thu Nov 21 22:31:02 2002 +0200
@@ -150,6 +150,7 @@
 			return FALSE;
 	}
 
+	index->mail_read_mmaped = getenv("MAIL_READ_MMAPED") != NULL;
 	return TRUE;
 }
 
--- a/src/lib-index/mail-index.h	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/lib-index/mail-index.h	Thu Nov 21 22:31:02 2002 +0200
@@ -366,6 +366,7 @@
 
 	unsigned int anon_mmap:1;
 	unsigned int opened:1;
+	unsigned int mail_read_mmaped:1;
 	unsigned int inconsistent:1;
 	unsigned int nodiskspace:1;
 };
@@ -376,7 +377,7 @@
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
-	0, 0, 0, 0, 0, 0
+	0, 0, 0, 0, 0, 0, 0
 
 /* defaults - same as above but prefixed with mail_index_. */
 int mail_index_open(MailIndex *index, int update_recent, int fast);
@@ -433,6 +434,8 @@
 
 /* Max. mmap()ed size for a message */
 #define MAIL_MMAP_BLOCK_SIZE (1024*256)
+/* Block size when read()ing message. */
+#define MAIL_READ_BLOCK_SIZE (1024*8)
 
 /* Delete unused non-local temp files after 24h. Just to be sure we don't
    delete it too early. The temp files don't harm much anyway. */
--- a/src/lib-index/maildir/maildir-open.c	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/lib-index/maildir/maildir-open.c	Thu Nov 21 22:31:02 2002 +0200
@@ -53,6 +53,11 @@
 		}
 	}
 
-	return i_buffer_create_mmap(fd, default_pool, MAIL_MMAP_BLOCK_SIZE,
-				    0, 0, TRUE);
+	if (index->mail_read_mmaped) {
+		return i_buffer_create_mmap(fd, default_pool,
+					    MAIL_MMAP_BLOCK_SIZE, 0, 0, TRUE);
+	} else {
+		return i_buffer_create_file(fd, default_pool,
+					    MAIL_READ_BLOCK_SIZE, TRUE);
+	}
 }
--- a/src/lib-index/maildir/maildir-update.c	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/lib-index/maildir/maildir-update.c	Thu Nov 21 22:31:02 2002 +0200
@@ -16,8 +16,13 @@
 		return TRUE;
 
 	t_push();
-	inbuf = i_buffer_create_mmap(fd, data_stack_pool, MAIL_MMAP_BLOCK_SIZE,
-				     0, 0, FALSE);
+	if (index->mail_read_mmaped) {
+		inbuf = i_buffer_create_mmap(fd, data_stack_pool,
+					     MAIL_MMAP_BLOCK_SIZE, 0, 0, FALSE);
+	} else {
+		inbuf = i_buffer_create_file(fd, data_stack_pool,
+					     MAIL_READ_BLOCK_SIZE, FALSE);
+	}
 	mail_index_update_headers(update, inbuf, cache_fields, NULL, NULL);
 	i_buffer_unref(inbuf);
 	t_pop();
--- a/src/lib-index/mbox/mbox-index.c	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/lib-index/mbox/mbox-index.c	Thu Nov 21 22:31:02 2002 +0200
@@ -71,9 +71,19 @@
 	}
 
 	if (index->mbox_inbuf == NULL) {
-		index->mbox_inbuf =
-			i_buffer_create_mmap(index->mbox_fd, default_pool,
-					     MAIL_MMAP_BLOCK_SIZE, 0, 0, FALSE);
+		if (index->mail_read_mmaped) {
+			index->mbox_inbuf =
+				i_buffer_create_mmap(index->mbox_fd,
+						     default_pool,
+						     MAIL_MMAP_BLOCK_SIZE,
+						     0, 0, FALSE);
+		} else {
+			index->mbox_inbuf =
+				i_buffer_create_file(index->mbox_fd,
+						     default_pool,
+						     MAIL_READ_BLOCK_SIZE,
+						     FALSE);
+		}
 	}
 
 	i_buffer_set_read_limit(index->mbox_inbuf, 0);
--- a/src/master/imap-process.c	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/master/imap-process.c	Thu Nov 21 22:31:02 2002 +0200
@@ -124,6 +124,8 @@
 
 	if (set_mail_save_crlf)
 		putenv("MAIL_SAVE_CRLF=1");
+	if (set_mail_read_mmaped)
+		putenv("MAIL_READ_MMAPED=1");
 	if (set_maildir_copy_with_hardlinks)
 		putenv("MAILDIR_COPY_WITH_HARDLINKS=1");
 	if (set_maildir_check_content_changes)
--- a/src/master/settings.c	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/master/settings.c	Thu Nov 21 22:31:02 2002 +0200
@@ -62,6 +62,7 @@
 	{ "mailbox_check_interval",
 				SET_INT, &set_mailbox_check_interval },
 	{ "mail_save_crlf",	SET_BOOL,&set_mail_save_crlf },
+	{ "mail_read_mmaped",	SET_BOOL,&set_mail_read_mmaped },
 	{ "maildir_copy_with_hardlinks",
 				SET_BOOL,&set_maildir_copy_with_hardlinks },
 	{ "maildir_check_content_changes",
@@ -121,6 +122,7 @@
 char *set_mail_never_cache_fields = NULL;
 unsigned int set_mailbox_check_interval = 30;
 int set_mail_save_crlf = FALSE;
+int set_mail_read_mmaped = FALSE;
 int set_maildir_copy_with_hardlinks = FALSE;
 int set_maildir_check_content_changes = FALSE;
 char *set_mbox_locks = "dotlock fcntl flock";
--- a/src/master/settings.h	Thu Nov 21 22:13:32 2002 +0200
+++ b/src/master/settings.h	Thu Nov 21 22:31:02 2002 +0200
@@ -43,6 +43,7 @@
 extern char *set_mail_never_cache_fields;
 extern unsigned int set_mailbox_check_interval;
 extern int set_mail_save_crlf;
+extern int set_mail_read_mmaped;
 extern int set_maildir_copy_with_hardlinks;
 extern int set_maildir_check_content_changes;
 extern char *set_mbox_locks;