From: Fam Zheng <famz@redhat.com>
To: Chunyan Liu <cyliu@suse.com>, qemu-devel@nongnu.org
Cc: stefanha@gmail.com
Subject: Re: [Qemu-devel] [PATCH] qemu-img create: set nocow flag by default
Date: Tue, 12 Nov 2013 14:15:26 +0800 [thread overview]
Message-ID: <5281C77E.4080108@redhat.com> (raw)
In-Reply-To: <1383811709-32203-1-git-send-email-cyliu@suse.com>
On 2013年11月07日 16:08, Chunyan Liu wrote:
> Set NOCOW flag to newly created images to solve performance issues on btrfs.
>
> Btrfs has terrible performance when hosting VM images, even more when the guest
> in those VM are also using btrfs as file system. One way to mitigate this bad
> performance is to turn off COW attributes on VM files (since having copy on
> write for this kind of data is not useful).
>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> qemu-img.c | 15 +++++++++++++++
> 1 files changed, 15 insertions(+), 0 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index bf3fb4f..d43e8f1 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -34,11 +34,17 @@
> #include <getopt.h>
> #include <stdio.h>
> #include <stdarg.h>
> +#include <linux/fs.h>
> +#include <sys/ioctl.h>
This should be in #ifdef to not break build on Windows.
> #ifdef _WIN32
> #include <windows.h>
> #endif
>
> +#ifndef FS_NOCOW_FL
> +#define FS_NOCOW_FL 0x00800000 /* Do not cow file */
> +#endif
> +
> typedef struct img_cmd_t {
> const char *name;
> int (*handler)(int argc, char **argv);
> @@ -340,6 +346,7 @@ static int img_create(int argc, char **argv)
> char *options = NULL;
> Error *local_err = NULL;
> bool quiet = false;
> + int fd, attr;
>
> for(;;) {
> c = getopt(argc, argv, "F:b:f:he6o:q");
> @@ -417,6 +424,14 @@ static int img_create(int argc, char **argv)
> return 1;
> }
>
> + /* set NOCOW by default to solve performance issue on btrfs */
> + fd = qemu_open(filename, O_RDONLY|O_NONBLOCK);
> + if (fd >= 0) {
> + attr = FS_NOCOW_FL;
> + ioctl(fd, FS_IOC_SETFLAGS, &attr);
> + qemu_close(fd);
> + }
> +
> return 0;
> }
>
>
"man chattr" says:
... For btrfs, the 'C' flag should be set on new or empty files. If it
is set on a file which already has data blocks, it is undefined when the
blocks assigned to the file will be fully stable...
But you are setting the attr after image creation, so what's the
difference here? just want to make sure this does what's expected.
Thanks,
Fam
next prev parent reply other threads:[~2013-11-12 6:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-07 8:08 [Qemu-devel] [PATCH] qemu-img create: set nocow flag by default Chunyan Liu
2013-11-12 6:15 ` Fam Zheng [this message]
2013-11-12 8:06 ` Chunyan Liu
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=5281C77E.4080108@redhat.com \
--to=famz@redhat.com \
--cc=cyliu@suse.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).