From patchwork Sat May 14 12:01:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9094921 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C3A8CBF29F for ; Sat, 14 May 2016 12:01:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 382CA20251 for ; Sat, 14 May 2016 12:01:44 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 53EE6201FE for ; Sat, 14 May 2016 12:01:43 +0000 (UTC) Received: from localhost ([::1]:37493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1YGM-0003I7-MF for patchwork-qemu-devel@patchwork.kernel.org; Sat, 14 May 2016 08:01:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1YGC-00039W-Oy for qemu-devel@nongnu.org; Sat, 14 May 2016 08:01:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1YG6-0006mc-OZ for qemu-devel@nongnu.org; Sat, 14 May 2016 08:01:31 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:16257 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1YG6-0006lm-B5 for qemu-devel@nongnu.org; Sat, 14 May 2016 08:01:26 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u4EC1Dng032296; Sat, 14 May 2016 15:01:18 +0300 (MSK) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Date: Sat, 14 May 2016 15:01:09 +0300 Message-Id: <1463227273-27523-3-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463227273-27523-1-git-send-email-den@openvz.org> References: <1463227273-27523-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 2/6] 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: Kevin Wolf , den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Original code will send 1 request covering 2 qcow2 clusters. One cluster could be zeroed as a whole, another could not be. In this case we will have both 2 clusters allocated. After the patch 2 requests to qcow2 layer will be sent and thus only one cluster will be allocated. Signed-off-by: Denis V. Lunev CC: Kevin Wolf --- block/io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index cd6d71a..2d6f48f 100644 --- a/block/io.c +++ b/block/io.c @@ -1172,13 +1172,13 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, /* Align request. Block drivers can expect the "bulk" of the request * to be aligned. */ - if (bs->bl.write_zeroes_alignment - && num > bs->bl.write_zeroes_alignment) { + if (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) { + } else if (num > bs->bl.write_zeroes_alignment && + (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. */