qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: OHMURA Kei <ohmura.kei@lab.ntt.co.jp>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, avi@redhat.com
Subject: [Qemu-devel] Re: [PATCH] qemu-kvm: Speed up of the dirty-bitmap-traveling
Date: Fri, 05 Feb 2010 13:04:40 +0100	[thread overview]
Message-ID: <4B6C0958.50704@siemens.com> (raw)
In-Reply-To: <4B6BF06D.1090909@lab.ntt.co.jp>

OHMURA Kei wrote:
> dirty-bitmap-traveling is carried out by byte size in qemu-kvm.c.
> But We think that dirty-bitmap-traveling by long size is faster than by byte
> size especially when most of memory is not dirty.

Sounds logical - do you have numbers on the improvement?

Would be great if you could provide a version for upstream as well
because it will likely replace this qemu-kvm code on day.

Jan

> 
> Signed-off-by: OHMURA Kei <ohmura.kei@lab.ntt.co.jp>
> ---
>  qemu-kvm.c |   49 ++++++++++++++++++++++++++++++++++++++++++-------
>  1 files changed, 42 insertions(+), 7 deletions(-)
> 
> diff --git a/qemu-kvm.c b/qemu-kvm.c
> index a305907..5459cdd 100644
> --- a/qemu-kvm.c
> +++ b/qemu-kvm.c
> @@ -2433,22 +2433,21 @@ int kvm_physical_memory_set_dirty_tracking(int enable)
>  }
>  
>  /* get kvm's dirty pages bitmap and update qemu's */
> -static int kvm_get_dirty_pages_log_range(unsigned long start_addr,
> -                                         unsigned char *bitmap,
> -                                         unsigned long offset,
> -                                         unsigned long mem_size)
> +static void kvm_get_dirty_pages_log_range_by_byte(unsigned int start,
> +                                                  unsigned int end,
> +                                                  unsigned char *bitmap,
> +                                                  unsigned long offset)
>  {
>      unsigned int i, j, n = 0;
>      unsigned char c;
>      unsigned long page_number, addr, addr1;
>      ram_addr_t ram_addr;
> -    unsigned int len = ((mem_size / TARGET_PAGE_SIZE) + 7) / 8;
>  
>      /* 
>       * bitmap-traveling is faster than memory-traveling (for addr...) 
>       * especially when most of the memory is not dirty.
>       */
> -    for (i = 0; i < len; i++) {
> +    for (i = start; i < end; i++) {
>          c = bitmap[i];
>          while (c > 0) {
>              j = ffsl(c) - 1;
> @@ -2461,13 +2460,49 @@ static int kvm_get_dirty_pages_log_range(unsigned long start_addr,
>              n++;
>          }
>      }
> +}
> +
> +static int kvm_get_dirty_pages_log_range_by_long(unsigned long start_addr,
> +                                                 unsigned char *bitmap,
> +                                                 unsigned long offset,
> +                                                 unsigned long mem_size)
> +{
> +    unsigned int i;
> +    unsigned int len;
> +    unsigned long *bitmap_ul = (unsigned long *)bitmap;
> +
> +    /* bitmap-traveling by long size is faster than by byte size
> +     * especially when most of memory is not dirty.
> +     * bitmap should be long-size aligned for traveling by long.
> +     */
> +    if (((unsigned long)bitmap & (TARGET_LONG_SIZE - 1)) == 0) {
> +        len = ((mem_size / TARGET_PAGE_SIZE) + TARGET_LONG_BITS - 1) /
> +            TARGET_LONG_BITS;
> +        for (i = 0; i < len; i++)
> +            if (bitmap_ul[i] != 0)
> +                kvm_get_dirty_pages_log_range_by_byte(i * TARGET_LONG_SIZE, 
> +                    (i + 1) * TARGET_LONG_SIZE, bitmap, offset);
> +        /* 
> +         * We will check the remaining dirty-bitmap, 
> +         * when the mem_size is not a multiple of TARGET_LONG_SIZE. 
> +         */ 
> +        if ((mem_size & (TARGET_LONG_SIZE - 1)) != 0) {
> +            len = ((mem_size / TARGET_PAGE_SIZE) + 7) / 8;
> +            kvm_get_dirty_pages_log_range_by_byte(i * TARGET_LONG_SIZE, 
> +                len, bitmap, offset);
> +        }
> +    } else { /* slow path: traveling by byte. */
> +        len = ((mem_size / TARGET_PAGE_SIZE) + 7) / 8;
> +        kvm_get_dirty_pages_log_range_by_byte(0, len, bitmap, offset);
> +    }
> +
>      return 0;
>  }
>  
>  static int kvm_get_dirty_bitmap_cb(unsigned long start, unsigned long len,
>                                     void *bitmap, void *opaque)
>  {
> -    return kvm_get_dirty_pages_log_range(start, bitmap, start, len);
> +    return kvm_get_dirty_pages_log_range_by_long(start, bitmap, start, len);
>  }
>  
>  /* 
> -- 1.6.3.3 

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

  reply	other threads:[~2010-02-05 12:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-05 10:18 [Qemu-devel] [PATCH] qemu-kvm: Speed up of the dirty-bitmap-traveling OHMURA Kei
2010-02-05 12:04 ` Jan Kiszka [this message]
2010-02-08  6:14   ` [Qemu-devel] " OHMURA Kei
2010-02-08 11:23     ` OHMURA Kei
2010-02-08 11:44       ` Jan Kiszka
2010-02-09  9:55         ` OHMURA Kei
2010-02-08 12:40 ` Avi Kivity
2010-02-09  9:54   ` OHMURA Kei
2010-02-09 10:26     ` Avi Kivity
2010-02-10  9:55       ` OHMURA Kei
2010-02-10 10:24         ` Avi Kivity

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=4B6C0958.50704@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=ohmura.kei@lab.ntt.co.jp \
    --cc=qemu-devel@nongnu.org \
    /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).