Skip to contentSkip to conversation

migration: Simplify handling of zero pages

PATCH In review Juan Quintela 3 participants 6 messages Oct 19, 2023 – Oct 23, 2023

lore
Share & tools
lore
#0 lore raw

cover migration: Simplify handling of zero pages

Hi

It has been more than a decade since we optimized pages filled of anything except zeros. Remove the reception support.

Review please.

Later, Juan.

Juan Quintela (2):
migration: Receiving a zero page non zero is an error
migration: Rename ram_handle_compressed() to ram_handle_zero()

 migration/ram.h  |  2 +-
 migration/ram.c  | 25 ++++++++++++++++---------
 migration/rdma.c |  8 ++++++--
 3 files changed, 23 insertions(+), 12 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/2 migration: Receiving a zero page non zero is an error

We don't allow non zero compressed pages since:

commit 3edcd7e6ebae3ef0ac178eed5f4225803159562d

Author: Peter Lieven <[email protected]>
Date:   Tue Mar 26 10:58:35 2013 +0100

migration: search for zero instead of dup pages

RDMA case is a bit more complicated, but they don't handle it since:

commit a1febc4950f2c6232c002f401d7cd409f6fa6a88

Author: Richard Henderson <[email protected]>
Date:   Mon Aug 29 11:46:14 2016 -0700

cutils: Export only buffer_is_zero

---
 migration/ram.c  | 15 +++++++++++----
 migration/rdma.c |  6 +++++-
 2 files changed, 16 insertions(+), 5 deletions(-)
migration/ram.c +11 -4
index c844151ee9..0dd8bbb339 100644
@@ -3730,16 +3730,18 @@ int ram_load_postcopy(QEMUFile *f, int channel)
         switch (flags & ~RAM_SAVE_FLAG_CONTINUE) {
         case RAM_SAVE_FLAG_ZERO:
             ch = qemu_get_byte(f);
+            if (ch != 0) {
+                error_report("Found a zero page with value %d", ch);
+                ret = -EINVAL;
+                break;
+            }
             /*
              * Can skip to set page_buffer when
              * this is a zero page and (block->page_size == TARGET_PAGE_SIZE).
              */
-            if (ch || !matches_target_page_size) {
+            if (!matches_target_page_size) {
                 memset(page_buffer, ch, TARGET_PAGE_SIZE);
             }
-            if (ch) {
-                tmp_page->all_zero = false;
-            }
             break;
 
         case RAM_SAVE_FLAG_PAGE:
@@ -4044,6 +4046,11 @@ static int ram_load_precopy(QEMUFile *f)
 
         case RAM_SAVE_FLAG_ZERO:
             ch = qemu_get_byte(f);
+            if (ch != 0) {
+                error_report("Found a zero page with value %d", ch);
+                ret = -EINVAL;
+                break;
+            }
             ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
             break;
 
migration/rdma.c +5 -1
index 2a1852ec7f..2d963fd147 100644
@@ -3592,7 +3592,11 @@ int rdma_registration_handle(QEMUFile *f)
 
             host_addr = block->local_host_addr +
                             (comp->offset - block->offset);
-
+            if (comp->value) {
+                error_report("rdma: Zero page with non-zero (%d) value",
+                             comp->value);
+                goto err;
+            }
             ram_handle_compressed(host_addr, comp->value, comp->length);
             break;
 
Signature · 1 line
2.41.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] migration: Receiving a zero page non zero is an error

Quoted 10 lines · Juan Quintela

We don't allow non zero compressed pages since:

commit 3edcd7e6ebae3ef0ac178eed5f4225803159562d

Author: Peter Lieven <[email protected]>
Date:   Tue Mar 26 10:58:35 2013 +0100

migration: search for zero instead of dup pages

RDMA case is a bit more complicated, but they don't handle it since:

Quoted 7 lines

commit a1febc4950f2c6232c002f401d7cd409f6fa6a88

Author: Richard Henderson <[email protected]>
Date:   Mon Aug 29 11:46:14 2016 -0700

cutils: Export only buffer_is_zero

#3 lore raw

PATCH 2/2 migration: Rename ram_handle_compressed() to ram_handle_zero()

In reply to Juan Quintela

Now that we know it only handles zero, we can remove the ch parameter.

---
 migration/ram.h  |  2 +-
 migration/ram.c  | 10 +++++-----
 migration/rdma.c |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
migration/ram.h +1 -1
index 145c915ca7..3f724b2f02 100644
@@ -60,7 +60,7 @@ int ram_discard_range(const char *block_name, uint64_t start, size_t length);
 int ram_postcopy_incoming_init(MigrationIncomingState *mis);
 int ram_load_postcopy(QEMUFile *f, int channel);
 
-void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
+void ram_handle_zero(void *host, uint64_t size);
 
 void ram_transferred_add(uint64_t bytes);
 void ram_release_page(const char *rbname, uint64_t offset);
migration/ram.c +5 -5
index 0dd8bbb339..132662818b 100644
@@ -3461,7 +3461,7 @@ static inline void *colo_cache_from_block_offset(RAMBlock *block,
 }
 
 /**
- * ram_handle_compressed: handle the zero page case
+ * ram_handle_zero: handle the zero page case
  *
  * If a page (or a whole RDMA chunk) has been
  * determined to be zero, then zap it.
@@ -3470,10 +3470,10 @@ static inline void *colo_cache_from_block_offset(RAMBlock *block,
  * @ch: what the page is filled from.  We only support zero
  * @size: size of the zero page
  */
-void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
+void ram_handle_zero(void *host, uint64_t size)
 {
-    if (ch != 0 || !buffer_is_zero(host, size)) {
-        memset(host, ch, size);
+    if (!buffer_is_zero(host, size)) {
+        memset(host, 0, size);
     }
 }
 
@@ -4051,7 +4051,7 @@ static int ram_load_precopy(QEMUFile *f)
                 ret = -EINVAL;
                 break;
             }
-            ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
+            ram_handle_zero(host, TARGET_PAGE_SIZE);
             break;
 
         case RAM_SAVE_FLAG_PAGE:
migration/rdma.c +1 -1
index 2d963fd147..e3493e3b3e 100644
@@ -3597,7 +3597,7 @@ int rdma_registration_handle(QEMUFile *f)
                              comp->value);
                 goto err;
             }
-            ram_handle_compressed(host_addr, comp->value, comp->length);
+            ram_handle_zero(host_addr, comp->length);
             break;
 
         case RDMA_CONTROL_REGISTER_FINISHED:
Signature · 1 line
2.41.0