diff mbox

[PATCHv3,5/9] migration: search for zero instead of dup pages

Message ID 1363881457-14814-6-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven March 21, 2013, 3:57 p.m. UTC
virtually all dup pages are zero pages. remove
the special is_dup_page() function and use the
optimized buffer_find_nonzero_offset() function
instead.

here buffer_find_nonzero_offset() is used directly
to avoid the unnecssary additional checks in
buffer_is_zero().

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 arch_init.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

Comments

Eric Blake March 21, 2013, 7:24 p.m. UTC | #1
On 03/21/2013 09:57 AM, Peter Lieven wrote:
> virtually all dup pages are zero pages. remove
> the special is_dup_page() function and use the
> optimized buffer_find_nonzero_offset() function
> instead.
> 
> here buffer_find_nonzero_offset() is used directly
> to avoid the unnecssary additional checks in
> buffer_is_zero().
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---

> -    return 1;
> +    return 
> +     buffer_find_nonzero_offset(p, TARGET_PAGE_SIZE) == TARGET_PAGE_SIZE;

Unusual layout.  I would have written:

    return buffer_find_nonzero_offset(p, TARGET_PAGE_SIZE) ==
        TARGET_PAGE_SIZE;

>  /* struct contains XBZRLE cache and a static page
> @@ -443,7 +434,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
>  
>              /* In doubt sent page as normal */
>              bytes_sent = -1;
> -            if (is_dup_page(p)) {
> +            if (is_zero_page(p)) {
>                  acct_info.dup_pages++;
>                  bytes_sent = save_block_hdr(f, block, offset, cont,
>                                              RAM_SAVE_FLAG_COMPRESS);

I would move the change for qemu_put_byte(f, 0) out of patch 7 into this
patch, since this is the first point where you know the byte to send is 0.
diff mbox

Patch

diff --git a/arch_init.c b/arch_init.c
index 1b71912..6806727 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -144,19 +144,10 @@  int qemu_read_default_config_files(bool userconfig)
     return 0;
 }
 
-static int is_dup_page(uint8_t *page)
+static inline bool is_zero_page(uint8_t *p)
 {
-    VECTYPE *p = (VECTYPE *)page;
-    VECTYPE val = SPLAT(page);
-    int i;
-
-    for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
-        if (!ALL_EQ(val, p[i])) {
-            return 0;
-        }
-    }
-
-    return 1;
+    return 
+     buffer_find_nonzero_offset(p, TARGET_PAGE_SIZE) == TARGET_PAGE_SIZE;
 }
 
 /* struct contains XBZRLE cache and a static page
@@ -443,7 +434,7 @@  static int ram_save_block(QEMUFile *f, bool last_stage)
 
             /* In doubt sent page as normal */
             bytes_sent = -1;
-            if (is_dup_page(p)) {
+            if (is_zero_page(p)) {
                 acct_info.dup_pages++;
                 bytes_sent = save_block_hdr(f, block, offset, cont,
                                             RAM_SAVE_FLAG_COMPRESS);