diff mbox

[7/7] Maintaing number of dirty pages

Message ID d413cd4bbe763ad7e9b9001dc2df358a4811da31.1337710679.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela May 22, 2012, 6:32 p.m. UTC
Calculate the number of dirty pages takes a lot on hosts with lots
of memory.  Just maintain how many pages are dirty.  Only sync bitmaps
if number is small enough.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c     |   15 +--------------
 cpu-all.h       |    1 +
 exec-obsolete.h |    8 ++++++++
 exec.c          |    2 ++
 4 files changed, 12 insertions(+), 14 deletions(-)

Comments

Orit Wasserman June 14, 2012, 11:42 a.m. UTC | #1
On 05/22/2012 09:32 PM, Juan Quintela wrote:
> Calculate the number of dirty pages takes a lot on hosts with lots
> of memory.  Just maintain how many pages are dirty.  Only sync bitmaps
> if number is small enough.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  arch_init.c     |   15 +--------------
>  cpu-all.h       |    1 +
>  exec-obsolete.h |    8 ++++++++
>  exec.c          |    2 ++
>  4 files changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/arch_init.c b/arch_init.c
> index 2aa77ff..77c3580 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -224,20 +224,7 @@ static uint64_t bytes_transferred;
> 
>  static ram_addr_t ram_save_remaining(void)
>  {
> -    RAMBlock *block;
> -    ram_addr_t count = 0;
> -
> -    QLIST_FOREACH(block, &ram_list.blocks, next) {
> -        ram_addr_t addr;
> -        for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
> -            if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
> -                                        DIRTY_MEMORY_MIGRATION)) {
> -                count++;
> -            }
> -        }
> -    }
> -
> -    return count;
> +    return ram_list.dirty_pages;
>  }
> 
>  uint64_t ram_bytes_remaining(void)
> diff --git a/cpu-all.h b/cpu-all.h
> index 028528f..897210f 100644
> --- a/cpu-all.h
> +++ b/cpu-all.h
> @@ -502,6 +502,7 @@ typedef struct RAMBlock {
>  typedef struct RAMList {
>      uint8_t *phys_dirty;
>      QLIST_HEAD(, RAMBlock) blocks;
> +    uint64_t dirty_pages;
>  } RAMList;
>  extern RAMList ram_list;
> 
> diff --git a/exec-obsolete.h b/exec-obsolete.h
> index 792c831..2e54ac9 100644
> --- a/exec-obsolete.h
> +++ b/exec-obsolete.h
> @@ -75,6 +75,10 @@ static inline int cpu_physical_memory_get_dirty(ram_addr_t start,
> 
>  static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
>  {
> +    if (!cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
> +                                       MIGRATION_DIRTY_FLAG)) {
> +        ram_list.dirty_pages++;
> +    }
>      ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] = 0xff;
>  }
> 
> @@ -112,6 +116,10 @@ static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
>      mask = ~dirty_flags;
>      p = ram_list.phys_dirty + (start >> TARGET_PAGE_BITS);
>      for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
> +        if (cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
> +                                          MIGRATION_DIRTY_FLAG & dirty_flags)) {
> +            ram_list.dirty_pages--;
> +        }
>          *p++ &= mask;
>      }
>  }
> diff --git a/exec.c b/exec.c
> index b6c7675..be4865c 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2687,6 +2687,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
>      memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
>             0xff, size >> TARGET_PAGE_BITS);
> 
> +    ram_list.dirty_pages += size >> TARGET_PAGE_BITS;
> +
>      if (kvm_enabled())
>          kvm_setup_guest_memory(new_block->host, size);
> 
Juan,
Don't we need to update cpu_physical_memory_set_dirty_range ?

Orit
diff mbox

Patch

diff --git a/arch_init.c b/arch_init.c
index 2aa77ff..77c3580 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -224,20 +224,7 @@  static uint64_t bytes_transferred;

 static ram_addr_t ram_save_remaining(void)
 {
-    RAMBlock *block;
-    ram_addr_t count = 0;
-
-    QLIST_FOREACH(block, &ram_list.blocks, next) {
-        ram_addr_t addr;
-        for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
-            if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
-                                        DIRTY_MEMORY_MIGRATION)) {
-                count++;
-            }
-        }
-    }
-
-    return count;
+    return ram_list.dirty_pages;
 }

 uint64_t ram_bytes_remaining(void)
diff --git a/cpu-all.h b/cpu-all.h
index 028528f..897210f 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -502,6 +502,7 @@  typedef struct RAMBlock {
 typedef struct RAMList {
     uint8_t *phys_dirty;
     QLIST_HEAD(, RAMBlock) blocks;
+    uint64_t dirty_pages;
 } RAMList;
 extern RAMList ram_list;

diff --git a/exec-obsolete.h b/exec-obsolete.h
index 792c831..2e54ac9 100644
--- a/exec-obsolete.h
+++ b/exec-obsolete.h
@@ -75,6 +75,10 @@  static inline int cpu_physical_memory_get_dirty(ram_addr_t start,

 static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
 {
+    if (!cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
+                                       MIGRATION_DIRTY_FLAG)) {
+        ram_list.dirty_pages++;
+    }
     ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] = 0xff;
 }

@@ -112,6 +116,10 @@  static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
     mask = ~dirty_flags;
     p = ram_list.phys_dirty + (start >> TARGET_PAGE_BITS);
     for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
+        if (cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
+                                          MIGRATION_DIRTY_FLAG & dirty_flags)) {
+            ram_list.dirty_pages--;
+        }
         *p++ &= mask;
     }
 }
diff --git a/exec.c b/exec.c
index b6c7675..be4865c 100644
--- a/exec.c
+++ b/exec.c
@@ -2687,6 +2687,8 @@  ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
     memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
            0xff, size >> TARGET_PAGE_BITS);

+    ram_list.dirty_pages += size >> TARGET_PAGE_BITS;
+
     if (kvm_enabled())
         kvm_setup_guest_memory(new_block->host, size);