From 4743015db6ad394bd43efadb0651e3906b4efc25 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Tue, 14 Oct 2014 17:58:13 +0200 Subject: [PATCH] journal: make JournalFile::chain_cache an OrderedHashmap The order of entries may matter here. Oldest entries are evicted first when the cache is full. (Though I don't see anything to rejuvenate entries on cache hits.) --- src/journal/journal-file.c | 16 ++++++++-------- src/journal/journal-file.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 038b437e1..d06dbc2f7 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -136,7 +136,7 @@ void journal_file_close(JournalFile *f) { if (f->mmap) mmap_cache_unref(f->mmap); - hashmap_free_free(f->chain_cache); + ordered_hashmap_free_free(f->chain_cache); #if defined(HAVE_XZ) || defined(HAVE_LZ4) free(f->compress_buffer); @@ -1366,7 +1366,7 @@ typedef struct ChainCacheItem { } ChainCacheItem; static void chain_cache_put( - Hashmap *h, + OrderedHashmap *h, ChainCacheItem *ci, uint64_t first, uint64_t array, @@ -1380,8 +1380,8 @@ static void chain_cache_put( if (array == first) return; - if (hashmap_size(h) >= CHAIN_CACHE_MAX) - ci = hashmap_steal_first(h); + if (ordered_hashmap_size(h) >= CHAIN_CACHE_MAX) + ci = ordered_hashmap_steal_first(h); else { ci = new(ChainCacheItem, 1); if (!ci) @@ -1390,7 +1390,7 @@ static void chain_cache_put( ci->first = first; - if (hashmap_put(h, &ci->first, ci) < 0) { + if (ordered_hashmap_put(h, &ci->first, ci) < 0) { free(ci); return; } @@ -1419,7 +1419,7 @@ static int generic_array_get( a = first; /* Try the chain cache first */ - ci = hashmap_get(f->chain_cache, &first); + ci = ordered_hashmap_get(f->chain_cache, &first); if (ci && i > ci->total) { a = ci->array; i -= ci->total; @@ -1522,7 +1522,7 @@ static int generic_array_bisect( /* Start with the first array in the chain */ a = first; - ci = hashmap_get(f->chain_cache, &first); + ci = ordered_hashmap_get(f->chain_cache, &first); if (ci && n > ci->total) { /* Ah, we have iterated this bisection array chain * previously! Let's see if we can skip ahead in the @@ -2498,7 +2498,7 @@ int journal_file_open( goto fail; } - f->chain_cache = hashmap_new(&uint64_hash_ops); + f->chain_cache = ordered_hashmap_new(&uint64_hash_ops); if (!f->chain_cache) { r = -ENOMEM; goto fail; diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index fa5b943e4..211e121d5 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -76,7 +76,7 @@ typedef struct JournalFile { JournalMetrics metrics; MMapCache *mmap; - Hashmap *chain_cache; + OrderedHashmap *chain_cache; #if defined(HAVE_XZ) || defined(HAVE_LZ4) void *compress_buffer; -- 2.30.2