diff options
author | Orit Wasserman <owasserm@redhat.com> | 2013-02-25 19:12:02 +0200 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2013-03-11 13:32:03 +0100 |
commit | a0ee2031dbf5f0183412d4b20a30cbfd404616a8 (patch) | |
tree | 06b7364a8abbd528ef7847c60e49ef4f5f3ad068 /page_cache.c | |
parent | 0db65d624e0211a43c011579d6607a50d8f06082 (diff) |
Fix cache_resize to keep old entry age
Instead of using cache_insert do the update itself
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'page_cache.c')
-rw-r--r-- | page_cache.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/page_cache.c b/page_cache.c index 748957bc42..e5717d53c9 100644 --- a/page_cache.c +++ b/page_cache.c @@ -192,18 +192,17 @@ int64_t cache_resize(PageCache *cache, int64_t new_num_pages) if (old_it->it_addr != -1) { /* check for collision, if there is, keep MRU page */ new_it = cache_get_by_addr(new_cache, old_it->it_addr); - if (new_it->it_data) { + if (new_it->it_data && new_it->it_age >= old_it->it_age) { /* keep the MRU page */ - if (new_it->it_age >= old_it->it_age) { - g_free(old_it->it_data); - } else { - g_free(new_it->it_data); - new_it->it_data = old_it->it_data; - new_it->it_age = old_it->it_age; - new_it->it_addr = old_it->it_addr; - } + g_free(old_it->it_data); } else { - cache_insert(new_cache, old_it->it_addr, old_it->it_data); + if (!new_it->it_data) { + new_cache->num_items++; + } + g_free(new_it->it_data); + new_it->it_data = old_it->it_data; + new_it->it_age = old_it->it_age; + new_it->it_addr = old_it->it_addr; } } } |