From e4fb5bfcdff32d337d054cce36e00e1cdfaae9f8 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 3 May 2004 17:22:24 +0300 Subject: [PATCH] INDEX_KEYWORDS_BYTE_COUNT was counted wrong so index files were larger than they needed to be. Added sizeof(keywords_mask_t) to compat_data. Added limit to growing index file exponentially. --HG-- branch : HEAD --- src/lib-index/mail-index-private.h | 18 ++++-------------- src/lib-index/mail-index-sync-update.c | 3 ++- src/lib-index/mail-index.c | 4 +++- src/lib-index/mail-index.h | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/lib-index/mail-index-private.h b/src/lib-index/mail-index-private.h index fcc9d8a667..3fb7c3f580 100644 --- a/src/lib-index/mail-index-private.h +++ b/src/lib-index/mail-index-private.h @@ -6,23 +6,13 @@ struct mail_transaction_header; -/* number of records to always keep allocated in index file, - either used or unused */ -#define INDEX_MIN_RECORDS_COUNT 64 -/* when empty space in index file gets full, grow the file n% larger */ -#define INDEX_GROW_PERCENTAGE 10 -/* ftruncate() the index file when only n% of it is in use */ -#define INDEX_TRUNCATE_PERCENTAGE 30 -/* don't truncate whole file anyway, keep n% of the empty space */ -#define INDEX_TRUNCATE_KEEP_PERCENTAGE 10 -/* Compress the file when deleted space reaches n% of total size */ -#define INDEX_COMPRESS_PERCENTAGE 50 -/* Compress the file when searching deleted records tree has to go this deep */ -#define INDEX_COMPRESS_DEPTH 10 +/* Index file is grown exponentially when we're adding less than this many + records. */ +#define MAIL_INDEX_MAX_POWER_GROW (1024*1024 / sizeof(struct mail_index_record)) /* How many times to retry opening index files if read/fstat returns ESTALE. This happens with NFS when the file has been deleted (ie. index file was rewritten by another computer than us). */ -#define INDEX_ESTALE_RETRY_COUNT 10 +#define MAIL_INDEX_ESTALE_RETRY_COUNT 10 #define MAIL_INDEX_MAP_IS_IN_MEMORY(map) \ ((map)->buffer != NULL) diff --git a/src/lib-index/mail-index-sync-update.c b/src/lib-index/mail-index-sync-update.c index 1acccd243e..9f460acceb 100644 --- a/src/lib-index/mail-index-sync-update.c +++ b/src/lib-index/mail-index-sync-update.c @@ -116,7 +116,8 @@ static int mail_index_grow(struct mail_index *index, unsigned int count) /* when we grow fast, do it exponentially */ if (count < index->last_grow_count) count = index->last_grow_count; - count = nearest_power(count); + if (count < MAIL_INDEX_MAX_POWER_GROW) + count = nearest_power(count); index->last_grow_count = count; size = map->hdr->header_size + diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index ace197d38e..e012063042 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -49,6 +49,7 @@ static int mail_index_check_header(struct mail_index *index, #endif compat_data[1] = sizeof(uoff_t); compat_data[2] = sizeof(time_t); + compat_data[3] = sizeof(keywords_mask_t); if (hdr->major_version != MAIL_INDEX_MAJOR_VERSION) { /* major version change - handle silently(?) */ @@ -233,7 +234,7 @@ static int mail_index_read_map_with_retry(struct mail_index *index, { int i, ret; - for (i = 0; i < INDEX_ESTALE_RETRY_COUNT; i++) { + for (i = 0; i < MAIL_INDEX_ESTALE_RETRY_COUNT; i++) { ret = mail_index_read_map(index, map); if (ret != 0) return ret; @@ -359,6 +360,7 @@ void mail_index_header_init(struct mail_index_header *hdr) #endif hdr->compat_data[1] = sizeof(uoff_t); hdr->compat_data[2] = sizeof(time_t); + hdr->compat_data[3] = sizeof(keywords_mask_t); hdr->indexid = now; diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index 24c9aee8d7..e941835392 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -10,7 +10,7 @@ /* Number of keywords in mail_index_record. */ #define INDEX_KEYWORDS_COUNT (3*8) -#define INDEX_KEYWORDS_BYTE_COUNT ((INDEX_KEYWORDS_COUNT*7)/8) +#define INDEX_KEYWORDS_BYTE_COUNT ((INDEX_KEYWORDS_COUNT+CHAR_BIT-1) / CHAR_BIT) enum mail_index_open_flags { /* Create index if it doesn't exist */ -- 2.47.3