# HG changeset patch # User Timo Sirainen # Date 1194290128 -7200 # Node ID c7742d109a672bb5ec252e726323291ceada2133 # Parent 3123e03dc3d8a1a004ac5fc318da32383a8b04e8 mmap_disable=yes: When following cache field headers, don't invalidate the same part of the cache file over and over again and cause re-reads. diff -r 3123e03dc3d8 -r c7742d109a67 src/lib-index/mail-cache-fields.c --- a/src/lib-index/mail-cache-fields.c Mon Nov 05 20:34:15 2007 +0200 +++ b/src/lib-index/mail-cache-fields.c Mon Nov 05 21:15:28 2007 +0200 @@ -5,6 +5,7 @@ #include "hash.h" #include "file-cache.h" #include "write-full.h" +#include "mmap-util.h" #include "mail-cache-private.h" #include @@ -167,8 +168,11 @@ static int mail_cache_header_fields_get_offset(struct mail_cache *cache, uint32_t *offset_r) { + const size_t page_size = mmap_get_page_size(); const struct mail_cache_header_fields *field_hdr; + const unsigned int size = sizeof(*field_hdr) + CACHE_HDR_PREFETCH; uint32_t offset, next_offset; + uoff_t invalid_start = 0, invalid_end = 0; if (MAIL_CACHE_IS_UNUSABLE(cache)) { *offset_r = 0; @@ -187,14 +191,24 @@ } offset = next_offset; - if (cache->file_cache != NULL) { - /* we can't trust that the cached data is valid */ - file_cache_invalidate(cache->file_cache, offset, - sizeof(*field_hdr) + - CACHE_HDR_PREFETCH); + if (offset < invalid_start && cache->file_cache != NULL) { + uoff_t new_start = offset; + + new_start &= ~(page_size-1); + file_cache_invalidate(cache->file_cache, + new_start, invalid_start); + invalid_start = new_start; } - if (mail_cache_map(cache, offset, - sizeof(*field_hdr) + CACHE_HDR_PREFETCH) < 0) + if (offset + size > invalid_end && cache->file_cache != NULL) { + uoff_t new_size = invalid_end - invalid_start + size; + + new_size = (new_size + page_size-1) & ~(page_size - 1); + file_cache_invalidate(cache->file_cache, + invalid_end, new_size); + invalid_end = offset + new_size; + } + + if (mail_cache_map(cache, offset, size) < 0) return -1; field_hdr = CONST_PTR_OFFSET(cache->data, offset);