Skip to contentSkip to conversation

migration: Count new_dirty instead of real_dirty

PATCH Superseded Keqian Zhu 2 participants 4 messages Jun 1, 2020 – Jun 16, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Keqian Zhu

author
#0 lore raw

PATCH 1/1 migration: Count new_dirty instead of real_dirty

DIRTY_LOG_INITIALLY_ALL_SET feature is on the queue. This fixs the dirty rate calculation for this feature. After introducing this feature, real_dirty_pages is equal to total memory size at begining. This causing wrong dirty rate and false positive throttling.

BTW, real dirty rate is not suitable and not very accurate.

1. For not suitable: We mainly concern on the relationship between dirty rate and network bandwidth. Net increasement of dirty pages makes more sense.
2. For not very accurate: With manual dirty log clear, some dirty pages will be cleared during each peroid, our "real dirty rate" is less than real "real dirty rate".

---
 include/exec/ram_addr.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
include/exec/ram_addr.h +2 -3
index 5e59a3d8d7..af9677e291 100644
@@ -443,7 +443,7 @@ static inline
 uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                                                ram_addr_t start,
                                                ram_addr_t length,
-                                               uint64_t *real_dirty_pages)
+                                               uint64_t *accu_dirty_pages)
 {
     ram_addr_t addr;
     unsigned long word = BIT_WORD((start + rb->offset) >> TARGET_PAGE_BITS);
@@ -469,7 +469,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
             if (src[idx][offset]) {
                 unsigned long bits = atomic_xchg(&src[idx][offset], 0);
                 unsigned long new_dirty;
-                *real_dirty_pages += ctpopl(bits);
                 new_dirty = ~dest[k];
                 dest[k] |= bits;
                 new_dirty &= bits;
@@ -502,7 +501,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                         start + addr + offset,
                         TARGET_PAGE_SIZE,
                         DIRTY_MEMORY_MIGRATION)) {
-                *real_dirty_pages += 1;
                 long k = (start + addr) >> TARGET_PAGE_BITS;
                 if (!test_and_set_bit(k, dest)) {
                     num_dirty++;
@@ -511,6 +509,7 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
         }
     }
 
+    *accu_dirty_pages += num_dirty;
     return num_dirty;
 }
 #endif
Signature · 1 line
2.19.1
author
#1 lore raw

Hi Paolo and Jian Zhou,

Do you have any suggestion on this patch?

Thanks,
Keqian

Quoted 57 lines · Keqian Zhu

DIRTY_LOG_INITIALLY_ALL_SET feature is on the queue. This fixs the dirty rate calculation for this feature. After introducing this feature, real_dirty_pages is equal to total memory size at begining. This causing wrong dirty rate and false positive throttling.

BTW, real dirty rate is not suitable and not very accurate.

1. For not suitable: We mainly concern on the relationship between dirty rate and network bandwidth. Net increasement of dirty pages makes more sense.
2. For not very accurate: With manual dirty log clear, some dirty pages will be cleared during each peroid, our "real dirty rate" is less than real "real dirty rate".

---
 include/exec/ram_addr.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
include/exec/ram_addr.h +2 -3
index 5e59a3d8d7..af9677e291 100644
@@ -443,7 +443,7 @@ static inline
 uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                                                ram_addr_t start,
                                                ram_addr_t length,
-                                               uint64_t *real_dirty_pages)
+                                               uint64_t *accu_dirty_pages)
 {
     ram_addr_t addr;
     unsigned long word = BIT_WORD((start + rb->offset) >> TARGET_PAGE_BITS);
@@ -469,7 +469,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
             if (src[idx][offset]) {
                 unsigned long bits = atomic_xchg(&src[idx][offset], 0);
                 unsigned long new_dirty;
-                *real_dirty_pages += ctpopl(bits);
                 new_dirty = ~dest[k];
                 dest[k] |= bits;
                 new_dirty &= bits;
@@ -502,7 +501,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                         start + addr + offset,
                         TARGET_PAGE_SIZE,
                         DIRTY_MEMORY_MIGRATION)) {
-                *real_dirty_pages += 1;
                 long k = (start + addr) >> TARGET_PAGE_BITS;
                 if (!test_and_set_bit(k, dest)) {
                     num_dirty++;
@@ -511,6 +509,7 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
         }
     }
 
+    *accu_dirty_pages += num_dirty;
     return num_dirty;
 }
 #endif
#2 lore raw

Hi Keqian,

Quoted 9 lines

-----Original Message-----
From: zhukeqian
Sent: Monday, June 15, 2020 11:19 AM
To: [email protected]; [email protected]; Paolo Bonzini <[email protected]>; Zhoujian (jay) <[email protected]>
Cc: Juan Quintela <[email protected]>; Chao Fan <[email protected]>; Wanghaibin (D) <[email protected]>
Subject: Re: [PATCH] migration: Count new_dirty instead of real_dirty

Quoted 9 lines

Hi Paolo and Jian Zhou,

Do you have any suggestion on this patch?

Thanks,
Keqian

Quoted 1 line · Keqian Zhu

DIRTY_LOG_INITIALLY_ALL_SET feature is on the queue. This fixs the

s/fixs/fixes

Quoted 3 lines
Quoted 3 lines

dirty rate calculation for this feature. After introducing this feature, real_dirty_pages is equal to total memory size at begining. This causing wrong dirty rate and false positive throttling.

I think it should be tested whether DIRTY_LOG_INITIALLY_ALL_SET is enabled in ram_init_bitmaps(maybe?) in order to be compatible with the old path.

Thanks,
Jay Zhou

Quoted 61 lines
Quoted 23 lines

BTW, real dirty rate is not suitable and not very accurate.

1. For not suitable: We mainly concern on the relationship between dirty rate and network bandwidth. Net increasement of dirty pages makes more sense.
2. For not very accurate: With manual dirty log clear, some dirty pages will be cleared during each peroid, our "real dirty rate" is less than real "real dirty rate".

---
 include/exec/ram_addr.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
include/exec/ram_addr.h index renamed from include/exec/ram_addr.h +0 -0

5e59a3d8d7..af9677e291 100644

include/exec/ram_addr.h static inline · line 446

Quoted 4 lines
include/exec/ram_addr.h +0 -1
@@ -443,7 +443,7 @@ static inline
 uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                                                ram_addr_t start,
                                                ram_addr_t length,
-                                               uint64_t

*real_dirty_pages)

Quoted 6 lines
include/exec/ram_addr.h +2 -0
+                                               uint64_t
+ *accu_dirty_pages)
 {
     ram_addr_t addr;
     unsigned long word = BIT_WORD((start + rb->offset) >>

TARGET_PAGE_BITS); @@ -469,7 +469,6 @@ uint64_t

cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,

include/exec/ram_addr.h uint64_t

Quoted 8 lines
             if (src[idx][offset]) {
                 unsigned long bits = atomic_xchg(&src[idx][offset], 0);
                 unsigned long new_dirty;
include/exec/ram_addr.h +0 -1
-                *real_dirty_pages += ctpopl(bits);
                 new_dirty = ~dest[k];
                 dest[k] |= bits;
                 new_dirty &= bits;
@@ -502,7 +501,6 @@ uint64_t

cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,

include/exec/ram_addr.h uint64_t

Quoted 8 lines
include/exec/ram_addr.h +0 -1
                         start + addr + offset,
                         TARGET_PAGE_SIZE,
                         DIRTY_MEMORY_MIGRATION)) {
-                *real_dirty_pages += 1;
                 long k = (start + addr) >> TARGET_PAGE_BITS;
                 if (!test_and_set_bit(k, dest)) {
                     num_dirty++;
@@ -511,6 +509,7 @@ uint64_t

cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,

Quoted 8 lines
include/exec/ram_addr.h +1 -0
         }
     }
 
+    *accu_dirty_pages += num_dirty;
     return num_dirty;
 }
 #endif
author
#3 lore raw

Hi Jay Zhou,

Quoted 15 lines · Zhoujian (jay)

Hi Keqian,

Quoted 13 lines

-----Original Message-----
From: zhukeqian
Sent: Monday, June 15, 2020 11:19 AM
To: [email protected]; [email protected]; Paolo Bonzini <[email protected]>; Zhoujian (jay) <[email protected]>
Cc: Juan Quintela <[email protected]>; Chao Fan <[email protected]>; Wanghaibin (D) <[email protected]>
Subject: Re: [PATCH] migration: Count new_dirty instead of real_dirty

Hi Paolo and Jian Zhou,

Do you have any suggestion on this patch?

Quoted 7 lines
Quoted 5 lines

Thanks,
Keqian

Quoted 1 line · Keqian Zhu

DIRTY_LOG_INITIALLY_ALL_SET feature is on the queue. This fixs the

s/fixs/fixes

Thanks.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

dirty rate calculation for this feature. After introducing this feature, real_dirty_pages is equal to total memory size at begining. This causing wrong dirty rate and false positive throttling.

I think it should be tested whether DIRTY_LOG_INITIALLY_ALL_SET is enabled in ram_init_bitmaps(maybe?) in order to be compatible with the old path.

Yeah, you are right ;-)

But after I tested old path yesterday, I found that the num_dirty_pages_period becomes total ram size after log sync in ram_init_bitmaps. The reason is that bitmap of ramblock is initialized to be all set, so old path counts them as dirty by mistake.

This bug causes false positive throttling at the end of first ram save iteration, even without our DIRTY_LOG_INITIALLY_ALL_SET feature.

Quoted 14 lines

Thanks,
Jay Zhou

Quoted 9 lines
Quoted 9 lines

BTW, real dirty rate is not suitable and not very accurate.

1. For not suitable: We mainly concern on the relationship between dirty rate and network bandwidth. Net increasement of dirty pages makes more sense.
2. For not very accurate: With manual dirty log clear, some dirty pages will be cleared during each peroid, our "real dirty rate" is less than real "real dirty rate".

I should correct these commit messages for reason above :-)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[...]

Thanks,
Keqian