From patchwork Tue Jul 12 17:43:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 9225845 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 005DB6086B for ; Tue, 12 Jul 2016 17:45:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7A5027813 for ; Tue, 12 Jul 2016 17:45:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB57527C38; Tue, 12 Jul 2016 17:45:04 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 4787827813 for ; Tue, 12 Jul 2016 17:45:04 +0000 (UTC) Received: from localhost ([::1]:42436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bN1jx-0006Tq-D1 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Jul 2016 13:45:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bN1jc-0006Qo-V0 for qemu-devel@nongnu.org; Tue, 12 Jul 2016 13:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bN1jX-0003gI-Gw for qemu-devel@nongnu.org; Tue, 12 Jul 2016 13:44:39 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:21639 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bN1jX-0003gD-3n for qemu-devel@nongnu.org; Tue, 12 Jul 2016 13:44:35 -0400 Received: from kvm.sw.ru. ([10.28.8.145]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u6B0VaNY015723; Mon, 11 Jul 2016 03:31:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jul 2016 20:43:51 +0300 Message-Id: <1468345431-106198-1-git-send-email-vsementsov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH] qcow2: do not allocate extra memory 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, Vladimir Sementsov-Ogievskiy , mreitz@redhat.com, stefanha@redhat.com, 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 There are no needs to allocate more than one cluster, as we set avail_out for deflate to one cluster. Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! Please, can anybody say me what I'm missing? I've looked through deflate documentation at http://www.zlib.net/manual.html, and I didn't find anything about allocating more memory for out buffer than specified in avail_out field.. What is this magic formula? ======== All uses of out_buf in the function: uint8_t *out_buf; ... out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); ... strm.avail_out = s->cluster_size; strm.next_out = out_buf; ret = deflate(&strm, Z_FINISH); ... out_len = strm.next_out - out_buf; ... ret = bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len); ... g_free(out_buf); block/qcow.c | 2 +- block/qcow2.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index ac849bd..d8826f3 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -983,7 +983,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return ret; } - out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); + out_buf = g_malloc(s->cluster_size); /* best compression, small window, no zlib header */ memset(&strm, 0, sizeof(strm)); diff --git a/block/qcow2.c b/block/qcow2.c index a5ea19b..b1c90ae 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2612,7 +2612,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, return ret; } - out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); + out_buf = g_malloc(s->cluster_size); /* best compression, small window, no zlib header */ memset(&strm, 0, sizeof(strm));