]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Memory usage optimizations.
authorTimo Sirainen <tss@iki.fi>
Mon, 15 Feb 2010 03:38:42 +0000 (05:38 +0200)
committerTimo Sirainen <tss@iki.fi>
Mon, 15 Feb 2010 03:38:42 +0000 (05:38 +0200)
--HG--
branch : HEAD

src/dsync/dsync-worker-local.c
src/dsync/dsync-worker.c
src/lib-storage/index/index-transaction.c
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list.c

index 82a6c308f9b4d8be087b33dbfc92b01e919c4c28..54f27396c716cdb94e8a235754bf2818e3f9bd71 100644 (file)
@@ -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;
 }
index 1ecf2f0e352f4d82e847849c72c000831ace8217..bf4d7f665d1965e69ae7da5f21b97c74f768cb95 100644 (file)
@@ -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,
index d9501fd3a310d49b4163d860b01e9244c16cffba..34795ec6885c34413ea08118da39e983d7826704 100644 (file)
@@ -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;
 
index bda49dac65827b5a39fc3933eef1ca14cba02d55..f30b319315ffda0a18347a63bbbe95c1b7bab711 100644 (file)
@@ -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)
index a54f78b644f6e185c30b34a4b3b1e8fc6cbf72ee..d8c43c9c6d7dabe599fe01868e1d622d89369915 100644 (file)
@@ -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;