From: Timo Sirainen Date: Mon, 15 Feb 2010 03:38:42 +0000 (+0200) Subject: Memory usage optimizations. X-Git-Tag: 2.0.beta3~70 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6d931bbce16786df431e9ae8201a78a95084316d;p=thirdparty%2Fdovecot%2Fcore.git Memory usage optimizations. --HG-- branch : HEAD --- diff --git a/src/dsync/dsync-worker-local.c b/src/dsync/dsync-worker-local.c index 82a6c308f9..54f27396c7 100644 --- a/src/dsync/dsync-worker-local.c +++ b/src/dsync/dsync-worker-local.c @@ -19,6 +19,7 @@ struct local_dsync_worker_mailbox_iter { struct dsync_worker_mailbox_iter iter; + pool_t ret_pool; struct mailbox_list_iterate_context *list_iter; struct hash_iterate_context *deleted_iter; struct hash_iterate_context *deleted_dir_iter; @@ -389,6 +390,7 @@ local_worker_mailbox_iter_init(struct dsync_worker *_worker) iter = i_new(struct local_dsync_worker_mailbox_iter, 1); iter->iter.worker = _worker; + iter->ret_pool = pool_alloconly_create("local mailbox iter", 1024); iter->list_iter = mailbox_list_iter_init_namespaces(worker->user->namespaces, patterns, list_flags); @@ -532,10 +534,12 @@ local_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *_iter, dsync_box_r->uid_next = status.uidnext; dsync_box_r->highest_modseq = status.highest_modseq; + p_clear(iter->ret_pool); fields = array_get(status.cache_fields, &field_count); - t_array_init(&dsync_box_r->cache_fields, field_count); + p_array_init(&dsync_box_r->cache_fields, iter->ret_pool, field_count); for (i = 0; i < field_count; i++) { - const char *field_name = t_strdup(fields[i]); + const char *field_name = p_strdup(iter->ret_pool, fields[i]); + array_append(&dsync_box_r->cache_fields, &field_name, 1); } @@ -554,6 +558,7 @@ local_worker_mailbox_iter_deinit(struct dsync_worker_mailbox_iter *_iter) if (mailbox_list_iter_deinit(&iter->list_iter) < 0) ret = -1; + pool_unref(&iter->ret_pool); i_free(iter); return ret; } diff --git a/src/dsync/dsync-worker.c b/src/dsync/dsync-worker.c index 1ecf2f0e35..bf4d7f665d 100644 --- a/src/dsync/dsync-worker.c +++ b/src/dsync/dsync-worker.c @@ -50,7 +50,12 @@ dsync_worker_mailbox_iter_init(struct dsync_worker *worker) int dsync_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *iter, struct dsync_mailbox *dsync_box_r) { - return iter->worker->v.mailbox_iter_next(iter, dsync_box_r); + int ret; + + T_BEGIN { + ret = iter->worker->v.mailbox_iter_next(iter, dsync_box_r); + } T_END; + return ret; } int dsync_worker_mailbox_iter_deinit(struct dsync_worker_mailbox_iter **_iter) @@ -127,23 +132,26 @@ void dsync_worker_create_mailbox(struct dsync_worker *worker, i_assert(dsync_box->uid_validity != 0 || dsync_mailbox_is_noselect(dsync_box)); - if (!worker->readonly) + if (!worker->readonly) T_BEGIN { worker->v.create_mailbox(worker, dsync_box); + } T_END; } void dsync_worker_delete_mailbox(struct dsync_worker *worker, const struct dsync_mailbox *dsync_box) { - if (!worker->readonly) + if (!worker->readonly) T_BEGIN { worker->v.delete_mailbox(worker, dsync_box); + } T_END; } void dsync_worker_rename_mailbox(struct dsync_worker *worker, const mailbox_guid_t *mailbox, const struct dsync_mailbox *dsync_box) { - if (!worker->readonly) + if (!worker->readonly) T_BEGIN { worker->v.rename_mailbox(worker, mailbox, dsync_box); + } T_END; } void dsync_worker_update_mailbox(struct dsync_worker *worker, @@ -157,8 +165,10 @@ void dsync_worker_update_mailbox(struct dsync_worker *worker, void dsync_worker_select_mailbox(struct dsync_worker *worker, const struct dsync_mailbox *box) { - worker->v.select_mailbox(worker, &box->mailbox_guid, - &box->cache_fields); + T_BEGIN { + worker->v.select_mailbox(worker, &box->mailbox_guid, + &box->cache_fields); + } T_END; } void dsync_worker_msg_update_metadata(struct dsync_worker *worker, @@ -188,8 +198,10 @@ void dsync_worker_msg_copy(struct dsync_worker *worker, void *context) { if (!worker->failed && !worker->readonly) { - worker->v.msg_copy(worker, src_mailbox, src_uid, dest_msg, - callback, context); + T_BEGIN { + worker->v.msg_copy(worker, src_mailbox, src_uid, + dest_msg, callback, context); + } T_END; } else { callback(FALSE, context); } @@ -200,8 +212,9 @@ void dsync_worker_msg_save(struct dsync_worker *worker, const struct dsync_msg_static_data *data) { if (!worker->readonly) { - if (!worker->failed) + if (!worker->failed) T_BEGIN { worker->v.msg_save(worker, msg, data); + } T_END; } else { const unsigned char *d; size_t size; @@ -222,10 +235,11 @@ void dsync_worker_msg_get(struct dsync_worker *worker, { i_assert(uid != 0); - if (!worker->failed) - worker->v.msg_get(worker, mailbox, uid, callback, context); - else + if (worker->failed) callback(DSYNC_MSG_GET_RESULT_FAILED, NULL, context); + else T_BEGIN { + worker->v.msg_get(worker, mailbox, uid, callback, context); + } T_END; } void dsync_worker_finish(struct dsync_worker *worker, diff --git a/src/lib-storage/index/index-transaction.c b/src/lib-storage/index/index-transaction.c index d9501fd3a3..34795ec688 100644 --- a/src/lib-storage/index/index-transaction.c +++ b/src/lib-storage/index/index-transaction.c @@ -116,7 +116,8 @@ int index_transaction_commit(struct mailbox_transaction_context *_t, int ret; memset(changes_r, 0, sizeof(*changes_r)); - changes_r->pool = pool_alloconly_create("transaction changes", 1024); + changes_r->pool = pool_alloconly_create(MEMPOOL_GROWING + "transaction changes", 512); p_array_init(&changes_r->saved_uids, changes_r->pool, 32); _t->changes = changes_r; diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index bda49dac65..f30b319315 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -1126,11 +1126,15 @@ int mailbox_transaction_commit_get_changes( struct mail_transaction_commit_changes *changes_r) { struct mailbox_transaction_context *t = *_t; + int ret; t->box->transaction_count--; *_t = NULL; - return t->box->v.transaction_commit(t, changes_r); + T_BEGIN { + ret = t->box->v.transaction_commit(t, changes_r); + } T_END; + return ret; } void mailbox_transaction_rollback(struct mailbox_transaction_context **_t) diff --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index a54f78b644..d8c43c9c6d 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -464,19 +464,29 @@ void mailbox_list_get_dir_permissions(struct mailbox_list *list, bool mailbox_list_is_valid_pattern(struct mailbox_list *list, const char *pattern) { - return list->v.is_valid_pattern(list, pattern); + bool ret; + + T_BEGIN { + ret = list->v.is_valid_pattern(list, pattern); + } T_END; + return ret; } bool mailbox_list_is_valid_existing_name(struct mailbox_list *list, const char *name) { + bool ret; + if (*name == '\0' && *list->ns->prefix != '\0') { /* an ugly way to get to mailbox root (e.g. Maildir/ when it's not the INBOX) */ return TRUE; } - return list->v.is_valid_existing_name(list, name); + T_BEGIN { + ret = list->v.is_valid_existing_name(list, name); + } T_END; + return ret; } bool mailbox_list_is_valid_create_name(struct mailbox_list *list, @@ -619,7 +629,7 @@ mailbox_list_iter_init_namespaces(struct mail_namespace *namespaces, i_assert(namespaces != NULL); - pool = pool_alloconly_create("mailbox list namespaces", 512); + pool = pool_alloconly_create("mailbox list namespaces", 1024); ctx = p_new(pool, struct ns_list_iterate_context, 1); ctx->pool = pool; ctx->ctx.flags = flags;