/* 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)
}
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)