qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alberto Garcia <berto@igalia.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] block: Give always priority to unused entries in the qcow2 L2 cache
Date: Thu, 5 Feb 2015 14:59:34 +0100	[thread overview]
Message-ID: <20150205135934.GA18629@igalia.com> (raw)
In-Reply-To: <54D374AE.2090500@redhat.com>

On Thu, Feb 05, 2015 at 08:48:30AM -0500, Max Reitz wrote:

> >-        c->entries[i].cache_hits /= 2;
> >+        if (c->entries[i].cache_hits > 1) {
> >+            c->entries[i].cache_hits /= 2;
> >+        }
> >      }
> >      if (min_index == -1) {
> 
> Hm, I can't see where the code is actually giving priority to unused
> entries. qcow2_cache_find_entry_to_replace() is the only place which
> selects the entry to be used

Yes, and it looks for the one with the lowest cache hit count. That is
the only criteria:

        if (c->entries[i].cache_hits < min_count) {
            min_index = i;
            min_count = c->entries[i].cache_hits;
        }

If there are several with the same hit count then the first one is
chosen.

Since dividing the hit count by two everytime there's a cache miss can
make it go down to zero, an existing entry with cache_hits == 0 will
always be chosen before any empty one located afterwards in the array.

By never allowing the hit count to go down to zero, we make sure that
all unused entries are chosen first before a valid one is discarded.

Berto

  reply	other threads:[~2015-02-05 13:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150205135934.GA18629@igalia.com \
    --to=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).