Patchwork [v4,8/8] coalesce adjacent iovecs

login
register
mail settings
Submitter Orit Wasserman
Date March 21, 2013, 6:34 p.m.
Message ID <1363890878-8161-9-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/229811/
State New
Headers show

Comments

Orit Wasserman - March 21, 2013, 6:34 p.m.
This way we send one big buffer instead of many small ones

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 savevm.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Eric Blake - March 21, 2013, 7:41 p.m.
On 03/21/2013 12:34 PM, Orit Wasserman wrote:
> This way we send one big buffer instead of many small ones
> 
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
> ---
>  savevm.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/savevm.c b/savevm.c
> index b024354..9e8ddee 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -622,6 +622,18 @@ int qemu_fclose(QEMUFile *f)
>      return ret;
>  }
>  
> +static void add_to_iovec(QEMUFile *f, const uint8_t *buf, int size)
> +{
> +    /* check for adjoint buffer and colasce them */

s/adjoint/adjacent/
s/colasce/coalesce/

Patch

diff --git a/savevm.c b/savevm.c
index b024354..9e8ddee 100644
--- a/savevm.c
+++ b/savevm.c
@@ -622,6 +622,18 @@  int qemu_fclose(QEMUFile *f)
     return ret;
 }
 
+static void add_to_iovec(QEMUFile *f, const uint8_t *buf, int size)
+{
+    /* check for adjoint buffer and colasce them */
+    if (f->iovcnt > 0 && buf == f->iov[f->iovcnt - 1].iov_base +
+        f->iov[f->iovcnt - 1].iov_len) {
+        f->iov[f->iovcnt - 1].iov_len += size;
+    } else {
+        f->iov[f->iovcnt].iov_base = (uint8_t *)buf;
+        f->iov[f->iovcnt++].iov_len = size;
+    }
+}
+
 void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size)
 {
     if (f->last_error) {
@@ -634,8 +646,7 @@  void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size)
         abort();
     }
 
-    f->iov[f->iovcnt].iov_base = (uint8_t *)buf;
-    f->iov[f->iovcnt++].iov_len = size;
+    add_to_iovec(f, buf, size);
 
     f->is_write = 1;
     f->bytes_xfer += size;
@@ -690,8 +701,8 @@  void qemu_put_byte(QEMUFile *f, int v)
     f->buf[f->buf_index++] = v;
     f->is_write = 1;
     f->bytes_xfer++;
-    f->iov[f->iovcnt].iov_base = f->buf + (f->buf_index - 1);
-    f->iov[f->iovcnt++].iov_len = 1;
+
+    add_to_iovec(f, f->buf + (f->buf_index - 1), 1);
 
     if (f->buf_index >= IO_BUF_SIZE || f->iovcnt >= MAX_IOV_SIZE) {
         qemu_fflush(f);