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

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 13 19:40:27 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/1e8edebee242
changeset: 9317:1e8edebee242
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 13 12:40:19 2009 -0400
description:
Use separate read block sizes when reading only message header vs. full message.

diffstat:

8 files changed, 34 insertions(+), 16 deletions(-)
src/lib-storage/index/cydir/cydir-mail.c     |    6 ++----
src/lib-storage/index/dbox/dbox-file.c       |   11 +++++++----
src/lib-storage/index/index-mail.c           |   11 +++++++++++
src/lib-storage/index/index-mail.h           |    1 +
src/lib-storage/index/index-storage.h        |    6 ++++--
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 ++--

diffs (152 lines):

diff -r 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-mail.c	Thu Aug 13 12:40:19 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 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/dbox/dbox-file.c
--- a/src/lib-storage/index/dbox/dbox-file.c	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-file.c	Thu Aug 13 12:40:19 2009 -0400
@@ -21,6 +21,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#define DBOX_READ_BLOCK_SIZE 4096
+
 enum mail_flags dbox_mail_flags_map[DBOX_METADATA_FLAGS_COUNT] = {
 	MAIL_ANSWERED,
 	MAIL_FLAGGED,
@@ -410,7 +412,7 @@ static int dbox_file_open_fd(struct dbox
 	return 1;
 }
 
-static int dbox_file_open(struct dbox_file *file, bool read_header,
+static int dbox_file_open(struct dbox_file *file, bool read_file_header,
 			  bool *deleted_r)
 {
 	int ret;
@@ -431,9 +433,10 @@ static int dbox_file_open(struct dbox_fi
 		}
 	}
 
-	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);
-	return !read_header || file->maildir_file ? 1 :
+	/* FIXME: should use the mail hdr/full block sizes */
+	file->input = i_stream_create_fd(file->fd, DBOX_READ_BLOCK_SIZE, FALSE);
+	i_stream_set_init_buffer_size(file->input, DBOX_READ_BLOCK_SIZE);
+	return !read_file_header || file->maildir_file ? 1 :
 		dbox_file_read_header(file);
 }
 
diff -r 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/index-mail.c	Thu Aug 13 12:40:19 2009 -0400
@@ -805,6 +805,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 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/index-mail.h
--- a/src/lib-storage/index/index-mail.h	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/index-mail.h	Thu Aug 13 12:40:19 2009 -0400
@@ -172,6 +172,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 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/index-storage.h	Thu Aug 13 12:40:19 2009 -0400
@@ -7,8 +7,10 @@
 
 /* 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)
+/* 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)
 
 #define MAILBOX_FULL_SYNC_INTERVAL 5
 
diff -r 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Thu Aug 13 12:40:19 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 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/mbox/mbox-file.c
--- a/src/lib-storage/index/mbox/mbox-file.c	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-file.c	Thu Aug 13 12:40:19 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;
@@ -78,9 +80,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 2fd8d3a2bd52 -r 1e8edebee242 src/lib-storage/index/raw/raw-storage.c
--- a/src/lib-storage/index/raw/raw-storage.c	Thu Aug 13 12:24:42 2009 -0400
+++ b/src/lib-storage/index/raw/raw-storage.c	Thu Aug 13 12:40:19 2009 -0400
@@ -123,8 +123,8 @@ raw_mailbox_open_input(struct mail_stora
 		}
 		return -1;
 	}
-	*input_r = i_stream_create_fd(fd, MAIL_READ_BLOCK_SIZE, TRUE);
-	i_stream_set_init_buffer_size(*input_r, MAIL_READ_BLOCK_SIZE);
+	*input_r = i_stream_create_fd(fd, MAIL_READ_FULL_BLOCK_SIZE, TRUE);
+	i_stream_set_init_buffer_size(*input_r, MAIL_READ_FULL_BLOCK_SIZE);
 	return 0;
 }
 


More information about the dovecot-cvs mailing list