Mercurial > dovecot > core-2.2
changeset 2341:b3c0ed666757 HEAD
Limit how much a single transaction can reserve space
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Jul 2004 20:06:25 +0300 |
parents | 29cc953f1822 |
children | fa529dd77176 |
files | src/lib-index/mail-cache-private.h src/lib-index/mail-cache-transaction.c |
diffstat | 2 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache-private.h Tue Jul 20 20:06:08 2004 +0300 +++ b/src/lib-index/mail-cache-private.h Tue Jul 20 20:06:25 2004 +0300 @@ -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)
--- a/src/lib-index/mail-cache-transaction.c Tue Jul 20 20:06:08 2004 +0300 +++ b/src/lib-index/mail-cache-transaction.c Tue Jul 20 20:06:25 2004 +0300 @@ -179,10 +179,15 @@ } 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)