From 2e5af0a5dc61b0bd0a34def3bbe19b7e799b7a64 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 27 May 2010 08:21:24 +0100 Subject: xenconsoled: Discard guest console data in bigger chunks Discard guest console data in bigger chunks so that there are fewer discontinuities in the console data. Also avoid discarding data if space is available at the front of the buffer by reclaiming that space. Patch from: Christian Limpach Signed-off-by: Tim Deegan --- tools/console/daemon/io.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'tools/console') diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 5a6ccbfd43..22833d7469 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -202,18 +202,25 @@ static void buffer_append(struct domain *dom) } if (discard_overflowed_data && buffer->max_capacity && - buffer->size > buffer->max_capacity) { - /* Discard the middle of the data. */ - - size_t over = buffer->size - buffer->max_capacity; - char *maxpos = buffer->data + buffer->max_capacity; - - memmove(maxpos - over, maxpos, over); - buffer->data = realloc(buffer->data, buffer->max_capacity); - buffer->size = buffer->capacity = buffer->max_capacity; + buffer->size > 5 * buffer->max_capacity / 4) { + if (buffer->consumed > buffer->max_capacity / 4) { + /* Move data up in buffer, since beginning has + * been output. Only needed because buffer is + * not a ring buffer *sigh* */ + memmove(buffer->data, + buffer->data + buffer->consumed, + buffer->size - buffer->consumed); + buffer->size -= buffer->consumed; + buffer->consumed = 0; + } else { + /* Discard the middle of the data. */ + size_t over = buffer->size - buffer->max_capacity; - if (buffer->consumed > buffer->max_capacity - over) - buffer->consumed = buffer->max_capacity - over; + memmove(buffer->data + buffer->max_capacity / 2, + buffer->data + buffer->max_capacity, + over); + buffer->size = buffer->max_capacity / 2 + over; + } } } -- cgit v1.2.3