qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block: Give always priority to unused entries in the qcow2 L2 cache
@ 2015-02-05 12:55 Alberto Garcia
  2015-02-05 13:48 ` Max Reitz
  2015-02-06 14:09 ` Kevin Wolf
  0 siblings, 2 replies; 10+ messages in thread
From: Alberto Garcia @ 2015-02-05 12:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Alberto Garcia, Stefan Hajnoczi

The current algorithm to replace entries from the L2 cache gives
priority to newer hits by dividing the hit count of all existing
entries by two everytime there is a cache miss.

However, if there are several cache misses the hit count of the
existing entries can easily go down to 0. This will result in those
entries being replaced even when there are others that have never been
used.

This problem is more noticeable with larger disk images and cache
sizes, since the chances of having several misses before the cache is
full are higher.

If we make sure that the hit count can never go down to 0 again,
unused entries will always have priority.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/qcow2-cache.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 904f6b1..b115549 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -253,7 +253,9 @@ static int qcow2_cache_find_entry_to_replace(Qcow2Cache *c)
 
         /* Give newer hits priority */
         /* TODO Check how to optimize the replacement strategy */
-        c->entries[i].cache_hits /= 2;
+        if (c->entries[i].cache_hits > 1) {
+            c->entries[i].cache_hits /= 2;
+        }
     }
 
     if (min_index == -1) {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-02-06 14:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-05 12:55 [Qemu-devel] [PATCH] block: Give always priority to unused entries in the qcow2 L2 cache Alberto Garcia
2015-02-05 13:48 ` Max Reitz
2015-02-05 13:59   ` Alberto Garcia
2015-02-05 14:03     ` Max Reitz
2015-02-05 14:17     ` Kevin Wolf
2015-02-05 14:42       ` Alberto Garcia
2015-02-06  9:44       ` Alberto Garcia
2015-02-06 11:18         ` Kevin Wolf
2015-02-06 13:46           ` Alberto Garcia
2015-02-06 14:09 ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).