From: Eric Blake <eblake@redhat.com>
To: Chunyan Liu <cyliu@suse.com>, qemu-devel@nongnu.org
Cc: stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH V3] qemu-img create: add 'nocow' option
Date: Tue, 01 Jul 2014 15:02:04 -0600 [thread overview]
Message-ID: <53B321CC.7070300@redhat.com> (raw)
In-Reply-To: <1403515022-24802-1-git-send-email-cyliu@suse.com>
[-- Attachment #1: Type: text/plain, Size: 5376 bytes --]
On 06/23/2014 03:17 AM, Chunyan Liu wrote:
> Add 'nocow' option so that users could have a chance to set NOCOW flag to
> newly created files. It's useful on btrfs file system to enhance performance.
>
> Btrfs has low 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. Generally, there are
> two ways to turn off NOCOW on btrfs: a) by mounting fs with nodatacow, then
> all newly created files will be NOCOW. b) per file. Add the NOCOW file
> attribute. It could only be done to empty or new files.
>
> This patch tries the second way, according to the option, it could add NOCOW
> per file.
>
> For most block drivers, since the create file step is in raw-posix.c, so we
> can do setting NOCOW flag ioctl in raw-posix.c only.
>
> But there are some exceptions, like block/vpc.c and block/vdi.c, they are
> creating file by calling qemu_open directly. For them, do the same setting
> NOCOW flag ioctl work in them separately.
Design question (not a patch review):
It looks like your patch allows one to set the NOCOW flag via ioctl when
requested. But how does one learn if the flag is already set? Can you
update 'qemu-img info' to show whether a file currently has the flag
set? Can 'qemu-img amend' be taught to set and/or clear the flag on an
already existing file?
> @@ -1291,6 +1296,21 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
> result = -errno;
> error_setg_errno(errp, -result, "Could not create file");
> } else {
> + if (nocow) {
> +#ifdef __linux__
> + /* Set NOCOW flag to solve performance issue on fs like btrfs.
> + * This is an optimisation. The FS_IOC_SETFLAGS ioctl return value
> + * will be ignored since any failure of this operation should not
> + * block the left work.
> + */
> + int attr;
> + if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0) {
> + attr |= FS_NOCOW_FL;
> + ioctl(fd, FS_IOC_SETFLAGS, &attr);
> + }
> +#endif
> + }
This silently ignores the nocow flag on non-Linux. Wouldn't it be
better to reject the option as unsupported?
What happens if the ioctl fails? Would it be better to fail the
qemu-img creation if the flag is requested but can't be honored?
> +++ b/qemu-doc.texi
> @@ -589,6 +589,22 @@ check -r all} is required, which may take some time.
>
> This option can only be enabled if @code{compat=1.1} is specified.
>
> +@item nocow
> +If this option is set to @code{on}, it will trun off COW of the file. It's only
s/trun/turn/
> +valid on btrfs, no effect on other file systems.
This sort of statement may get stale, if other file systems learn to
honor the same ioctl as btrfs.
> +
> +Btrfs has low performance when hosting a VM image file, even more when the guest
> +on the VM also using btrfs as file system. Turning off COW is a way to mitigate
> +this bad performance. Generally there are two ways to turn off COW on btrfs:
> +a) Disable it by mounting with nodatacow, then all newly created files will be
> +NOCOW. b) For an empty file, add the NOCOW file attribute. That's what this option
> +does.
> +
> +Note: this option is only valid to new or empty files. If there is an existing
> +file which is COW and has data blocks already, it couldn't be changed to NOCOW
> +by setting @code{nocow=on}. One can issue @code{lsattr filename} to check if
> +the NOCOW flag is set or not (Capitabl 'C' is NOCOW flag).
s/Capitabl/Capital/
Oh, so it looks like setting the attribute is one-way, and can't be
undone once something is written? Or is it that it can only be set on
an empty file, but can be cleared at any time?
Again, making people refer to lsattr to learn if the flag is already set
seems painful; can qemu-img info be taught to expose this information,
so that one tool is sufficient to manage the entire experience?
> +++ b/qemu-img.texi
> @@ -474,6 +474,22 @@ check -r all} is required, which may take some time.
>
> This option can only be enabled if @code{compat=1.1} is specified.
>
> +@item nocow
> +If this option is set to @code{on}, it will trun off COW of the file. It's only
s/trun/turn/
> +valid on btrfs, no effect on other file systems.
> +
> +Btrfs has low performance when hosting a VM image file, even more when the guest
> +on the VM also using btrfs as file system. Turning off COW is a way to mitigate
> +this bad performance. Generally there are two ways to turn off COW on btrfs:
> +a) Disable it by mounting with nodatacow, then all newly created files will be
> +NOCOW. b) For an empty file, add the NOCOW file attribute. That's what this option
> +does.
> +
> +Note: this option is only valid to new or empty files. If there is an existing
> +file which is COW and has data blocks already, it couldn't be changed to NOCOW
> +by setting @code{nocow=on}. One can issue @code{lsattr filename} to check if
> +the NOCOW flag is set or not (Capitabl 'C' is NOCOW flag).
s/Capitabl/Capital/
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2014-07-01 21:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-23 9:17 [Qemu-devel] [PATCH V3] qemu-img create: add 'nocow' option Chunyan Liu
2014-06-27 3:36 ` Chun Yan Liu
2014-06-27 11:48 ` Stefan Hajnoczi
2014-06-30 4:50 ` Chun Yan Liu
2014-07-01 21:02 ` Eric Blake [this message]
2014-07-02 3:03 ` Chun Yan 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=53B321CC.7070300@redhat.com \
--to=eblake@redhat.com \
--cc=cyliu@suse.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).