[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 1/5] qcow2: do not allocate extra memory
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PULL 1/5] qcow2: do not allocate extra memory |
Date: |
Tue, 26 Jul 2016 19:18:34 +0200 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
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 not 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 <address@hidden>
Message-id: address@hidden
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: John Snow <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
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 0c7b75b..6f9b2e2 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 d620d0a..91ef4df 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));
--
2.9.0
- [Qemu-devel] [PULL 0/5] Block patches for 2.7.0-rc1, Max Reitz, 2016/07/26
- [Qemu-devel] [PULL 1/5] qcow2: do not allocate extra memory,
Max Reitz <=
- [Qemu-devel] [PULL 2/5] AioContext: correct comments, Max Reitz, 2016/07/26
- [Qemu-devel] [PULL 4/5] block: export LUKS specific data to qemu-img info, Max Reitz, 2016/07/26
- [Qemu-devel] [PULL 3/5] crypto: add support for querying parameters for block encryption, Max Reitz, 2016/07/26
- [Qemu-devel] [PULL 5/5] iotest: fix python based IO tests, Max Reitz, 2016/07/26
- Re: [Qemu-devel] [PULL 0/5] Block patches for 2.7.0-rc1, Peter Maydell, 2016/07/27