Received: from eggs.gnu.org ([2001:4830:134:3::10]:40553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlESI-00078G-Cc for qemu-devel@nongnu.org; Tue, 26 Nov 2013 03:57:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlESC-0008Md-GQ for qemu-devel@nongnu.org; Tue, 26 Nov 2013 03:57:14 -0500 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:45794 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlESC-0008M5-6C for qemu-devel@nongnu.org; Tue, 26 Nov 2013 03:57:08 -0500 From: Peter Lieven Date: Tue, 26 Nov 2013 09:56:20 +0100 Message-Id: <1385456183-24840-7-git-send-email-pl@kamp.de> In-Reply-To: <1385456183-24840-1-git-send-email-pl@kamp.de> References: <1385456183-24840-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCHv2 1.8 6/9] qemu-img: dynamically adjust iobuffer size during convert List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven , stefanha@redhat.com since the convert process is basically a sync operation it might be benificial in some case to change the hardcoded I/O buffer size to a greater value. This patch increases the I/O buffer size if the output driver advertises an optimal transfer length or discard alignment that is greater than the default buffer size of 2M. Signed-off-by: Peter Lieven --- qemu-img.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e2d1a0a..b076d44 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1135,6 +1135,7 @@ static int img_convert(int argc, char **argv) sector_num_next_status = 0; uint64_t bs_sectors; uint8_t * buf = NULL; + size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE; const uint8_t *buf1; BlockDriverInfo bdi; QEMUOptionParameter *param = NULL, *create_options = NULL; @@ -1371,7 +1372,16 @@ static int img_convert(int argc, char **argv) bs_i = 0; bs_offset = 0; bdrv_get_geometry(bs[0], &bs_sectors); - buf = qemu_blockalign(out_bs, IO_BUF_SIZE); + + /* increase bufsectors from the default 4096 (2M) if opt_transfer_length + * or discard_alignment of the out_bs is greater. Limit to 32768 (16MB) + * as maximum. */ + bufsectors = MIN(32768, + MAX(bufsectors, MAX(out_bs->bl.opt_transfer_length, + out_bs->bl.discard_alignment)) + ); + + buf = qemu_blockalign(out_bs, bufsectors * BDRV_SECTOR_SIZE); if (skip_create) { int64_t output_length = bdrv_getlength(out_bs); @@ -1394,7 +1404,7 @@ static int img_convert(int argc, char **argv) goto out; } cluster_size = bdi.cluster_size; - if (cluster_size <= 0 || cluster_size > IO_BUF_SIZE) { + if (cluster_size <= 0 || cluster_size > bufsectors * BDRV_SECTOR_SIZE) { error_report("invalid cluster size"); ret = -1; goto out; @@ -1531,8 +1541,8 @@ static int img_convert(int argc, char **argv) sector_num_next_status = sector_num + n1; } - if (nb_sectors >= (IO_BUF_SIZE / 512)) { - n = (IO_BUF_SIZE / 512); + if (nb_sectors >= bufsectors) { + n = bufsectors; } else { n = nb_sectors; } -- 1.7.9.5