qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Alberto Garcia <berto@igalia.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] block: Give always priority to unused entries in the qcow2 L2 cache
Date: Thu, 05 Feb 2015 08:48:30 -0500	[thread overview]
Message-ID: <54D374AE.2090500@redhat.com> (raw)
In-Reply-To: <1423140931-11823-1-git-send-email-berto@igalia.com>

On 2015-02-05 at 07:55, Alberto Garcia wrote:
> 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) {

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, and it does not check entries[i].offset 
which it should in order to determine whether there are unused entries.

Furthermore, I think we should prioritize clean entries over dirty ones; 
but I guess that's what the TODO comment is hinting at...

Max

  reply	other threads:[~2015-02-05 13:49 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 [this message]
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

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=54D374AE.2090500@redhat.com \
    --to=mreitz@redhat.com \
    --cc=berto@igalia.com \
    --cc=kwolf@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).