# HG changeset patch # User Tim Deegan # Date 1274880454 -3600 # Node ID 127cb61828d47baa8b024af354abc25f66438fb4 # Parent fa41b06a52a3dd1ec70a5cfe13201f2b47e6fc8b 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 -r fa41b06a52a3 -r 127cb61828d4 tools/console/daemon/io.c --- a/tools/console/daemon/io.c Wed May 26 10:52:15 2010 +0100 +++ b/tools/console/daemon/io.c Wed May 26 14:27:34 2010 +0100 @@ -202,18 +202,25 @@ } if (discard_overflowed_data && buffer->max_capacity && - buffer->size > buffer->max_capacity) { - /* Discard the middle of the data. */ + 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; - 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; - - 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; + } } }