dovecot-2.0: Use separate read block sizes when reading only mes...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 13 19:46:35 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/72b79f58ce1b
changeset: 9779:72b79f58ce1b
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 13 12:46:28 2009 -0400
description:
Use separate read block sizes when reading only message header vs. full message.

diffstat:

8 files changed, 31 insertions(+), 14 deletions(-)
src/lib-storage/index/cydir/cydir-mail.c     |    6 ++----
src/lib-storage/index/dbox/dbox-file.c       |    6 ++++--
src/lib-storage/index/index-mail.c           |   11 +++++++++++
src/lib-storage/index/index-mail.h           |    1 +
src/lib-storage/index/maildir/maildir-mail.c |    4 ++--
src/lib-storage/index/mbox/mbox-file.c       |    7 +++++--
src/lib-storage/index/raw/raw-storage.c      |    4 ++--
src/lib-storage/mail-storage-private.h       |    6 ++++--

diffs (140 lines):

diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-mail.c	Thu Aug 13 12:46:28 2009 -0400
@@ -112,10 +112,8 @@ cydir_mail_get_stream(struct mail *_mail
 			}
 			return -1;
 		}
-		mail->data.stream =
-			i_stream_create_fd(fd, MAIL_READ_BLOCK_SIZE, TRUE);
-		i_stream_set_init_buffer_size(mail->data.stream,
-					      MAIL_READ_BLOCK_SIZE);
+		mail->data.stream = i_stream_create_fd(fd, 0, TRUE);
+		index_mail_set_read_buffer_size(_mail, mail->data.stream);
 	}
 
 	return index_mail_init_stream(mail, hdr_size, body_size, stream_r);
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/dbox/dbox-file.c
--- a/src/lib-storage/index/dbox/dbox-file.c	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-file.c	Thu Aug 13 12:46:28 2009 -0400
@@ -23,6 +23,8 @@
 #include <ctype.h>
 #include <fcntl.h>
 
+#define DBOX_READ_BLOCK_SIZE 4096
+
 char *dbox_generate_tmp_filename(void)
 {
 	static unsigned int create_count = 0;
@@ -427,8 +429,8 @@ int dbox_file_open(struct dbox_file *fil
 		}
 	}
 
-	file->input = i_stream_create_fd(file->fd, MAIL_READ_BLOCK_SIZE, FALSE);
-	i_stream_set_init_buffer_size(file->input, MAIL_READ_BLOCK_SIZE);
+	file->input = i_stream_create_fd(file->fd, 0, FALSE);
+	i_stream_set_init_buffer_size(file->input, DBOX_READ_BLOCK_SIZE);
 	return file->maildir_file ? 1 :
 		dbox_file_read_header(file);
 }
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/index-mail.c	Thu Aug 13 12:46:28 2009 -0400
@@ -800,6 +800,17 @@ static void index_mail_stream_destroy_ca
 	i_assert(mail->data.destroying_stream);
 
 	mail->data.destroying_stream = FALSE;
+}
+
+void index_mail_set_read_buffer_size(struct mail *_mail, struct istream *input)
+{
+	struct index_mail *mail = (struct index_mail *)_mail;
+	unsigned int block_size;
+
+	i_stream_set_max_buffer_size(input, MAIL_READ_FULL_BLOCK_SIZE);
+	block_size = (mail->data.access_part & READ_BODY) != 0 ?
+		MAIL_READ_FULL_BLOCK_SIZE : MAIL_READ_HDR_BLOCK_SIZE;
+	i_stream_set_init_buffer_size(input, block_size);
 }
 
 int index_mail_init_stream(struct index_mail *mail,
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/index-mail.h
--- a/src/lib-storage/index/index-mail.h	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/index-mail.h	Thu Aug 13 12:46:28 2009 -0400
@@ -174,6 +174,7 @@ int index_mail_get_header_stream(struct 
 int index_mail_get_header_stream(struct mail *_mail,
 				 struct mailbox_header_lookup_ctx *headers,
 				 struct istream **stream_r);
+void index_mail_set_read_buffer_size(struct mail *mail, struct istream *input);
 
 enum mail_flags index_mail_get_flags(struct mail *_mail);
 uint64_t index_mail_get_modseq(struct mail *_mail);
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Thu Aug 13 12:46:28 2009 -0400
@@ -66,8 +66,8 @@ maildir_open_mail(struct maildir_mailbox
 		return NULL;
 	}
 
-	input = i_stream_create_fd(fd, MAIL_READ_BLOCK_SIZE, TRUE);
-	i_stream_set_init_buffer_size(input, MAIL_READ_BLOCK_SIZE);
+	input = i_stream_create_fd(fd, 0, TRUE);
+	index_mail_set_read_buffer_size(mail, input);
 	return input;
 }
 
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/mbox/mbox-file.c
--- a/src/lib-storage/index/mbox/mbox-file.c	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-file.c	Thu Aug 13 12:46:28 2009 -0400
@@ -10,6 +10,8 @@
 #include <sys/stat.h>
 #include <utime.h>
 
+#define MBOX_READ_BLOCK_SIZE (1024*4)
+
 int mbox_file_open(struct mbox_mailbox *mbox)
 {
 	struct stat st;
@@ -79,9 +81,10 @@ int mbox_file_open_stream(struct mbox_ma
 		} else {
 			mbox->mbox_file_stream =
 				i_stream_create_fd(mbox->mbox_fd,
-						   MAIL_READ_BLOCK_SIZE, FALSE);
+						   MBOX_READ_BLOCK_SIZE,
+						   FALSE);
 			i_stream_set_init_buffer_size(mbox->mbox_file_stream,
-						      MAIL_READ_BLOCK_SIZE);
+						      MBOX_READ_BLOCK_SIZE);
 		}
 	}
 
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/index/raw/raw-storage.c
--- a/src/lib-storage/index/raw/raw-storage.c	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/index/raw/raw-storage.c	Thu Aug 13 12:46:28 2009 -0400
@@ -85,8 +85,8 @@ static int raw_mailbox_open(struct mailb
 		}
 		return -1;
 	}
-	box->input = i_stream_create_fd(fd, MAIL_READ_BLOCK_SIZE, TRUE);
-	i_stream_set_init_buffer_size(box->input, MAIL_READ_BLOCK_SIZE);
+	box->input = i_stream_create_fd(fd, MAIL_READ_FULL_BLOCK_SIZE, TRUE);
+	i_stream_set_init_buffer_size(box->input, MAIL_READ_FULL_BLOCK_SIZE);
 	return index_storage_mailbox_open(box);
 }
 
diff -r 3bbad277bef0 -r 72b79f58ce1b src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Thu Aug 13 12:23:44 2009 -0400
+++ b/src/lib-storage/mail-storage-private.h	Thu Aug 13 12:46:28 2009 -0400
@@ -7,8 +7,10 @@
 #include "mail-storage-settings.h"
 #include "mail-index-private.h"
 
-/* Block size when read()ing message. */
-#define MAIL_READ_BLOCK_SIZE (1024*8)
+/* Block size when read()ing message header. */
+#define MAIL_READ_HDR_BLOCK_SIZE (1024*4)
+/* Block size when read()ing message (header and) body. */
+#define MAIL_READ_FULL_BLOCK_SIZE (1024*8)
 
 /* Called after mail storage has been created */
 extern void (*hook_mail_storage_created)(struct mail_storage *storage);


More information about the dovecot-cvs mailing list