Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6101:6805ccf0b82e HEAD
mmap() mailbox list index only if it's at least 32kB
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 19 Jul 2007 04:47:25 +0300 |
parents | a55ee2e3caac |
children | a7dca74c0978 |
files | src/lib-index/mailbox-list-index-private.h src/lib-index/mailbox-list-index-sync.c src/lib-index/mailbox-list-index.c |
diffstat | 3 files changed, 24 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mailbox-list-index-private.h Thu Jul 19 04:18:30 2007 +0300 +++ b/src/lib-index/mailbox-list-index-private.h Thu Jul 19 04:47:25 2007 +0300 @@ -10,6 +10,8 @@ #define MAILBOX_LIST_COMPRESS_PERCENTAGE 10 #define MAILBOX_LIST_COMPRESS_MIN_SIZE 1024 +#define MAILBOX_LIST_INDEX_MMAP_MIN_SIZE (1024*32) + struct mailbox_list_index_header { uint8_t major_version; uint8_t minor_version;
--- a/src/lib-index/mailbox-list-index-sync.c Thu Jul 19 04:18:30 2007 +0300 +++ b/src/lib-index/mailbox-list-index-sync.c Thu Jul 19 04:47:25 2007 +0300 @@ -502,7 +502,7 @@ /* all allocations must be 32bit aligned */ pos = (pos + 3) & ~3; - if (ctx->index->mmap_disable) { + if (ctx->index->mmap_base == NULL) { /* write the data into temporary buffer first */ buffer_reset(ctx->output_buf); @@ -647,7 +647,7 @@ i_assert(dest == nondeleted_count); i_assert(name_pos == space_needed); - if (index->mmap_disable) { + if (index->mmap_base == NULL) { file_cache_write(index->file_cache, ctx->output_buf->data, ctx->output_buf->used, ctx->output->offset); o_stream_send(ctx->output, ctx->output_buf->data, @@ -661,7 +661,7 @@ /* add a link to this newly created directory. */ uint32_t data = mail_index_uint32_to_offset(base_offset); - if (!index->mmap_disable) { + if (index->mmap_base != NULL) { uint32_t *pos; pos = PTR_OFFSET(index->mmap_base, offset_pos); @@ -679,7 +679,7 @@ } } - if (index->mmap_disable) { + if (index->mmap_base == NULL) { /* file_cache_write() calls may have moved mmaping */ index->const_mmap_base = file_cache_get_map(index->file_cache, &index->mmap_size); @@ -711,7 +711,7 @@ i_assert(count <= dir->count); i_assert(sync_dir->seen_records_count < count); - if (!ctx->index->mmap_disable) + if (ctx->index->mmap_base != NULL) recs = MAILBOX_LIST_RECORDS_MODIFIABLE(dir); else { /* @UNSAFE: copy the records into a temporary buffer that @@ -749,7 +749,7 @@ i++; } } - if (ctx->index->mmap_disable) { + if (ctx->index->mmap_base == NULL) { uoff_t offset, old_offset; size_t size = sizeof(struct mailbox_list_record) * dir->count; @@ -849,7 +849,7 @@ bool partial; int ret = 0; - if (ctx->index->mmap_disable) { + if (ctx->index->mmap_base == NULL) { ctx->output = o_stream_create_file(ctx->index->fd, default_pool, 0, FALSE); ctx->output_buf = buffer_create_dynamic(default_pool, 4096); @@ -870,7 +870,7 @@ if (!ctx->changed) { /* nothing written */ - } else if (!ctx->index->mmap_disable) { + } else if (ctx->index->mmap_base != NULL) { /* update header */ hdr = ctx->index->mmap_base; if (ret == 0) @@ -900,7 +900,7 @@ ret = -1; } } - if (ctx->index->mmap_disable) { + if (ctx->index->mmap_base == NULL) { o_stream_destroy(&ctx->output); buffer_free(ctx->output_buf); }
--- a/src/lib-index/mailbox-list-index.c Thu Jul 19 04:18:30 2007 +0300 +++ b/src/lib-index/mailbox-list-index.c Thu Jul 19 04:47:25 2007 +0300 @@ -139,12 +139,24 @@ int mailbox_list_index_map(struct mailbox_list_index *index) { const struct mailbox_list_index_header *hdr; + struct stat st; ssize_t ret; mailbox_list_index_unmap(index); if (!index->mmap_disable) { - index->mmap_base = mmap_rw_file(index->fd, &index->mmap_size); + if (fstat(index->fd, &st) < 0) { + mailbox_list_index_set_syscall_error(index, "fstat()"); + return -1; + } + } + + if (!index->mmap_disable && + st.st_size >= MAILBOX_LIST_INDEX_MMAP_MIN_SIZE) { + index->mmap_size = st.st_size; + index->mmap_base = mmap(NULL, index->mmap_size, + PROT_READ | PROT_WRITE, + MAP_SHARED, index->fd, 0); if (index->mmap_base == MAP_FAILED) { index->mmap_base = NULL; mailbox_list_index_set_syscall_error(index, "mmap()");