From: Dmitry Konishchev <konishchev@gmail.com>
To: qemu-devel@nongnu.org
Cc: stanislav.ievlev@gmail.com
Subject: [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization
Date: Tue, 17 May 2011 18:33:40 +0400 [thread overview]
Message-ID: <BANLkTinHhx5jTgcH-cytci=fNdk2V7zssg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1419 bytes --]
Hi! I was wondering why qemu-img consumes so much CPU when it converts
one partially allocated qcow2 image to another qcow2 image and I've
written a patch which improves the situation a little.
I have an image:
> $ qemu-img info ubuntu.10.04.qcow2
> image: ubuntu.10.04.qcow2
> file format: qcow2
> virtual size: 20G (21474836480 bytes)
> disk size: 2.2G
> cluster_size: 65536
I create a new copy on write image:
> $ qemu-img create -f qcow2 -o backing_file=ubuntu.10.04.qcow2 volume.qcow2 100G
... and use it for a while.
Then I want to create a non-copy on write image from it to send it to someone:
> qemu-img convert -O qcow2 volume.qcow2 snapshot.qcow2
The last operation consumes a lot of CPU, so I run qemu-img under
profiler and realized, that most of CPU time is consumed by
is_not_zero() function. I had made a couple of optimizations on it and
got the following output for `time qemu-img convert -O qcow2
volume.qcow2 snapshot.qcow2`:
x86_64 machine:
Original qemu-img:
real 0m56.159s
user 0m34.670s
sys 0m12.079s
Patched qemu-img:
real 0m34.805s
user 0m18.445s
sys 0m12.552s
x86 machine:
Original qemu-img:
real 1m13.991s
user 0m24.734s
sys 0m6.604s
Patched qemu-img:
real 1m6.898s
user 0m16.021s
sys 0m6.700s
Please, see on the consumed user CPU time. I think that the
optimization worth it, so it will be awesome if you accept this patch
(see the attachment).
Thanks for your attention.
[-- Attachment #2: 0001-is_not_zero-optimization-in-qemu-img.patch --]
[-- Type: text/x-patch, Size: 1239 bytes --]
From 61d228c0ea0d518de48a08577cd6d282e2f97759 Mon Sep 17 00:00:00 2001
From: Dmitry Konishchev <konishchev@gmail.com>
Date: Tue, 17 May 2011 16:29:48 +0400
Subject: [PATCH] is_not_zero() optimization in qemu-img
---
qemu-img.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index e825123..41b4e32 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -498,12 +498,30 @@ static int img_commit(int argc, char **argv)
static int is_not_zero(const uint8_t *sector, int len)
{
+ /*
+ * Use long as the biggest available internal data type that fits into the
+ * CPU register and unroll the loop to smooth out the effect of memory
+ * latency.
+ */
+
int i;
- len >>= 2;
- for(i = 0;i < len; i++) {
- if (((uint32_t *)sector)[i] != 0)
+ len /= sizeof(long);
+
+ long d0;
+ long d1;
+ long d2;
+ long d3;
+
+ for(i = 0; i < len; i += 4) {
+ d0 = ((const long*) sector)[i + 0];
+ d1 = ((const long*) sector)[i + 1];
+ d2 = ((const long*) sector)[i + 2];
+ d3 = ((const long*) sector)[i + 3];
+
+ if (d0 || d1 || d2 || d3)
return 1;
}
+
return 0;
}
--
1.7.4.1
next reply other threads:[~2011-05-17 14:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-17 14:33 Dmitry Konishchev [this message]
2011-05-17 15:35 ` [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization Stefan Hajnoczi
2011-05-18 6:55 ` Dmitry Konishchev
2011-05-18 7:57 ` Stefan Hajnoczi
2011-05-18 8:05 ` Kevin Wolf
2011-05-18 9:18 ` Dmitry Konishchev
2011-05-18 9:31 ` Kevin Wolf
2011-05-18 10:27 ` Dmitry Konishchev
2011-05-18 11:03 ` [Qemu-devel] [PATCH] is_not_zero() optimization in qemu-img Dmitry Konishchev
2011-05-18 12:14 ` Kevin Wolf
2011-05-18 9:40 ` [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization Peter Maydell
2011-05-18 9:40 ` Peter Maydell
2011-05-18 10:27 ` Dmitry Konishchev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='BANLkTinHhx5jTgcH-cytci=fNdk2V7zssg@mail.gmail.com' \
--to=konishchev@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=stanislav.ievlev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).