From: Keir Fraser Date: Thu, 27 May 2010 07:21:24 +0000 (+0100) Subject: xenconsoled: Discard guest console data in bigger chunks X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12079 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2e5af0a5dc61b0bd0a34def3bbe19b7e799b7a64;p=xen.git 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 --- 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; + } } }