From patchwork Thu May 26 03:48:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9136551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96557607D3 for ; Thu, 26 May 2016 03:49:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C9182829C for ; Thu, 26 May 2016 03:49:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81202282C0; Thu, 26 May 2016 03:49:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6A6B2829C for ; Thu, 26 May 2016 03:49:32 +0000 (UTC) Received: from localhost ([::1]:36246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5mIb-000202-OB for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 May 2016 23:49:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5mIC-0001yw-BS for qemu-devel@nongnu.org; Wed, 25 May 2016 23:49:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5mIA-00042v-1R for qemu-devel@nongnu.org; Wed, 25 May 2016 23:49:03 -0400 Received: from resqmta-po-03v.sys.comcast.net ([2001:558:fe16:19:96:114:154:162]:58084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5mI9-00041a-Si for qemu-devel@nongnu.org; Wed, 25 May 2016 23:49:01 -0400 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by comcast with SMTP id 5mHcbdqBCYPZX5mI9bZUB8; Thu, 26 May 2016 03:49:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1464234541; bh=U4jww/ccPRXSs0UsXqPTzbpWzumMSFTnJmX1ZFOYnf4=; h=Received:Received:From:To:Subject:Date:Message-Id; b=ns5zGlPsNW/pOkmIp9Dj5Innpcpt33zwaLokDGDTt+zRRP/llBRZTAsqSo4STKwfX nAlki89tecUR5ljqqb9BQPccVwpVLhrraG2CkliQBSlgvgdyEhqeW9DYqZhRfaRR98 Xr6slryKsLHs+J/IXRedsuimMov+9fl25XRgG2lFmkuDNhaG8AZ4exi+794fplb2pv RdIDPlW3+qSg0jEDwX77NfvwhO477xHZAw3v/kybgafI2aXSHc16gGFszlx5XJXEXh nv1mbdrPwFM9TcBBGkQs5PqO0Jo7PIHYYHXgubc5kuzEIfOMvNIHd/L896Y7/j1W/Q GV9WVoOSAnetQ== Received: from red.localdomain ([24.10.254.122]) by resomta-po-18v.sys.comcast.net with comcast id yrop1s00E2fD5rL01rp1lF; Thu, 26 May 2016 03:49:01 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 21:48:45 -0600 Message-Id: <1464234529-13018-2-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464234529-13018-1-git-send-email-eblake@redhat.com> References: <1464234529-13018-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:162 Subject: [Qemu-devel] [PATCH v3 1/5] block: split write_zeroes always 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: kwolf@redhat.com, Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Denis V. Lunev" We should split requests even if they are less than write_zeroes_alignment. For example we can have the following request: offset 62k size 4k write_zeroes_alignment 64k The original code sent 1 request covering 2 qcow2 clusters, and resulted in both clusters being allocated. But by splitting the request, we can cater to the case where one of the two clusters can be zeroed as a whole, for only 1 cluster allocated after the operation. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Kevin Wolf Message-Id: <1463476543-3087-2-git-send-email-den@openvz.org> [eblake: Avoid exceeding nb_sectors, hoist alignment checks out of loop, and update testsuite to show that patch works] Signed-off-by: Eric Blake Reviewed-by: Fam Zheng --- block/io.c | 30 +++++++++++++++++------------- tests/qemu-iotests/154.out | 18 ++++++++++++------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/block/io.c b/block/io.c index f474b9a..26b5845 100644 --- a/block/io.c +++ b/block/io.c @@ -1118,28 +1118,32 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, struct iovec iov = {0}; int ret = 0; bool need_flush = false; + int head = 0; + int tail = 0; int max_write_zeroes = MIN_NON_ZERO(bs->bl.max_write_zeroes, BDRV_REQUEST_MAX_SECTORS); + if (bs->bl.write_zeroes_alignment) { + assert(is_power_of_2(bs->bl.write_zeroes_alignment)); + head = sector_num & (bs->bl.write_zeroes_alignment - 1); + tail = (sector_num + nb_sectors) & (bs->bl.write_zeroes_alignment - 1); + max_write_zeroes &= ~(bs->bl.write_zeroes_alignment - 1); + } while (nb_sectors > 0 && !ret) { int num = nb_sectors; /* Align request. Block drivers can expect the "bulk" of the request - * to be aligned. + * to be aligned, and that unaligned requests do not cross cluster + * boundaries. */ - if (bs->bl.write_zeroes_alignment - && num > bs->bl.write_zeroes_alignment) { - if (sector_num % bs->bl.write_zeroes_alignment != 0) { - /* Make a small request up to the first aligned sector. */ - num = bs->bl.write_zeroes_alignment; - num -= sector_num % bs->bl.write_zeroes_alignment; - } else if ((sector_num + num) % bs->bl.write_zeroes_alignment != 0) { - /* Shorten the request to the last aligned sector. num cannot - * underflow because num > bs->bl.write_zeroes_alignment. - */ - num -= (sector_num + num) % bs->bl.write_zeroes_alignment; - } + if (head) { + /* Make a small request up to the first aligned sector. */ + num = MIN(nb_sectors, bs->bl.write_zeroes_alignment - head); + head = 0; + } else if (tail && num > bs->bl.write_zeroes_alignment) { + /* Shorten the request to the last aligned sector. */ + num -= tail; } /* limit request size */ diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out index 8946b73..b9d27c5 100644 --- a/tests/qemu-iotests/154.out +++ b/tests/qemu-iotests/154.out @@ -106,11 +106,14 @@ read 1024/1024 bytes at offset 67584 read 5120/5120 bytes at offset 68608 5 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) [{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false}, -{ "start": 32768, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 20480}, +{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480}, +{ "start": 36864, "length": 4096, "depth": 0, "zero": true, "data": false}, { "start": 40960, "length": 8192, "depth": 1, "zero": true, "data": false}, -{ "start": 49152, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 28672}, +{ "start": 49152, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576}, +{ "start": 53248, "length": 4096, "depth": 0, "zero": true, "data": false}, { "start": 57344, "length": 8192, "depth": 1, "zero": true, "data": false}, -{ "start": 65536, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 36864}, +{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672}, +{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false}, { "start": 73728, "length": 134144000, "depth": 1, "zero": true, "data": false}] == spanning two clusters, non-zero after request == @@ -145,11 +148,14 @@ read 7168/7168 bytes at offset 65536 read 1024/1024 bytes at offset 72704 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) [{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false}, -{ "start": 32768, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 20480}, +{ "start": 32768, "length": 4096, "depth": 0, "zero": true, "data": false}, +{ "start": 36864, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480}, { "start": 40960, "length": 8192, "depth": 1, "zero": true, "data": false}, -{ "start": 49152, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 28672}, +{ "start": 49152, "length": 4096, "depth": 0, "zero": true, "data": false}, +{ "start": 53248, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576}, { "start": 57344, "length": 8192, "depth": 1, "zero": true, "data": false}, -{ "start": 65536, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 36864}, +{ "start": 65536, "length": 4096, "depth": 0, "zero": true, "data": false}, +{ "start": 69632, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672}, { "start": 73728, "length": 134144000, "depth": 1, "zero": true, "data": false}] == spanning two clusters, partially overwriting backing file ==