From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: Peter Lieven <pl@kamp.de>, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 2/4] vnc: allow the Buffer to shrink again
Date: Thu, 27 Aug 2015 12:18:52 +0200 [thread overview]
Message-ID: <1440670734-5616-3-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1440670734-5616-1-git-send-email-pl@kamp.de>
currently the Buffer can only grow. This increases Qemu memory footprint
dramatically since normally the biggest VNC updates are at connection time.
But also after a VNC session has terminated there is one persistent buffer
in queue->buffer which I have seen to increase to over 100MB and it is never
getting smaller again.
Signed-off-by: Peter Lieven <pl@kamp.de>
---
ui/vnc.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/ui/vnc.c b/ui/vnc.c
index 8cfd2d8..061e337 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -654,6 +654,7 @@ void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
}
#define BUFFER_MIN_INIT_SIZE 4096
+#define BUFFER_MIN_SHRINK_SIZE 65536
void buffer_reserve(Buffer *buffer, size_t len)
{
@@ -674,9 +675,19 @@ uint8_t *buffer_end(Buffer *buffer)
return buffer->buffer + buffer->offset;
}
+static void buffer_shrink(Buffer *buffer) {
+ size_t new = MAX(pow2ceil(buffer->offset) * 2,
+ BUFFER_MIN_SHRINK_SIZE);
+ if (new < buffer->capacity) {
+ buffer->buffer = g_realloc(buffer->buffer, new);
+ buffer->capacity = new;
+ }
+}
+
void buffer_reset(Buffer *buffer)
{
- buffer->offset = 0;
+ buffer->offset = 0;
+ buffer_shrink(buffer);
}
void buffer_free(Buffer *buffer)
@@ -698,6 +709,7 @@ void buffer_advance(Buffer *buf, size_t len)
memmove(buf->buffer, buf->buffer + len,
(buf->offset - len));
buf->offset -= len;
+ buffer_shrink(buf);
}
static void vnc_desktop_resize(VncState *vs)
--
1.9.1
next prev parent reply other threads:[~2015-08-27 10:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 10:18 [Qemu-devel] [PATCH 0/4] VNC server memory savings Peter Lieven
2015-08-27 10:18 ` [Qemu-devel] [PATCH 1/4] vnc: make the Buffer capacity increase in powers of two Peter Lieven
2015-09-03 8:56 ` Gerd Hoffmann
2015-09-03 10:29 ` Peter Lieven
2015-09-03 10:47 ` Gerd Hoffmann
2015-08-27 10:18 ` Peter Lieven [this message]
2015-08-27 10:39 ` [Qemu-devel] [PATCH 2/4] vnc: allow the Buffer to shrink again Daniel P. Berrange
2015-08-27 12:36 ` Peter Lieven
2015-09-03 9:52 ` Gerd Hoffmann
2015-09-03 10:07 ` Peter Lieven
2015-09-03 11:52 ` Gerd Hoffmann
2015-09-03 14:52 ` Peter Lieven
2015-09-03 10:36 ` Peter Lieven
2015-09-03 11:57 ` Gerd Hoffmann
2015-09-03 12:00 ` Peter Lieven
2015-08-27 10:18 ` [Qemu-devel] [PATCH 3/4] vnc-jobs: move buffer_reset to vnc_async_encoding_end Peter Lieven
2015-08-27 10:18 ` [Qemu-devel] [PATCH 4/4] vnc: destroy server surface if no client is connected Peter Lieven
2015-09-03 9:57 ` Gerd Hoffmann
2015-09-03 10:08 ` Peter Lieven
2015-09-03 10:54 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440670734-5616-3-git-send-email-pl@kamp.de \
--to=pl@kamp.de \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).