From patchwork Tue Mar 26 09:58:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 231141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B8B92C0089 for ; Tue, 26 Mar 2013 21:05:14 +1100 (EST) Received: from localhost ([::1]:39318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKQki-0002eL-Hp for incoming@patchwork.ozlabs.org; Tue, 26 Mar 2013 06:05:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKQgy-0005Do-BY for qemu-devel@nongnu.org; Tue, 26 Mar 2013 06:01:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKQgr-0006Pw-G5 for qemu-devel@nongnu.org; Tue, 26 Mar 2013 06:01:20 -0400 Received: from [2a02:248:0:30:223:aeff:fefe:7f1c] (port=49000 helo=dns.kamp-intra.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKQgr-0006Pe-9H for qemu-devel@nongnu.org; Tue, 26 Mar 2013 06:01:13 -0400 Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 90504206B0; Tue, 26 Mar 2013 11:01:10 +0100 (CET) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 8173E5FBAA; Tue, 26 Mar 2013 11:01:12 +0100 (CET) From: Peter Lieven To: qemu-devel@nongnu.org Date: Tue, 26 Mar 2013 10:58:35 +0100 Message-Id: <1364291919-19563-7-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1364291919-19563-1-git-send-email-pl@kamp.de> References: <1364291919-19563-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2a02:248:0:30:223:aeff:fefe:7f1c Cc: quintela@redhat.com, Stefan Hajnoczi , Peter Lieven , Orit Wasserman , Paolo Bonzini Subject: [Qemu-devel] [PATCHv5 06/10] migration: search for zero instead of dup pages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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(). raw performace gain checking 1 GByte zeroed memory over is_dup_page() is approx. 10-12% with SSE2 and 8-10% with unsigned long arithmedtic. Signed-off-by: Peter Lieven Reviewed-by: Orit Wasserman Reviewed-by: Eric Blake --- arch_init.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/arch_init.c b/arch_init.c index 35974c2..dd5deff 100644 --- a/arch_init.c +++ b/arch_init.c @@ -146,19 +146,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 @@ -445,12 +436,12 @@ 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); - qemu_put_byte(f, *p); - bytes_sent += 1; + qemu_put_byte(f, 0); + bytes_sent++; } else if (migrate_use_xbzrle()) { current_addr = block->offset + offset; bytes_sent = save_xbzrle_page(f, p, current_addr, block,