dovecot: mmap_disable=yes: When following cache field headers, d...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Nov 5 21:15:33 EET 2007
details: http://hg.dovecot.org/dovecot/rev/c7742d109a67
changeset: 6694:c7742d109a67
user: Timo Sirainen <tss at iki.fi>
date: Mon Nov 05 21:15:28 2007 +0200
description:
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.
diffstat:
1 file changed, 22 insertions(+), 8 deletions(-)
src/lib-index/mail-cache-fields.c | 30 ++++++++++++++++++++++--------
diffs (56 lines):
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 <stddef.h>
@@ -167,8 +168,11 @@ static int mail_cache_header_fields_get_
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 @@ static int mail_cache_header_fields_get_
}
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 (mail_cache_map(cache, offset,
- sizeof(*field_hdr) + CACHE_HDR_PREFETCH) < 0)
+ 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 (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);
More information about the dovecot-cvs
mailing list