qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: huangy81@chinatelecom.cn
Cc: Eduardo Habkost <ehabkost@redhat.com>,
	Juan Quintela <quintela@redhat.com>,
	qemu-devel@nongnu.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Chuan Zheng <zhengchuan@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v3 2/3] memory: introduce DirtyRateDirtyPages and util function
Date: Thu, 15 Jul 2021 16:49:20 -0400	[thread overview]
Message-ID: <YPCfUGk4MdWKi9So@t490s> (raw)
In-Reply-To: <316de737c2fee577cbf75a47dc7537ce38844a63.1626364220.git.huangy81@chinatelecom.cn>

On Thu, Jul 15, 2021 at 11:51:32PM +0800, huangy81@chinatelecom.cn wrote:
> From: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
> 
> introduce DirtyRateDirtyPages and use it to the dirty pages
> along with memory_global_dirty_log_sync.
> introduce cpu_physical_memory_dirtyrate_reset_protect to
> clear dirty bitmap within slot in kvm
> 
> Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
> ---
>  include/exec/ram_addr.h | 19 +++++++++++++++++++
>  migration/dirtyrate.c   |  2 ++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 45c9132..dce0f46 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -26,6 +26,8 @@
>  #include "exec/ramlist.h"
>  #include "exec/ramblock.h"
>  
> +extern uint64_t DirtyRateDirtyPages;
> +
>  /**
>   * clear_bmap_size: calculate clear bitmap size
>   *
> @@ -415,6 +417,17 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>              }
>          }
>      }
> +
> +    if (global_dirty_tracking &&

This check can be dropped.

> +        global_dirty_tracking & GLOBAL_DIRTY_DIRTY_RATE) {
> +        long nr = BITS_TO_LONGS(pages);
> +        for (i = 0; i < nr; i++) {
> +            if (bitmap[i]) {
> +                unsigned long temp = leul_to_cpu(bitmap[i]);
> +                DirtyRateDirtyPages += ctpopl(temp);

IMHO we don't need to loop the bitmap twice; we can still do it in above if
blocks when looping.

Note that this variable (DirtyRateDirtyPages) should either be protected by a
lock or updated using qatomic_add().  I think it's easier we just read/write it
with BQL as it should be required for cpu_physical_memory_set_dirty_lebitmap()
callers.  So looks okay.

> +            }
> +        }
> +    }
>  }
>  #endif /* not _WIN32 */
>  
> @@ -510,5 +523,11 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
>  
>      return num_dirty;
>  }
> +
> +static inline
> +void cpu_physical_memory_dirtyrate_reset_protect(RAMBlock *rb)
> +{
> +    memory_region_clear_dirty_bitmap(rb->mr, 0, rb->used_length);
> +}

The name cpu_physical_memory_dirtyrate_reset_protect() didn't really help
anything.. I'd suggest we drop this helper and call it directly in the next
patch.

>  #endif
>  #endif
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index 3c8c5e2..c465e62 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -28,6 +28,8 @@
>  #include "sysemu/runstate.h"
>  #include "exec/memory.h"
>  
> +uint64_t DirtyRateDirtyPages;

CamelCase is normally used for type definitions in QEMU.  Maybe define it as
"total_dirty_pages"?  Then we never reset it to zero, but only increase it.

Also let's comment above it: it's protected by BQL.  So far it should be enough.

Thanks,

> +
>  typedef struct DirtyPageRecord {
>      uint64_t start_pages;
>      uint64_t end_pages;
> -- 
> 1.8.3.1
> 

-- 
Peter Xu



  reply	other threads:[~2021-07-15 20:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 15:51 [PATCH v3 0/3] support dirtyrate measurement with dirty bitmap huangy81
     [not found] ` <cover.1626364220.git.huangy81@chinatelecom.cn>
2021-07-15 15:51   ` [PATCH v3 1/3] KVM: introduce kvm_get_manual_dirty_log_protect huangy81
2021-07-15 15:51   ` [PATCH v3 2/3] memory: introduce DirtyRateDirtyPages and util function huangy81
2021-07-15 20:49     ` Peter Xu [this message]
2021-07-15 15:51   ` [PATCH v3 3/3] migration/dirtyrate: implement dirty-bitmap dirtyrate calculation huangy81
2021-07-15 20:58     ` Peter Xu
2021-07-15 21:00 ` [PATCH v3 0/3] support dirtyrate measurement with dirty bitmap Peter Xu

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=YPCfUGk4MdWKi9So@t490s \
    --to=peterx@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=huangy81@chinatelecom.cn \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=zhengchuan@huawei.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).