Patchwork [10/41] ram: Introduce migration_bitmap_test_and_reset_dirty()

login
register
mail settings
Submitter Juan Quintela
Date Sept. 21, 2012, 8:47 a.m.
Message ID <1348217255-22441-11-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/185638/
State New
Headers show

Comments

Juan Quintela - Sept. 21, 2012, 8:47 a.m.
It just test if the dirty bit is set, and clears it.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
Orit Wasserman - Sept. 25, 2012, 9:35 a.m.
On 09/21/2012 11:47 AM, Juan Quintela wrote:
> It just test if the dirty bit is set, and clears it.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  arch_init.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/arch_init.c b/arch_init.c
> index b2dcc24..acc057f 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -332,6 +332,19 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
>  static RAMBlock *last_block;
>  static ram_addr_t last_offset;
> 
> +static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr,
> +                                                         ram_addr_t offset)
> +{
> +    bool ret = memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
> +                                       DIRTY_MEMORY_MIGRATION);
> +
> +    if (ret) {
> +        memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
> +                                  DIRTY_MEMORY_MIGRATION);
> +    }
> +    return ret;
> +}
> +
>  static inline void migration_bitmap_set_dirty(MemoryRegion *mr, int length)
>  {
>      ram_addr_t addr;
> @@ -365,14 +378,10 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
> 
>      do {
>          mr = block->mr;
> -        if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
> -                                    DIRTY_MEMORY_MIGRATION)) {
> +        if (migration_bitmap_test_and_reset_dirty(mr, offset)) {
>              uint8_t *p;
>              int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
> 
> -            memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
> -                                      DIRTY_MEMORY_MIGRATION);
> -
>              p = memory_region_get_ram_ptr(mr) + offset;
> 
>              if (is_dup_page(p)) {
> 

Reviewed-by: Orit Wasserman <owasserm@redhat.com>

Patch

diff --git a/arch_init.c b/arch_init.c
index b2dcc24..acc057f 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -332,6 +332,19 @@  static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
 static RAMBlock *last_block;
 static ram_addr_t last_offset;

+static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr,
+                                                         ram_addr_t offset)
+{
+    bool ret = memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
+                                       DIRTY_MEMORY_MIGRATION);
+
+    if (ret) {
+        memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
+                                  DIRTY_MEMORY_MIGRATION);
+    }
+    return ret;
+}
+
 static inline void migration_bitmap_set_dirty(MemoryRegion *mr, int length)
 {
     ram_addr_t addr;
@@ -365,14 +378,10 @@  static int ram_save_block(QEMUFile *f, bool last_stage)

     do {
         mr = block->mr;
-        if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
-                                    DIRTY_MEMORY_MIGRATION)) {
+        if (migration_bitmap_test_and_reset_dirty(mr, offset)) {
             uint8_t *p;
             int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;

-            memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
-                                      DIRTY_MEMORY_MIGRATION);
-
             p = memory_region_get_ram_ptr(mr) + offset;

             if (is_dup_page(p)) {