Skip to contentSkip to conversation

migration/postcopy: cleanup function postcopy_send_discard_bm_ram

PATCH In review Wei Yang 2 participants 9 messages Jun 27, 2019 – Aug 7, 2019

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

cover migration/postcopy: cleanup function postcopy_send_discard_bm_ram

Some cleanup of function postcopy_send_discard_bm_ram:

* use a more restrict check for discard page
* break the loop when no more page to discard
* it is for sure discard_length is not 0

No functional change.

Wei Yang (3):
migration/postcopy: the valid condition is one less then end migration/postcopy: break the loop when there is no more page to
discard
migration/postcopy: discard_length must not be 0

 migration/ram.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 1/3 migration/postcopy: the valid condition is one less then end

If one equals end, it means we have gone through the whole bitmap.

Use a more restrict check to skip a unnecessary condition.

---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index 908517fc2b..b78169e811 100644
@@ -2777,7 +2777,7 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
     for (current = 0; current < end; ) {
         unsigned long one = find_next_bit(unsentmap, end, current);
 
-        if (one <= end) {
+        if (one < end) {
             unsigned long zero = find_next_zero_bit(unsentmap, end, one + 1);
             unsigned long discard_length;
 
Signature · 1 line
2.19.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] migration/postcopy: the valid condition is one less then end

Quoted 5 lines · * Wei Yang ([email protected]) wrote:

If one equals end, it means we have gone through the whole bitmap.

Use a more restrict check to skip a unnecessary condition.

Yes, I don't think that'll break, since I think the find_next_zero_bit will also return end, and then discard_length would be 0; still I think it's a correct fix.

Quoted 20 lines
---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index 908517fc2b..b78169e811 100644
@@ -2777,7 +2777,7 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
     for (current = 0; current < end; ) {
         unsigned long one = find_next_bit(unsentmap, end, current);
 
-        if (one <= end) {
+        if (one < end) {
             unsigned long zero = find_next_zero_bit(unsentmap, end, one + 1);
             unsigned long discard_length;
 
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] migration/postcopy: the valid condition is one less then end

Quoted 10 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Wei Yang ([email protected]) wrote:

If one equals end, it means we have gone through the whole bitmap.

Use a more restrict check to skip a unnecessary condition.

Yes, I don't think that'll break, since I think the find_next_zero_bit will also return end, and then discard_length would be 0; still I think it's a correct fix.

Yep, you are exactly right.

Quoted 25 lines
Quoted 20 lines
---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index 908517fc2b..b78169e811 100644
@@ -2777,7 +2777,7 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
     for (current = 0; current < end; ) {
         unsigned long one = find_next_bit(unsentmap, end, current);
 
-        if (one <= end) {
+        if (one < end) {
             unsigned long zero = find_next_zero_bit(unsentmap, end, one + 1);
             unsigned long discard_length;
 
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
author
#4 lore raw

PATCH 2/3 migration/postcopy: break the loop when there is no more page to discard

In reply to Wei Yang

When one is equal or bigger then end, it means there is no page to discard. Just break the loop in this case instead of processing it.

No functional change, just refactor it a little.

---
 migration/ram.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
migration/ram.c +13 -13
index b78169e811..b41b58ee54 100644
@@ -2776,23 +2776,23 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
 
     for (current = 0; current < end; ) {
         unsigned long one = find_next_bit(unsentmap, end, current);
+        unsigned long zero, discard_length;
 
-        if (one < end) {
-            unsigned long zero = find_next_zero_bit(unsentmap, end, one + 1);
-            unsigned long discard_length;
+        if (one >= end) {
+            break;
+        }
 
-            if (zero >= end) {
-                discard_length = end - one;
-            } else {
-                discard_length = zero - one;
-            }
-            if (discard_length) {
-                postcopy_discard_send_range(ms, pds, one, discard_length);
-            }
-            current = one + discard_length;
+        zero = find_next_zero_bit(unsentmap, end, one + 1);
+
+        if (zero >= end) {
+            discard_length = end - one;
         } else {
-            current = one;
+            discard_length = zero - one;
+        }
+        if (discard_length) {
+            postcopy_discard_send_range(ms, pds, one, discard_length);
         }
+        current = one + discard_length;
     }
 
     return 0;
Signature · 1 line
2.19.1
Reviewed-by on v1 2/3
#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] migration/postcopy: break the loop when there is no more page to discard

Quoted 6 lines · * Wei Yang ([email protected]) wrote:

When one is equal or bigger then end, it means there is no page to discard. Just break the loop in this case instead of processing it.

No functional change, just refactor it a little.

Quoted 48 lines
---
 migration/ram.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
migration/ram.c +13 -13
index b78169e811..b41b58ee54 100644
@@ -2776,23 +2776,23 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
 
     for (current = 0; current < end; ) {
         unsigned long one = find_next_bit(unsentmap, end, current);
+        unsigned long zero, discard_length;
 
-        if (one < end) {
-            unsigned long zero = find_next_zero_bit(unsentmap, end, one + 1);
-            unsigned long discard_length;
+        if (one >= end) {
+            break;
+        }
 
-            if (zero >= end) {
-                discard_length = end - one;
-            } else {
-                discard_length = zero - one;
-            }
-            if (discard_length) {
-                postcopy_discard_send_range(ms, pds, one, discard_length);
-            }
-            current = one + discard_length;
+        zero = find_next_zero_bit(unsentmap, end, one + 1);
+
+        if (zero >= end) {
+            discard_length = end - one;
         } else {
-            current = one;
+            discard_length = zero - one;
+        }
+        if (discard_length) {
+            postcopy_discard_send_range(ms, pds, one, discard_length);
         }
+        current = one + discard_length;
     }
 
     return 0;
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#6 lore raw

PATCH 3/3 migration/postcopy: discard_length must not be 0

In reply to Wei Yang

Since we break the loop when there is no more page to discard, we are sure the following process would find some page to discard.

It is not necessary to check it again.

---
 migration/ram.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
migration/ram.c +1 -3
index b41b58ee54..246efe6939 100644
@@ -2789,9 +2789,7 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
         } else {
             discard_length = zero - one;
         }
-        if (discard_length) {
-            postcopy_discard_send_range(ms, pds, one, discard_length);
-        }
+        postcopy_discard_send_range(ms, pds, one, discard_length);
         current = one + discard_length;
     }
 
Signature · 1 line
2.19.1
Reviewed-by on v1 3/3
#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] migration/postcopy: discard_length must not be 0

Quoted 6 lines · * Wei Yang ([email protected]) wrote:

Since we break the loop when there is no more page to discard, we are sure the following process would find some page to discard.

It is not necessary to check it again.

Quoted 22 lines
---
 migration/ram.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
migration/ram.c +1 -3
index b41b58ee54..246efe6939 100644
@@ -2789,9 +2789,7 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
         } else {
             discard_length = zero - one;
         }
-        if (discard_length) {
-            postcopy_discard_send_range(ms, pds, one, discard_length);
-        }
+        postcopy_discard_send_range(ms, pds, one, discard_length);
         current = one + discard_length;
     }
 
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#8 lore raw
In reply to Wei Yang
Quoted 8 lines · * Wei Yang ([email protected]) wrote:

Some cleanup of function postcopy_send_discard_bm_ram:

* use a more restrict check for discard page
* break the loop when no more page to discard
* it is for sure discard_length is not 0

No functional change.

Queued

Quoted 6 lines

Wei Yang (3):
migration/postcopy: the valid condition is one less then end migration/postcopy: break the loop when there is no more page to
discard
migration/postcopy: discard_length must not be 0

Quoted 7 lines
 migration/ram.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK