Skip to contentSkip to conversation

Discard guest console data in bigger chunks

PATCH New Tim Deegan 1 participant 1 message May 26, 2010

lore
Share & tools
lore

Tim Deegan

author
#0 lore raw

PATCH 1/1 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 <[email protected]>

# HG changeset patch
# User Tim Deegan <[email protected]> # 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 <[email protected]>

tools/console/daemon/io.c +18 -11
diff -r fa41b06a52a3 -r 127cb61828d4 tools/console/daemon/io.c
@@ -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;
+		}
 	}
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel