]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Limit how much a single transaction can reserve space
authorTimo Sirainen <tss@iki.fi>
Tue, 20 Jul 2004 17:06:25 +0000 (20:06 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 20 Jul 2004 17:06:25 +0000 (20:06 +0300)
--HG--
branch : HEAD

src/lib-index/mail-cache-private.h
src/lib-index/mail-cache-transaction.c

index 0009ef6abf7b1877c8caeac48608c508034379db..38cfc781b31d6b3206e2cfe61221c782cf9b3e10 100644 (file)
@@ -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)
index 0144c9d5c173167f709cc093f10fd0baa23f23de..493c567033003d6ec5e7363ae657906e8a11c6c1 100644 (file)
@@ -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)