chiark / gitweb /
journal: make JournalFile::chain_cache an OrderedHashmap
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 14 Oct 2014 15:58:13 +0000 (17:58 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 23 Oct 2014 15:38:02 +0000 (17:38 +0200)
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
src/journal/journal-file.h

index 038b437e1ff25642d357c81c5c86cabb02c549f9..d06dbc2f753397efd6408a0d451fd6ab914cc948 100644 (file)
@@ -136,7 +136,7 @@ void journal_file_close(JournalFile *f) {
         if (f->mmap)
                 mmap_cache_unref(f->mmap);
 
         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);
 
 #if defined(HAVE_XZ) || defined(HAVE_LZ4)
         free(f->compress_buffer);
@@ -1366,7 +1366,7 @@ typedef struct ChainCacheItem {
 } ChainCacheItem;
 
 static void chain_cache_put(
 } ChainCacheItem;
 
 static void chain_cache_put(
-                Hashmap *h,
+                OrderedHashmap *h,
                 ChainCacheItem *ci,
                 uint64_t first,
                 uint64_t array,
                 ChainCacheItem *ci,
                 uint64_t first,
                 uint64_t array,
@@ -1380,8 +1380,8 @@ static void chain_cache_put(
                 if (array == first)
                         return;
 
                 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)
                 else {
                         ci = new(ChainCacheItem, 1);
                         if (!ci)
@@ -1390,7 +1390,7 @@ static void chain_cache_put(
 
                 ci->first = first;
 
 
                 ci->first = first;
 
-                if (hashmap_put(h, &ci->first, ci) < 0) {
+                if (ordered_hashmap_put(h, &ci->first, ci) < 0) {
                         free(ci);
                         return;
                 }
                         free(ci);
                         return;
                 }
@@ -1419,7 +1419,7 @@ static int generic_array_get(
         a = first;
 
         /* Try the chain cache first */
         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;
         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;
 
         /* 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
         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;
         }
 
                 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;
         if (!f->chain_cache) {
                 r = -ENOMEM;
                 goto fail;
index fa5b943e46a2f6393ba1fae0ca86449db413d312..211e121d5c6e8997dd6aaddfdb1a3414656f78aa 100644 (file)
@@ -76,7 +76,7 @@ typedef struct JournalFile {
         JournalMetrics metrics;
         MMapCache *mmap;
 
         JournalMetrics metrics;
         MMapCache *mmap;
 
-        Hashmap *chain_cache;
+        OrderedHashmap *chain_cache;
 
 #if defined(HAVE_XZ) || defined(HAVE_LZ4)
         void *compress_buffer;
 
 #if defined(HAVE_XZ) || defined(HAVE_LZ4)
         void *compress_buffer;