From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNlvy-0004eh-9M for qemu-devel@nongnu.org; Thu, 14 Jul 2016 15:04:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNlvw-0002xZ-3I for qemu-devel@nongnu.org; Thu, 14 Jul 2016 15:04:29 -0400 References: <1468515565-81313-1-git-send-email-vsementsov@virtuozzo.com> From: John Snow Message-ID: Date: Thu, 14 Jul 2016 15:04:20 -0400 MIME-Version: 1.0 In-Reply-To: <1468515565-81313-1-git-send-email-vsementsov@virtuozzo.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2] qcow2: do not allocate extra memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org On 07/14/2016 12:59 PM, Vladimir Sementsov-Ogievskiy wrote: > There are no needs to allocate more than one cluster, as we set > avail_out for deflate to one cluster. > > Zlib docs (http://www.zlib.net/manual.html) says: > "deflate compresses as much data as possible, and stops when the input > buffer becomes empty or the output buffer becomes full." > > So, deflate will not write more than avail_out to output buffer. If > there is no enough space in output buffer for compressed data (it may be > larger than input data) deflate just returns Z_OK. (if all data is > compressed and written to output buffer deflate returns Z_STREAM_END). > > Signed-off-by: Vladimir Sementsov-Ogievskiy > --- > > v2: improve commit message > > 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)); > Reviewed-by: John Snow