Maintain the number of dirty pages
authorJuan Quintela <quintela@redhat.com>
Fri, 22 Jun 2012 13:21:07 +0000 (15:21 +0200)
committerJuan Quintela <quintela@redhat.com>
Fri, 29 Jun 2012 11:31:07 +0000 (13:31 +0200)
Calculate the number of dirty pages takes a lot on hosts with lots
of memory.  Just maintain how many pages are dirty.

Signed-off-by: Juan Quintela <quintela@redhat.com>
arch_init.c
cpu-all.h
exec-obsolete.h

index 64b85fd1b1fd1952768d5d45f27ceef18ce9d7fb..5b0f5626a96b093f439cb2af3e958b9b249d5c8a 100644 (file)
@@ -238,20 +238,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)
index 9dc249a1657acb3f1497697d3c2b4539ef4b1ded..82ba1d7cd59d9c8ebc1caad24a3a49489f9d4d03 100644 (file)
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -486,6 +486,7 @@ typedef struct RAMBlock {
 typedef struct RAMList {
     uint8_t *phys_dirty;
     QLIST_HEAD(, RAMBlock) blocks;
+    uint64_t dirty_pages;
 } RAMList;
 extern RAMList ram_list;
 
index f8ffce607af1857e93995d8e9b83c79a70dddd03..c09925610d0ddc6c6bfdc2482e92310e137dbd40 100644 (file)
@@ -74,6 +74,11 @@ static inline int cpu_physical_memory_get_dirty(ram_addr_t start,
 static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr,
                                                       int dirty_flags)
 {
+    if ((dirty_flags & MIGRATION_DIRTY_FLAG) &&
+        !cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
+                                       MIGRATION_DIRTY_FLAG)) {
+        ram_list.dirty_pages++;
+    }
     return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags;
 }
 
@@ -87,6 +92,11 @@ static inline int cpu_physical_memory_clear_dirty_flags(ram_addr_t addr,
 {
     int mask = ~dirty_flags;
 
+    if ((dirty_flags & MIGRATION_DIRTY_FLAG) &&
+        cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE,
+                                      MIGRATION_DIRTY_FLAG)) {
+        ram_list.dirty_pages--;
+    }
     return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask;
 }