Blame SOURCES/kvm-qemu-img-dynamically-adjust-iobuffer-size-during-con.patch.patch

0a122b
From ba5bef1bb19b97c88b2e99071ffab067b7f3b9d3 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <ba5bef1bb19b97c88b2e99071ffab067b7f3b9d3.1389014116.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Date: Mon, 9 Dec 2013 14:09:36 +0100
0a122b
Subject: [PATCH 48/50] qemu-img: dynamically adjust iobuffer size during
0a122b
 convert
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-51-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56087
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 50/52] qemu-img: dynamically adjust iobuffer size during convert
0a122b
Bugzilla: 1039557
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
From: Peter Lieven <pl@kamp.de>
0a122b
0a122b
since the convert process is basically a sync operation it might
0a122b
be benificial in some case to change the hardcoded I/O buffer
0a122b
size to a greater value.
0a122b
0a122b
This patch increases the I/O buffer size if the output
0a122b
driver advertises an optimal transfer length or discard alignment
0a122b
that is greater than the default buffer size of 2M.
0a122b
0a122b
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Signed-off-by: Peter Lieven <pl@kamp.de>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit f2521c9023067a007d18b844fe7639c1c5b6f2ac)
0a122b
---
0a122b
 qemu-img.c | 16 +++++++++++++---
0a122b
 1 file changed, 13 insertions(+), 3 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 qemu-img.c | 16 +++++++++++++---
0a122b
 1 file changed, 13 insertions(+), 3 deletions(-)
0a122b
0a122b
diff --git a/qemu-img.c b/qemu-img.c
0a122b
index c81d70a..6890bb1 100644
0a122b
--- a/qemu-img.c
0a122b
+++ b/qemu-img.c
0a122b
@@ -1133,6 +1133,7 @@ static int img_convert(int argc, char **argv)
0a122b
             sector_num_next_status = 0;
0a122b
     uint64_t bs_sectors;
0a122b
     uint8_t * buf = NULL;
0a122b
+    size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
0a122b
     const uint8_t *buf1;
0a122b
     BlockDriverInfo bdi;
0a122b
     QEMUOptionParameter *param = NULL, *create_options = NULL;
0a122b
@@ -1369,7 +1370,16 @@ static int img_convert(int argc, char **argv)
0a122b
     bs_i = 0;
0a122b
     bs_offset = 0;
0a122b
     bdrv_get_geometry(bs[0], &bs_sectors);
0a122b
-    buf = qemu_blockalign(out_bs, IO_BUF_SIZE);
0a122b
+
0a122b
+    /* increase bufsectors from the default 4096 (2M) if opt_transfer_length
0a122b
+     * or discard_alignment of the out_bs is greater. Limit to 32768 (16MB)
0a122b
+     * as maximum. */
0a122b
+    bufsectors = MIN(32768,
0a122b
+                     MAX(bufsectors, MAX(out_bs->bl.opt_transfer_length,
0a122b
+                                         out_bs->bl.discard_alignment))
0a122b
+                    );
0a122b
+
0a122b
+    buf = qemu_blockalign(out_bs, bufsectors * BDRV_SECTOR_SIZE);
0a122b
 
0a122b
     if (skip_create) {
0a122b
         int64_t output_length = bdrv_getlength(out_bs);
0a122b
@@ -1392,7 +1402,7 @@ static int img_convert(int argc, char **argv)
0a122b
             goto out;
0a122b
         }
0a122b
         cluster_size = bdi.cluster_size;
0a122b
-        if (cluster_size <= 0 || cluster_size > IO_BUF_SIZE) {
0a122b
+        if (cluster_size <= 0 || cluster_size > bufsectors * BDRV_SECTOR_SIZE) {
0a122b
             error_report("invalid cluster size");
0a122b
             ret = -1;
0a122b
             goto out;
0a122b
@@ -1529,7 +1539,7 @@ static int img_convert(int argc, char **argv)
0a122b
                 sector_num_next_status = sector_num + n1;
0a122b
             }
0a122b
 
0a122b
-            n = MIN(nb_sectors, IO_BUF_SIZE / 512);
0a122b
+            n = MIN(nb_sectors, bufsectors);
0a122b
             n = MIN(n, bs_sectors - (sector_num - bs_offset));
0a122b
             n1 = n;
0a122b
 
0a122b
-- 
0a122b
1.7.11.7
0a122b