summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2013-01-14 17:42:12 +0100
committerCarlos Martín Nieto <cmn@elego.de>2013-01-14 18:10:56 +0100
commit9c62aaab40248fb1b87d403ef5eab917be327b9e (patch)
tree105ab0672a2ba412e460680f7ecf04e70c56975b
parented6648ba469c30b074e83bc102298ba0b183e231 (diff)
downloadlibgit2-9c62aaab40248fb1b87d403ef5eab917be327b9e.tar.gz
pack: evict all of the pages at once
Somewhat surprisingly, this can increase the speed considerably, as we don't bother trying to decide what to evict, and the most used entries are quickly back into the cache.
-rw-r--r--src/pack.c35
1 files changed, 4 insertions, 31 deletions
diff --git a/src/pack.c b/src/pack.c
index d4ae29072..810a82129 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -116,49 +116,22 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
return entry;
}
-#define BASE_DELTA_EVICT_NR 8
-
/* Run with the cache lock held */
static void free_lowest_entry(git_pack_cache *cache)
{
git_pack_cache_entry *entry;
khiter_t k;
- git_pack_cache_entry *lru[BASE_DELTA_EVICT_NR] = {NULL};
- khiter_t lru_k[BASE_DELTA_EVICT_NR];
- int i;
-
for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) {
if (!kh_exist(cache->entries, k))
continue;
entry = kh_value(cache->entries, k);
- for (i = 0; i < BASE_DELTA_EVICT_NR; i++) {
- if (lru[i] == NULL ||
- (entry->last_usage < lru[i]->last_usage &&
- entry->refcount.val == 0)) {
- int j;
-
- for (j = 0; j < i; j++) {
- lru[j] = lru[j+1];
- lru_k[j] = lru_k[j+1];
- }
-
- lru[i] = entry;
- lru_k[i] = k;
-
- /* jump out and try with the next entry */
- break;
- }
- }
- }
-
- for (i = 0; i < BASE_DELTA_EVICT_NR; i++) {
- if (lru[i]) {
- cache->memory_used -= lru[i]->raw.len;
- kh_del(off, cache->entries, lru_k[i]);
- free_cache_object(lru[i]);
+ if (entry && entry->refcount.val == 0) {
+ cache->memory_used -= entry->raw.len;
+ kh_del(off, cache->entries, k);
+ free_cache_object(entry);
}
}
}