Skip to contentSkip to conversation

Revert "memory: syncronize kvm bitmap using bitmaps operations"

PATCH In review Alexey Kardashevskiy 3 participants 6 messages Jan 29, 2014 – Jan 30, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "memory: syncronize kvm bitmap using bitmaps operations"

This reverts commit ae2810c4bb3b383176e8e1b33931b16c01483aab.

This reverts the optimization introduced by the original patch as it breaks dirty page tracking on systems where getpagesize() != TARGET_PAGE_SIZE such as POWERPC64.

The cpu_physical_memory_set_dirty_lebitmap() is called from the kvm_physical_sync_dirty_bitmap() with the bitmap returned by the KVM's KVM_GET_DIRTY_LOG ioctl where 1 bit is per the system page. However QEMU's ram_list.dirty_memory maps are allocated to store 1 bit per TARGET_PAGE_SIZE which is hardcoded to 4K.

Since 64K system page size is quite popular configuration on PPC64, the original patch breaks migration.

---
 include/exec/ram_addr.h | 54 +++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
include/exec/ram_addr.h +18 -36
index 33c8acc..c6736ed 100644
@@ -83,47 +83,29 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
                                                           ram_addr_t start,
                                                           ram_addr_t pages)
 {
-    unsigned long i, j;
+    unsigned int i, j;
     unsigned long page_number, c;
     hwaddr addr;
     ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
-    /* start address is aligned at the start of a word? */
-    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {
-        long k;
-        long nr = BITS_TO_LONGS(pages);
-
-        for (k = 0; k < nr; k++) {
-            if (bitmap[k]) {
-                unsigned long temp = leul_to_cpu(bitmap[k]);
-
-                ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION][page + k] |= temp;
-                ram_list.dirty_memory[DIRTY_MEMORY_VGA][page + k] |= temp;
-                ram_list.dirty_memory[DIRTY_MEMORY_CODE][page + k] |= temp;
-            }
-        }
-        xen_modified_memory(start, pages);
-    } else {
-        /*
-         * bitmap-traveling is faster than memory-traveling (for addr...)
-         * especially when most of the memory is not dirty.
-         */
-        for (i = 0; i < len; i++) {
-            if (bitmap[i] != 0) {
-                c = leul_to_cpu(bitmap[i]);
-                do {
-                    j = ffsl(c) - 1;
-                    c &= ~(1ul << j);
-                    page_number = (i * HOST_LONG_BITS + j) * hpratio;
-                    addr = page_number * TARGET_PAGE_SIZE;
-                    ram_addr = start + addr;
-                    cpu_physical_memory_set_dirty_range(ram_addr,
-                                       TARGET_PAGE_SIZE * hpratio);
-                } while (c != 0);
-            }
+    /*
+     * bitmap-traveling is faster than memory-traveling (for addr...)
+     * especially when most of the memory is not dirty.
+     */
+    for (i = 0; i < len; i++) {
+        if (bitmap[i] != 0) {
+            c = leul_to_cpu(bitmap[i]);
+            do {
+                j = ffsl(c) - 1;
+                c &= ~(1ul << j);
+                page_number = (i * HOST_LONG_BITS + j) * hpratio;
+                addr = page_number * TARGET_PAGE_SIZE;
+                ram_addr = start + addr;
+                cpu_physical_memory_set_dirty_range(ram_addr,
+                                                    TARGET_PAGE_SIZE * hpratio);
+            } while (c != 0);
         }
     }
 }
Signature · 1 line
1.8.4.rc4
#1 lore raw

Il 29/01/2014 06:50, Alexey Kardashevskiy ha scritto:

Quoted 18 lines

Since 64K system page size is quite popular configuration on PPC64, the original patch breaks migration.

---
 include/exec/ram_addr.h | 54 +++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
include/exec/ram_addr.h +1 -1
index 33c8acc..c6736ed 100644
@@ -83,47 +83,29 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
                                                           ram_addr_t start,
                                                           ram_addr_t pages)
 {
-    unsigned long i, j;
+    unsigned int i, j;

include/exec/ram_addr.h static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, · line 95

Quoted 10 lines
include/exec/ram_addr.h +1 -4
     unsigned long page_number, c;
     hwaddr addr;
     ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
-    /* start address is aligned at the start of a word? */
-    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {

Why not just add " && hpratio == 1" here?

Paolo

#2 lore raw
Quoted 29 lines · Paolo Bonzini

Il 29/01/2014 06:50, Alexey Kardashevskiy ha scritto:

Quoted 28 lines

Since 64K system page size is quite popular configuration on PPC64, the original patch breaks migration.

---
 include/exec/ram_addr.h | 54
+++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
include/exec/ram_addr.h +2 -3
index 33c8acc..c6736ed 100644
@@ -83,47 +83,29 @@ static inline void
 cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
                                                           ram_addr_t start,
                                                           ram_addr_t pages)
 {
-    unsigned long i, j;
+    unsigned int i, j;
     unsigned long page_number, c;
     hwaddr addr;
     ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
Quoted 4 lines

include/exec/ram_addr.h static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, · line 95

Quoted 2 lines
include/exec/ram_addr.h +0 -2
-    /* start address is aligned at the start of a word? */
-    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {

Why not just add " && hpratio == 1" here?

Or fix dirty map to make it 1 bit per system page size (may be the fix is coming, who knows, but I am just not ready to do this now). Or do tricks with bits and support hpratio!=1. I could not choose and decided to revert it for now :)

Do we really earn a lot here?

Signature · 1 line
Alexey
#3 lore raw

Il 29/01/2014 09:12, Alexey Kardashevskiy ha scritto:

Quoted 35 lines · Paolo Bonzini
Quoted 29 lines

Il 29/01/2014 06:50, Alexey Kardashevskiy ha scritto:

Quoted 28 lines

Since 64K system page size is quite popular configuration on PPC64, the original patch breaks migration.

---
 include/exec/ram_addr.h | 54
+++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
include/exec/ram_addr.h +2 -3
index 33c8acc..c6736ed 100644
@@ -83,47 +83,29 @@ static inline void
 cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
                                                           ram_addr_t start,
                                                           ram_addr_t pages)
 {
-    unsigned long i, j;
+    unsigned int i, j;
     unsigned long page_number, c;
     hwaddr addr;
     ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
Quoted 4 lines

include/exec/ram_addr.h static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, · line 95

Quoted 2 lines
include/exec/ram_addr.h +0 -2
-    /* start address is aligned at the start of a word? */
-    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {

Why not just add " && hpratio == 1" here?

Quoted 4 lines

Or fix dirty map to make it 1 bit per system page size (may be the fix is coming, who knows, but I am just not ready to do this now). Or do tricks with bits and support hpratio!=1. I could not choose and decided to revert it for now :)

Can you post the patch that adds " && hpratio == 1"?

Quoted 1 line

Do we really earn a lot here?

Yes, because this is the only part of migration that runs with the iothread lock taken. Without Juan's patches you can see large guests hiccups that last a few seconds.

Paolo

#4 lore raw
Quoted 38 lines · Paolo Bonzini

Il 29/01/2014 09:12, Alexey Kardashevskiy ha scritto:

Quoted 37 lines · Paolo Bonzini
Quoted 35 lines

Il 29/01/2014 06:50, Alexey Kardashevskiy ha scritto:

Quoted 22 lines

Since 64K system page size is quite popular configuration on PPC64, the original patch breaks migration.

---
 include/exec/ram_addr.h | 54
+++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
include/exec/ram_addr.h +1 -1
index 33c8acc..c6736ed 100644
@@ -83,47 +83,29 @@ static inline void
 cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
                                                           ram_addr_t
 start,
                                                           ram_addr_t
 pages)
 {
-    unsigned long i, j;
+    unsigned int i, j;

include/exec/ram_addr.h static inline void · line 98

Quoted 10 lines
include/exec/ram_addr.h +1 -4
     unsigned long page_number, c;
     hwaddr addr;
     ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
-    /* start address is aligned at the start of a word? */
-    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {

Why not just add " && hpratio == 1" here?

Quoted 6 lines
Quoted 4 lines

Or fix dirty map to make it 1 bit per system page size (may be the fix is coming, who knows, but I am just not ready to do this now). Or do tricks with bits and support hpratio!=1. I could not choose and decided to revert it for now :)

Can you post the patch that adds " && hpratio == 1"?

Ok, done.

But I still wonder why there are still TARGET_PAGE_SIZE vs. getpagesize() and why bitmap formats are different between KVM and QEMU - is it just an old stuff which has to be fixes some day or something more?

Quoted 5 lines
Quoted 1 line

Do we really earn a lot here?

Yes, because this is the only part of migration that runs with the iothread lock taken. Without Juan's patches you can see large guests hiccups that last a few seconds.

Signature · 1 line
Alexey
#5 lore raw
In reply to Alexey Kardashevskiy
Quoted 36 lines · Alexey Kardashevskiy
Quoted 29 lines · Paolo Bonzini

Il 29/01/2014 06:50, Alexey Kardashevskiy ha scritto:

Quoted 28 lines

Since 64K system page size is quite popular configuration on PPC64, the original patch breaks migration.

---
 include/exec/ram_addr.h | 54
+++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
include/exec/ram_addr.h +2 -3
index 33c8acc..c6736ed 100644
@@ -83,47 +83,29 @@ static inline void
 cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
                                                           ram_addr_t start,
                                                           ram_addr_t pages)
 {
-    unsigned long i, j;
+    unsigned int i, j;
     unsigned long page_number, c;
     hwaddr addr;
     ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
Quoted 4 lines

include/exec/ram_addr.h static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, · line 95

Quoted 2 lines
include/exec/ram_addr.h +0 -2
-    /* start address is aligned at the start of a word? */
-    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {

Why not just add " && hpratio == 1" here?

Quoted 4 lines

Or fix dirty map to make it 1 bit per system page size (may be the fix is coming, who knows, but I am just not ready to do this now). Or do tricks with bits and support hpratio!=1. I could not choose and decided to revert it for now :)

Please, could you test Paolo suggestion?

Quoted 1 line

Do we really earn a lot here?

With 512GB guests, we used to have stalls of 10 seconds, now they are lost on the noise.

Thanks for the testing.

Later, Juan.