Skip to contentSkip to conversation

vnc buffer enhancements for 2.5

PATCH In review Peter Lieven 3 participants 8 messages Nov 3, 2015 – Nov 5, 2015

lore
Share & tools
lore
#0 lore raw

cover vnc buffer enhancements for 2.5

These are 2 patches on top of Gerds improve buffer handling series.

Patch 1 is an updated version of the patch included in Gerds series and Patch 2 is a further optimization open for discussion.

Peter

Peter Lieven (2):
io/buffer: allow a buffer to shrink gracefully io/buffer: avoid memmove at each qio_buffer_advance

 include/io/buffer.h |  3 ++
 io/buffer.c         | 81 +++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 66 insertions(+), 18 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 io/buffer: allow a buffer to shrink gracefully

the idea behind this patch is to allow the buffer to shrink, but make this a seldom operation. The buffers average size is measured exponentionally smoothed with am alpha of 1/128.

---
 include/io/buffer.h |  1 +
 io/buffer.c         | 42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 34 insertions(+), 9 deletions(-)
include/io/buffer.h +1 -0
index f6668cb..f63869e 100644
@@ -37,6 +37,7 @@ struct QIOBuffer {
     char *name;
     size_t capacity;
     size_t offset;
+    uint64_t avg_size;
     uint8_t *buffer;
 };
 
io/buffer.c +33 -9

78 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] io/buffer: allow a buffer to shrink gracefully

Am 03.11.2015 um 11:40 schrieb Gerd Hoffmann:

Quoted 8 lines · Peter Lieven

io/buffer.c

Quoted 5 lines
io/buffer.c +0 -0
index 0fd3cea..d2a6043 100644
@@ -23,6 +23,10 @@

Needs a rebase (current wip branch is available at
https://www.kraxel.org/cgit/qemu/log/?h=work/vnc-buffers)

I found that the version is ok, just the comment above the BUFFER_AVG_SIZE_SHIFT is missing.

Peter

#4 lore raw

PATCH 2/2 io/buffer: avoid memmove at each qio_buffer_advance

In reply to Peter Lieven

memmove isn't exactly cheap at it involves temporary buffers if the memory areas are overlapping. So make qio_buffer_advance basically a pointer adjustment, but still keep the wasted memory in reasonable limits.

---
 include/io/buffer.h |  2 ++
 io/buffer.c         | 43 ++++++++++++++++++++++++++++++++-----------
 2 files changed, 34 insertions(+), 11 deletions(-)
include/io/buffer.h +2 -0
index f63869e..43688cc 100644
@@ -39,6 +39,8 @@ struct QIOBuffer {
     size_t offset;
     uint64_t avg_size;
     uint8_t *buffer;
+    size_t base_offs;
+    uint8_t *base_ptr;
 };
 
 /**
io/buffer.c +32 -11

105 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] io/buffer: avoid memmove at each qio_buffer_advance

include/io/buffer.h struct QIOBuffer { · line 43

Quoted 10 lines
include/io/buffer.h +2 -0
index f63869e..43688cc 100644
@@ -39,6 +39,8 @@ struct QIOBuffer {
     size_t offset;
     uint64_t avg_size;
     uint8_t *buffer;
+    size_t base_offs;
+    uint8_t *base_ptr;

Why a separate base_ptr?

While being at it I'd much prefer to replace offset with start & end. The buffer content is buffer[start] ... buffer[end-1] then.

We can allow the buffer to wrap around, i.e. end < start. Buffer content is buf[start] ... buffer[size-1] and buffer[0] .. buffer[end-1] then. Makes the buffer management a bit more complicated, but we never have to memmove then (except when changing buffer size) and the WASTED_SIZE logic isn't needed too ...

cheers,
Gerd

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] io/buffer: avoid memmove at each qio_buffer_advance

Am 03.11.2015 um 11:52 schrieb Gerd Hoffmann:

Quoted 12 lines

include/io/buffer.h struct QIOBuffer { · line 43

Quoted 10 lines
include/io/buffer.h +2 -0
index f63869e..43688cc 100644
@@ -39,6 +39,8 @@ struct QIOBuffer {
      size_t offset;
      uint64_t avg_size;
      uint8_t *buffer;
+    size_t base_offs;
+    uint8_t *base_ptr;

Why a separate base_ptr?

Quoted 8 lines

While being at it I'd much prefer to replace offset with start & end. The buffer content is buffer[start] ... buffer[end-1] then.

We can allow the buffer to wrap around, i.e. end < start. Buffer content is buf[start] ... buffer[size-1] and buffer[0] .. buffer[end-1] then. Makes the buffer management a bit more complicated, but we never have to memmove then (except when changing buffer size) and the WASTED_SIZE logic isn't needed too ...

Then drop this patch and try to use your approach for 2.6+

Peter

#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] io/buffer: avoid memmove at each qio_buffer_advance

In reply to Peter Lieven
Quoted 2 lines · Peter Lieven

memmove isn't exactly cheap at it involves temporary buffers if the memory areas are overlapping.

Really? The memmove() I've seen detect whether to copy forward or backward. None of them copies through a bounce buffer.

Avoiding it can be worthwhile regardless.

Quoted 3 lines

So make qio_buffer_advance
basically a pointer adjustment, but still keep the wasted memory in reasonable limits.