qemu-img: set nocow flag to new file
PATCH v2 1/1 qemu-img: set nocow flag to new file
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).
--- block/raw-posix.c | 12 ++++++++++++ block/vdi.c | 13 +++++++++++++ block/vmdk.c | 13 +++++++++++++ include/qemu-common.h | 9 +++++++++ 4 files changed, 47 insertions(+), 0 deletions(-)
block/raw-posix.c +12 -0
@@ -1072,6 +1072,18 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, result = -errno;error_setg_errno (errp, -result,"Could not create file" ); }else { +#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 if (ftruncate (fd, total_size *BDRV_SECTOR_SIZE ) !=0 ) { result = -errno;error_setg_errno (errp, -result,"Could not resize file" );
block/vdi.c +13 -0
@@ -686,6 +686,19 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options, 0644);if (fd <0 ) {return -errno; + }else { +#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 }/* We need enough blocks to store the given disk size,
block/vmdk.c +13 -0
@@ -1447,6 +1447,19 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, 0644);if (fd <0 ) {return -errno; + }else { +#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 }if (flat) { ret =ftruncate (fd, filesize);
include/qemu-common.h +9 -0
@@ -50,6 +50,15 @@#include "sysemu/os-posix.h" #endif +#ifdef __linux__ +#include <linux/fs.h> +#include <sys/ioctl.h> + +#ifndef FS_NOCOW_FL +#define FS_NOCOW_FL 0x00800000/* Do not cow file */ +#endif +#endif +#ifndef O_LARGEFILE #define O_LARGEFILE 0#endif
Signature · 1 line
1.6.0.2
Am 15.11.2013 um 06:01 hat Chunyan Liu geschrieben:
Quoted 19 lines
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 <[email protected]>include/qemu-common.h +2
-0@@ -50,6 +50,15 @@#include "sysemu/os-posix.h" #endif +#ifdef __linux__ +#include <linux/fs.h>
include/qemu-common.h line 64
Quoted 10 lines
include/qemu-common.h +7
-0+#include <sys/ioctl.h> + +#ifndef FS_NOCOW_FL +#define FS_NOCOW_FL 0x00800000/* Do not cow file */ +#endif +#endif +#ifndef O_LARGEFILE #define O_LARGEFILE 0#endif
hw/block/m25p80.c:219: Fehler: expected identifier before numeric constant
On RHEL 6, there seems to be a naming conflict for READ, which is present in linux/fs.h and used as a local enum value by m25p80.c.
Kevin
2013/11/15 Kevin Wolf <[email protected]>
Quoted 37 lines
Am 15.11.2013 um 06:01 hat Chunyan Liu geschrieben:
Quoted 1 line
Set NOCOW flag to newly created images to solve performance issues on
btrfs.
Quoted 2 lines
Btrfs has terrible performance when hosting VM images, even more when
the guest
Quoted 1 line
in those VM are also using btrfs as file system. One way to mitigate
this bad
Quoted 1 line
performance is to turn off COW attributes on VM files (since having copy
on
Quoted 14 lines
write for this kind of data is not useful).
Signed-off-by Chunyan Liu <[email protected]>include/qemu-common.h +2
-0@@ -50,6 +50,15 @@#include "sysemu/os-posix.h" #endif +#ifdef __linux__ +#include <linux/fs.h> include/qemu-common.h line 64
Quoted 10 lines
include/qemu-common.h +7
-0+#include <sys/ioctl.h> + +#ifndef FS_NOCOW_FL +#define FS_NOCOW_FL 0x00800000/* Do not cow file */ +#endif +#endif +#ifndef O_LARGEFILE #define O_LARGEFILE 0#endif
hw/block/m25p80.c:219: Fehler: expected identifier before numeric constant
Quoted 4 lines
On RHEL 6, there seems to be a naming conflict for READ, which is present in
linux/fs.hand used as a local enum value bym25p80.c.Will update for this and GETFLAGS & SETFLAGS.
Thanks,
Chunyan
Quoted 3 lines
Kevin