vnc buffer enhancements for 2.5
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
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
@@ -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
Re: [Qemu-devel] [PATCH 1/2] io/buffer: allow a buffer to shrink gracefully
io/buffer.c
Quoted 5 lines · Peter Lieven
io/buffer.c +0
-0@@ -23,6 +23,10 @@
Needs a rebase (current wip branch is available at
https://www.kraxel.org/cgit/qemu/log/?h=work/vnc-buffers)
cheers,
Gerd
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@@ -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
PATCH 2/2 io/buffer: avoid memmove at each qio_buffer_advance
In reply to Peter Lievenmemmove 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
@@ -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
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@@ -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
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@@ -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_SIZElogic isn't needed too ...
Then drop this patch and try to use your approach for 2.6+
Peter
Re: [Qemu-devel] [PATCH 2/2] io/buffer: avoid memmove at each qio_buffer_advance
In reply to Peter LievenQuoted 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.