qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory
@ 2016-07-14 16:59 Vladimir Sementsov-Ogievskiy
  2016-07-14 18:32 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2016-07-14 16:59 UTC (permalink / raw)
  To: qemu-devel, qemu-block
  Cc: mreitz, kwolf, stefanha, eblake, den,
	Vladimir Sementsov-Ogievskiy

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 <vsementsov@virtuozzo.com>
---

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));
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory
  2016-07-14 16:59 [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory Vladimir Sementsov-Ogievskiy
@ 2016-07-14 18:32 ` Eric Blake
  2016-07-14 19:04 ` [Qemu-devel] [Qemu-block] " John Snow
  2016-07-15 12:49 ` [Qemu-devel] " Max Reitz
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2016-07-14 18:32 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block
  Cc: mreitz, kwolf, stefanha, den

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

On 07/14/2016 10:59 AM, 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

s/no/not/

> 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 <vsementsov@virtuozzo.com>
> ---

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH v2] qcow2: do not allocate extra memory
  2016-07-14 16:59 [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory Vladimir Sementsov-Ogievskiy
  2016-07-14 18:32 ` Eric Blake
@ 2016-07-14 19:04 ` John Snow
  2016-07-15 12:49 ` [Qemu-devel] " Max Reitz
  2 siblings, 0 replies; 4+ messages in thread
From: John Snow @ 2016-07-14 19:04 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block
  Cc: kwolf, mreitz, stefanha, den



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 <vsementsov@virtuozzo.com>
> ---
> 
> 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 <jsnow@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory
  2016-07-14 16:59 [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory Vladimir Sementsov-Ogievskiy
  2016-07-14 18:32 ` Eric Blake
  2016-07-14 19:04 ` [Qemu-devel] [Qemu-block] " John Snow
@ 2016-07-15 12:49 ` Max Reitz
  2 siblings, 0 replies; 4+ messages in thread
From: Max Reitz @ 2016-07-15 12:49 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block
  Cc: kwolf, stefanha, eblake, den

[-- Attachment #1: Type: text/plain, Size: 1022 bytes --]

On 14.07.2016 18:59, 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 <vsementsov@virtuozzo.com>
> ---
> 
> v2: improve commit message
> 
>  block/qcow.c  | 2 +-
>  block/qcow2.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Thanks Vladimir, applied to my block branch (with s/no/not/ as proposed
by Eric):

https://github.com/XanClic/qemu/commits/block

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 498 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-15 12:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-14 16:59 [Qemu-devel] [PATCH v2] qcow2: do not allocate extra memory Vladimir Sementsov-Ogievskiy
2016-07-14 18:32 ` Eric Blake
2016-07-14 19:04 ` [Qemu-devel] [Qemu-block] " John Snow
2016-07-15 12:49 ` [Qemu-devel] " Max Reitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).