thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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