From: Timo Sirainen Date: Tue, 20 Jul 2004 17:06:25 +0000 (+0300) Subject: Limit how much a single transaction can reserve space X-Git-Tag: 1.1.alpha1~3765 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a51697f82fbd45a511710479e99efd42dc18453;p=thirdparty%2Fdovecot%2Fcore.git Limit how much a single transaction can reserve space --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-cache-private.h b/src/lib-index/mail-cache-private.h index 0009ef6abf..38cfc781b3 100644 --- a/src/lib-index/mail-cache-private.h +++ b/src/lib-index/mail-cache-private.h @@ -25,6 +25,9 @@ /* When more space is needed, grow the file n% larger than the previous size */ #define MAIL_CACHE_GROW_PERCENTAGE 10 +/* When allocating space for transactions, don't use blocks larger than this. */ +#define MAIL_CACHE_MAX_RESERVED_BLOCK_SIZE (1024*512) + #define MAIL_CACHE_LOCK_TIMEOUT 120 #define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 60 #define MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT (5*60) diff --git a/src/lib-index/mail-cache-transaction.c b/src/lib-index/mail-cache-transaction.c index 0144c9d5c1..493c567033 100644 --- a/src/lib-index/mail-cache-transaction.c +++ b/src/lib-index/mail-cache-transaction.c @@ -179,10 +179,15 @@ mail_cache_transaction_reserve_more(struct mail_cache_transaction_ctx *ctx, } if (!commit) { - size = (size + ctx->last_grow_size) * 2; - if ((uoff_t)hdr->used_file_size + size > (uint32_t)-1) - size = (uint32_t)-1; - ctx->last_grow_size = size; + /* allocate some more space than we need */ + size_t new_size = (size + ctx->last_grow_size) * 2; + if ((uoff_t)hdr->used_file_size + new_size > (uint32_t)-1) + new_size = (uint32_t)-1; + if (new_size > MAIL_CACHE_MAX_RESERVED_BLOCK_SIZE) { + new_size = size > MAIL_CACHE_MAX_RESERVED_BLOCK_SIZE ? + size : MAIL_CACHE_MAX_RESERVED_BLOCK_SIZE; + } + ctx->last_grow_size = new_size; } if (mail_cache_grow_file(ctx->cache, size) < 0)