From patchwork Mon Apr 24 13:55:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 754273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBSYX5VRlz9sDB for ; Mon, 24 Apr 2017 23:56:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AeL3j/7+"; dkim-atps=neutral Received: from localhost ([::1]:44324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2eTM-0000E5-5w for incoming@patchwork.ozlabs.org; Mon, 24 Apr 2017 09:56:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2eT1-0000Do-Pr for qemu-devel@nongnu.org; Mon, 24 Apr 2017 09:55:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2eSz-0006Bi-7R for qemu-devel@nongnu.org; Mon, 24 Apr 2017 09:55:51 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:36615) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d2eSy-0006B7-VV; Mon, 24 Apr 2017 09:55:49 -0400 Received: by mail-pf0-x242.google.com with SMTP id v14so2912017pfd.3; Mon, 24 Apr 2017 06:55:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=CG4tqjIRxw82zAMHlEvH8Uy684ydXPSASTFwfYCfQdw=; b=AeL3j/7+oU1ZPckvpZQ8SWzOESre6AAoos0x8W0wOsBTlcKjgQtpRqI8tMi6lkou+Y B81gx7/ihFJ7QXE9k006DONxjXyb5vJaHn3ch2RndDu10+VMdu/A2FoDGurrhmR5pzxA 3eQvyIpKQtqCR6YzK/Z3jqmmys9ClDlijijGGz+1GZvPyQXENRp7b1t1ZPAJWJQPwqm1 CApmg0iCYz+9Oj6Bj92EkLWDIro0cwBwB+c6QPCz0fhI0RUyYxvn8Glj1tlm+0NFVWD1 W51yhSqFNy2wT1SeqyPCmVtHmh2bo08+U30GoTMgT4AEYk+HjHZaokzpMU3XlBQ43sbe cDSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CG4tqjIRxw82zAMHlEvH8Uy684ydXPSASTFwfYCfQdw=; b=jjPc1jH6/IVizjez3OMSH1glMdnTYfvLxlMrbRQ+w1gdeeECvvjqgFI4kr+aSh60rW iZUcfDKYbZeNY3CKEdlCoxNFLJrTNiYLfKsGYWMcBf9KfQIeKYnTOgk9pwwPN1MpPHbO AJr8oDIjfb3upg0adtATOrhZ1jYWp6eo845D3g9VHwRMwguRys1xN8wM9oKay84tzL9m nsi0vaVn7Id7TmlZFeBQZVlIEdxbOXUx6MiZ8MzJkAF7dNWO9cf9Q3+S4h9aJhUPvj5t s7nHkIO8zlvDySdDsz5r2uu2aqA4WQCWuGdsNV9xyzoIWV8LYd8f46FXRMw6vcvALM9y kiZQ== X-Gm-Message-State: AN3rC/4u4V6UVzrkDX5WgFrSE6dt6oHWMFBXPF/9J8zJemuJk1aZqrS8 7aj4lwDql2xKFMX+ X-Received: by 10.99.97.209 with SMTP id v200mr10910507pgb.52.1493042147702; Mon, 24 Apr 2017 06:55:47 -0700 (PDT) Received: from localhost.localdomain ([119.28.70.25]) by smtp.gmail.com with ESMTPSA id p11sm31317635pfl.4.2017.04.24.06.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Apr 2017 06:55:47 -0700 (PDT) From: jemmy858585@gmail.com X-Google-Original-From: lidongchen@tencent.com To: qemu-devel@nongnu.org Date: Mon, 24 Apr 2017 21:55:40 +0800 Message-Id: <1493042140-25551-1-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH] migration/block: optimize the performance by coalescing the same write type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, qemu-block@nongnu.org, quintela@redhat.com, dgilbert@redhat.com, stefanha@redhat.com, Lidong Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Lidong Chen This patch optimizes the performance by coalescing the same write type. When the zero/non-zero state changes, perform the write for the accumulated cluster count. Signed-off-by: Lidong Chen --- Thanks Fam Zheng and Stefan's advice. --- migration/block.c | 66 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/migration/block.c b/migration/block.c index 060087f..e9c5e21 100644 --- a/migration/block.c +++ b/migration/block.c @@ -40,6 +40,8 @@ #define MAX_INFLIGHT_IO 512 +#define MIN_CLUSTER_SIZE 8192 + //#define DEBUG_BLK_MIGRATION #ifdef DEBUG_BLK_MIGRATION @@ -923,10 +925,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id) } ret = bdrv_get_info(blk_bs(blk), &bdi); - if (ret == 0 && bdi.cluster_size > 0 && - bdi.cluster_size <= BLOCK_SIZE && - BLOCK_SIZE % bdi.cluster_size == 0) { + if (ret == 0 && bdi.cluster_size > 0) { cluster_size = bdi.cluster_size; + while (cluster_size < MIN_CLUSTER_SIZE) { + cluster_size *= 2; + } } else { cluster_size = BLOCK_SIZE; } @@ -943,29 +946,58 @@ static int block_load(QEMUFile *f, void *opaque, int version_id) nr_sectors * BDRV_SECTOR_SIZE, BDRV_REQ_MAY_UNMAP); } else { - int i; - int64_t cur_addr; - uint8_t *cur_buf; + int64_t cur_addr = addr * BDRV_SECTOR_SIZE; + uint8_t *cur_buf = NULL; + int64_t last_addr = addr * BDRV_SECTOR_SIZE; + uint8_t *last_buf = NULL; + int64_t end_addr = addr * BDRV_SECTOR_SIZE + BLOCK_SIZE; buf = g_malloc(BLOCK_SIZE); qemu_get_buffer(f, buf, BLOCK_SIZE); - for (i = 0; i < BLOCK_SIZE / cluster_size; i++) { - cur_addr = addr * BDRV_SECTOR_SIZE + i * cluster_size; - cur_buf = buf + i * cluster_size; - - if ((!block_mig_state.zero_blocks || - cluster_size < BLOCK_SIZE) && - buffer_is_zero(cur_buf, cluster_size)) { - ret = blk_pwrite_zeroes(blk, cur_addr, - cluster_size, + cur_buf = buf; + last_buf = buf; + + while (last_addr < end_addr) { + int is_zero = 0; + int buf_size = MIN(end_addr - cur_addr, cluster_size); + + /* If the "zero blocks" migration capability is enabled + * and the buf_size == BLOCK_SIZE, then the source QEMU + * process has already scanned for zeroes. CPU is wasted + * scanning for zeroes in the destination QEMU process. + */ + if (block_mig_state.zero_blocks && + buf_size == BLOCK_SIZE) { + is_zero = 0; + } else { + is_zero = buffer_is_zero(cur_buf, buf_size); + } + + cur_addr += buf_size; + cur_buf += buf_size; + while (cur_addr < end_addr) { + buf_size = MIN(end_addr - cur_addr, cluster_size); + if (is_zero != buffer_is_zero(cur_buf, buf_size)) { + break; + } + cur_addr += buf_size; + cur_buf += buf_size; + } + + if (is_zero) { + ret = blk_pwrite_zeroes(blk, last_addr, + cur_addr - last_addr, BDRV_REQ_MAY_UNMAP); } else { - ret = blk_pwrite(blk, cur_addr, cur_buf, - cluster_size, 0); + ret = blk_pwrite(blk, last_addr, last_buf, + cur_addr - last_addr, 0); } if (ret < 0) { break; } + + last_addr = cur_addr; + last_buf = cur_buf; } g_free(buf); }