Skip to contentSkip to conversation

block/file-posix: Work around XFS bug

RFC In review Max Reitz 8 participants 47 messages Oct 25, 2019 – Nov 4, 2019 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

cover block/file-posix: Work around XFS bug

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
I don’t know how we would go about this, so this series doesn’t do it. (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS. The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

Advantages:
+ Maybe simpler, depending on how difficult it is to handle the layering violation
+ Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

Disadvantages:
- Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
- We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f. To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do? Is (1) really the best choice?

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time. (Without this series, it fails like every other time.)

Max Reitz (3):
block: Make wait/mark serialising requests public block/file-posix: Detect XFS with CONFIG_FALLOCATE block/file-posix: Let post-EOF fallocate serialize

 include/block/block_int.h |  3 +++
 block/file-posix.c        | 46 +++++++++++++++++++++++++++++++++++++--
 block/io.c                | 24 ++++++++++----------
 3 files changed, 59 insertions(+), 14 deletions(-)
Signature · 1 line
2.21.0
author
#1 lore raw

RFC 1/3 block: Make wait/mark serialising requests public

Make both bdrv_mark_request_serialising() and bdrv_wait_serialising_requests() public so they can be used from block drivers.

---
 include/block/block_int.h |  3 +++
 block/io.c                | 24 ++++++++++++------------
 2 files changed, 15 insertions(+), 12 deletions(-)
include/block/block_int.h +3 -0
index ca4ccac4c1..c85733293d 100644
@@ -984,6 +984,9 @@ extern unsigned int bdrv_drain_all_count;
 void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_parent);
 void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_parent);
 
+bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self);
+void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align);
+
 int get_tmp_filename(char *filename, int size);
 BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,
                             const char *filename);
block/io.c +12 -12
index f0b86c1d19..a65cc7fb61 100644
@@ -715,7 +715,7 @@ static void tracked_request_begin(BdrvTrackedRequest *req,
     qemu_co_mutex_unlock(&bs->reqs_lock);
 }
 
-static void mark_request_serialising(BdrvTrackedRequest *req, uint64_t align)
+void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align)
 {
     int64_t overlap_offset = req->offset & ~(align - 1);
     uint64_t overlap_bytes = ROUND_UP(req->offset + req->bytes, align)
@@ -805,7 +805,7 @@ void bdrv_dec_in_flight(BlockDriverState *bs)
     bdrv_wakeup(bs);
 }
 
-static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
+bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self)
 {
     BlockDriverState *bs = self->bs;
     BdrvTrackedRequest *req;
@@ -1437,14 +1437,14 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
          * with each other for the same cluster.  For example, in copy-on-read
          * it ensures that the CoR read and write operations are atomic and
          * guest writes cannot interleave between them. */
-        mark_request_serialising(req, bdrv_get_cluster_size(bs));
+        bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs));
     }
 
     /* BDRV_REQ_SERIALISING is only for write operation */
     assert(!(flags & BDRV_REQ_SERIALISING));
 
     if (!(flags & BDRV_REQ_NO_SERIALISING)) {
-        wait_serialising_requests(req);
+        bdrv_wait_serialising_requests(req);
     }
 
     if (flags & BDRV_REQ_COPY_ON_READ) {
@@ -1841,10 +1841,10 @@ bdrv_co_write_req_prepare(BdrvChild *child, int64_t offset, uint64_t bytes,
     assert(!(flags & ~BDRV_REQ_MASK));
 
     if (flags & BDRV_REQ_SERIALISING) {
-        mark_request_serialising(req, bdrv_get_cluster_size(bs));
+        bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs));
     }
 
-    waited = wait_serialising_requests(req);
+    waited = bdrv_wait_serialising_requests(req);
 
     assert(!waited || !req->serialising ||
            is_request_serialising_and_aligned(req));
@@ -2008,8 +2008,8 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child,
 
     padding = bdrv_init_padding(bs, offset, bytes, &pad);
     if (padding) {
-        mark_request_serialising(req, align);
-        wait_serialising_requests(req);
+        bdrv_mark_request_serialising(req, align);
+        bdrv_wait_serialising_requests(req);
 
         bdrv_padding_rmw_read(child, req, &pad, true);
 
@@ -2111,8 +2111,8 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
     }
 
     if (bdrv_pad_request(bs, &qiov, &qiov_offset, &offset, &bytes, &pad)) {
-        mark_request_serialising(&req, align);
-        wait_serialising_requests(&req);
+        bdrv_mark_request_serialising(&req, align);
+        bdrv_wait_serialising_requests(&req);
         bdrv_padding_rmw_read(child, &req, &pad, false);
     }
 
@@ -3205,7 +3205,7 @@ static int coroutine_fn bdrv_co_copy_range_internal(
         /* BDRV_REQ_SERIALISING is only for write operation */
         assert(!(read_flags & BDRV_REQ_SERIALISING));
         if (!(read_flags & BDRV_REQ_NO_SERIALISING)) {
-            wait_serialising_requests(&req);
+            bdrv_wait_serialising_requests(&req);
         }
 
         ret = src->bs->drv->bdrv_co_copy_range_from(src->bs,
@@ -3332,7 +3332,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset,
      * new area, we need to make sure that no write requests are made to it
      * concurrently or they might be overwritten by preallocation. */
     if (new_bytes) {
-        mark_request_serialising(&req, 1);
+        bdrv_mark_request_serialising(&req, 1);
     }
     if (bs->read_only) {
         error_setg(errp, "Image is read-only");
Signature · 1 line
2.21.0
author
#2 lore raw

RFC 2/3 block/file-posix: Detect XFS with CONFIG_FALLOCATE

In reply to Max Reitz

We will need this for the next patch.

---
 block/file-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/file-posix.c +2 -2
index 695fcf740d..5cd54c8bff 100644
@@ -149,7 +149,7 @@ typedef struct BDRVRawState {
     int perm_change_flags;
     BDRVReopenState *reopen_state;
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     bool is_xfs:1;
 #endif
     bool has_discard:1;
@@ -667,7 +667,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
 #endif
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     if (platform_test_xfs_fd(s->fd)) {
         s->is_xfs = true;
     }
Signature · 1 line
2.21.0
#3 lore raw

Re: [RFC 2/3] block/file-posix: Detect XFS with CONFIG_FALLOCATE

Am 25.10.2019 um 11:58 hat Max Reitz geschrieben:

Quoted 21 lines

We will need this for the next patch.

---
 block/file-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/file-posix.c +1 -1
index 695fcf740d..5cd54c8bff 100644
@@ -149,7 +149,7 @@ typedef struct BDRVRawState {
     int perm_change_flags;
     BDRVReopenState *reopen_state;
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     bool is_xfs:1;
 #endif
     bool has_discard:1;

block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 671

Quoted 6 lines
block/file-posix.c +1 -1
@@ -667,7 +667,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
 #endif
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     if (platform_test_xfs_fd(s->fd)) {

platform_test_xfs_fd() is defined in a header file from xfsprogs. I don't think you can call that without CONFIG_XFS, it would break the build.

block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 673

Quoted 2 lines
block/file-posix.c +0 -0
         s->is_xfs = true;
     }

Kevin

author
#4 lore raw

Re: [RFC 2/3] block/file-posix: Detect XFS with CONFIG_FALLOCATE

Quoted 25 lines · Kevin Wolf

Am 25.10.2019 um 11:58 hat Max Reitz geschrieben:

Quoted 24 lines

We will need this for the next patch.

---
 block/file-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/file-posix.c +1 -1
index 695fcf740d..5cd54c8bff 100644
@@ -149,7 +149,7 @@ typedef struct BDRVRawState {
     int perm_change_flags;
     BDRVReopenState *reopen_state;
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     bool is_xfs:1;
 #endif
     bool has_discard:1;
@@ -667,7 +667,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
 #endif
 
Quoted 7 lines

block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 671

Quoted 3 lines
block/file-posix.c +1 -1
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     if (platform_test_xfs_fd(s->fd)) {

platform_test_xfs_fd() is defined in a header file from xfsprogs. I don't think you can call that without CONFIG_XFS, it would break the build.

Aw.

OK. Should we then just assume is_xfs to be true (for the next patch) with !defined(CONFIG_XFS) && defined(CONFIG_FALLOCATE)?

Max

#5 lore raw

Re: [RFC 2/3] block/file-posix: Detect XFS with CONFIG_FALLOCATE

Am 25.10.2019 um 12:22 hat Max Reitz geschrieben:

Quoted 34 lines · Kevin Wolf
Quoted 25 lines

Am 25.10.2019 um 11:58 hat Max Reitz geschrieben:

Quoted 24 lines

We will need this for the next patch.

---
 block/file-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/file-posix.c +1 -1
index 695fcf740d..5cd54c8bff 100644
@@ -149,7 +149,7 @@ typedef struct BDRVRawState {
     int perm_change_flags;
     BDRVReopenState *reopen_state;
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     bool is_xfs:1;
 #endif
     bool has_discard:1;
@@ -667,7 +667,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
 #endif
 
Quoted 7 lines

block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 671

Quoted 3 lines
block/file-posix.c +1 -1
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     if (platform_test_xfs_fd(s->fd)) {

platform_test_xfs_fd() is defined in a header file from xfsprogs. I don't think you can call that without CONFIG_XFS, it would break the build.

Quoted 4 lines

Aw.

OK. Should we then just assume is_xfs to be true (for the next patch) with !defined(CONFIG_XFS) && defined(CONFIG_FALLOCATE)?

It's a small inline function that basically just calls statfs() and then checks f_type.

I think we can have a small function to implement this in the file-posix code. Don't copy it from the header because of licensing (LGPL, while file-posix is MIT); refer to the statfs() manpage instead and write it yourself.

Kevin

author
#6 lore raw

Re: [RFC 2/3] block/file-posix: Detect XFS with CONFIG_FALLOCATE

Quoted 35 lines · Kevin Wolf

Am 25.10.2019 um 12:22 hat Max Reitz geschrieben:

Quoted 34 lines · Kevin Wolf
Quoted 32 lines

Am 25.10.2019 um 11:58 hat Max Reitz geschrieben:

Quoted 21 lines

We will need this for the next patch.

---
 block/file-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/file-posix.c +1 -1
index 695fcf740d..5cd54c8bff 100644
@@ -149,7 +149,7 @@ typedef struct BDRVRawState {
     int perm_change_flags;
     BDRVReopenState *reopen_state;
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     bool is_xfs:1;
 #endif
     bool has_discard:1;

block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 671

Quoted 6 lines
block/file-posix.c +1 -1
@@ -667,7 +667,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
 #endif
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     if (platform_test_xfs_fd(s->fd)) {

platform_test_xfs_fd() is defined in a header file from xfsprogs. I don't think you can call that without CONFIG_XFS, it would break the build.

Quoted 7 lines
Quoted 4 lines

Aw.

OK. Should we then just assume is_xfs to be true (for the next patch) with !defined(CONFIG_XFS) && defined(CONFIG_FALLOCATE)?

It's a small inline function that basically just calls statfs() and then checks f_type.

Yes, this is where my error came from. I asked cscope, which happily referred me to the inline implementation and so I didn’t bother looking at the filename and just assumed it’d be some code that belongs to qemu.

Quoted 4 lines

I think we can have a small function to implement this in the file-posix code. Don't copy it from the header because of licensing (LGPL, while file-posix is MIT); refer to the statfs() manpage instead and write it yourself.

OK.

Max

#7 lore raw

Re: [RFC 2/3] block/file-posix: Detect XFS with CONFIG_FALLOCATE

In reply to Max Reitz
Quoted 22 lines · Max Reitz

We will need this for the next patch.

---
 block/file-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/file-posix.c +1 -1
index 695fcf740d..5cd54c8bff 100644
@@ -149,7 +149,7 @@ typedef struct BDRVRawState {
     int perm_change_flags;
     BDRVReopenState *reopen_state;
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     bool is_xfs:1;
 #endif
     bool has_discard:1;

block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 672

Quoted 7 lines
block/file-posix.c +1 -1
@@ -667,7 +667,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     }
 #endif
 
-#ifdef CONFIG_XFS
+#if defined(CONFIG_XFS) || defined(CONFIG_FALLOCATE)
     if (platform_test_xfs_fd(s->fd)) {
         s->is_xfs = true;

What about remote xfs filesystem, e.g. glusterfs over xfs mounted using fuse? (how oVirt uses glusterfs)

The buggy behavior with concurrent fallocate/pwrite can affect this, and platform_test_xfs_fd() will probably fail to detect xfs.

Nir

Quoted 5 lines
block/file-posix.c +0 -1
     }
--

2.21.0

author
#8 lore raw

RFC 3/3 block/file-posix: Let post-EOF fallocate serialize

In reply to Max Reitz

The XFS kernel driver has a bug that may cause data corruption for qcow2 images as of qemu commit c8bb23cbdbe32f. We can work around it by treating post-EOF fallocates as serializing up until infinity (INT64_MAX in practice).

---
 block/file-posix.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
block/file-posix.c +42 -0
index 5cd54c8bff..1f5a01df70 100644
@@ -2713,6 +2713,48 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes,
     RawPosixAIOData acb;
     ThreadPoolFunc *handler;
 
+#ifdef CONFIG_FALLOCATE
+    if (s->is_xfs && s->use_linux_aio &&
+        offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE)
+    {
+        BdrvTrackedRequest *req;
+        uint64_t end;
+
+        /*
+         * The Linux XFS driver has a bug where it will discard writes
+         * submitted through the AIO interface if they happen beyond a
+         * concurrently running fallocate() that increases the file
+         * length (i.e., both the write and the fallocate() happen
+         * beyond the EOF).
+         *
+         * To work around it, we look for the tracked request for this
+         * zero write, extend it until INT64_MAX (effectively
+         * infinity), and mark it as serializing.
+         *
+         * TODO: Detect whether this has been fixed in the XFS driver.
+         */
+
+        QLIST_FOREACH(req, &bs->tracked_requests, list) {
+            if (req->co == qemu_coroutine_self() &&
+                req->type == BDRV_TRACKED_WRITE)
+            {
+                break;
+            }
+        }
+
+        assert(req);
+        assert(req->offset <= offset);
+        assert(req->offset + req->bytes >= offset + bytes);
+
+        end = INT64_MAX & -(uint64_t)bs->bl.request_alignment;
+        req->bytes = end - req->offset;
+        req->overlap_bytes = req->bytes;
+
+        bdrv_mark_request_serialising(req, bs->bl.request_alignment);
+        bdrv_wait_serialising_requests(req);
+    }
+#endif
+
     acb = (RawPosixAIOData) {
         .bs             = bs,
         .aio_fildes     = s->fd,
Signature · 1 line
2.21.0
#9 lore raw

Re: [RFC 3/3] block/file-posix: Let post-EOF fallocate serialize

Quoted 16 lines · Max Reitz

The XFS kernel driver has a bug that may cause data corruption for qcow2 images as of qemu commit c8bb23cbdbe32f. We can work around it by treating post-EOF fallocates as serializing up until infinity (INT64_MAX in practice).

---
 block/file-posix.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
block/file-posix.c +0 -0
index 5cd54c8bff..1f5a01df70 100644

block/file-posix.c raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, · line 2717

Quoted 5 lines
block/file-posix.c +2 -0
@@ -2713,6 +2713,48 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes,
     RawPosixAIOData acb;
     ThreadPoolFunc *handler;
 
+#ifdef CONFIG_FALLOCATE
+    if (s->is_xfs && s->use_linux_aio &&

This limit the fix to local xfs filesystem, but the fix may be needed to remote filesystem such
as gluster over xfs.

Quoted 47 lines
block/file-posix.c +40 -1
+        offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE)
+    {
+        BdrvTrackedRequest *req;
+        uint64_t end;
+
+        /*
+         * The Linux XFS driver has a bug where it will discard writes
+         * submitted through the AIO interface if they happen beyond a
+         * concurrently running fallocate() that increases the file
+         * length (i.e., both the write and the fallocate() happen
+         * beyond the EOF).
+         *
+         * To work around it, we look for the tracked request for this
+         * zero write, extend it until INT64_MAX (effectively
+         * infinity), and mark it as serializing.
+         *
+         * TODO: Detect whether this has been fixed in the XFS driver.
+         */
+
+        QLIST_FOREACH(req, &bs->tracked_requests, list) {
+            if (req->co == qemu_coroutine_self() &&
+                req->type == BDRV_TRACKED_WRITE)
+            {
+                break;
+            }
+        }
+
+        assert(req);
+        assert(req->offset <= offset);
+        assert(req->offset + req->bytes >= offset + bytes);
+
+        end = INT64_MAX & -(uint64_t)bs->bl.request_alignment;
+        req->bytes = end - req->offset;
+        req->overlap_bytes = req->bytes;
+
+        bdrv_mark_request_serialising(req, bs->bl.request_alignment);
+        bdrv_wait_serialising_requests(req);
+    }
+#endif
+
     acb = (RawPosixAIOData) {
         .bs             = bs,
         .aio_fildes     = s->fd,
--

2.21.0

#10 lore raw
In reply to Max Reitz
Quoted 88 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
I don’t know how we would go about this, so this series doesn’t do it. (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS. The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

Advantages:
+ Maybe simpler, depending on how difficult it is to handle the layering violation
+ Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

Disadvantages:
- Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
- We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do? Is (1) really the best choice?

Quoted 7 lines

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time. (Without this series, it fails like every other time.)

Hi!

First, great thanks for your investigation!

We need c8bb23cbdbe3 patch, because we use 1M clusters, and zeroing 1M is significant in time.

I've tested a bit:

test:
for img in /ssd/test.img /test.img; do for cl in 64K 1M; do for step in 4K 64K 1M; do ./qemu-img create -f qcow2 -o cluster_size=$cl $img 15G > /dev/null; printf '%-15s%-7s%-10s : ' $img cl=$cl step=$step; ./qemu-img bench -c $((15 * 1024)) -n -s 4K -S $step -t none -w $img | tail -1 | awk '{print $4}'; done; done; done

on master:

/ssd/test.img  cl=64K step=4K    : 0.291
/ssd/test.img  cl=64K step=64K   : 0.813
/ssd/test.img  cl=64K step=1M    : 2.799
/ssd/test.img  cl=1M  step=4K    : 0.217
/ssd/test.img  cl=1M  step=64K   : 0.332
/ssd/test.img  cl=1M  step=1M    : 0.685
/test.img      cl=64K step=4K    : 1.751
/test.img      cl=64K step=64K   : 14.811
/test.img      cl=64K step=1M    : 18.321
/test.img      cl=1M  step=4K    : 0.759
/test.img      cl=1M  step=64K   : 13.574
/test.img      cl=1M  step=1M    : 28.970

rerun on master:

/ssd/test.img  cl=64K step=4K    : 0.295
/ssd/test.img  cl=64K step=64K   : 0.803
/ssd/test.img  cl=64K step=1M    : 2.921
/ssd/test.img  cl=1M  step=4K    : 0.233
/ssd/test.img  cl=1M  step=64K   : 0.321
/ssd/test.img  cl=1M  step=1M    : 0.762
/test.img      cl=64K step=4K    : 1.873
/test.img      cl=64K step=64K   : 15.621
/test.img      cl=64K step=1M    : 18.428
/test.img      cl=1M  step=4K    : 0.883
/test.img      cl=1M  step=64K   : 13.484
/test.img      cl=1M  step=1M    : 26.244

on master + revert c8bb23cbdbe32f5c326

/ssd/test.img  cl=64K step=4K    : 0.395
/ssd/test.img  cl=64K step=64K   : 4.231
/ssd/test.img  cl=64K step=1M    : 5.598
/ssd/test.img  cl=1M  step=4K    : 0.352
/ssd/test.img  cl=1M  step=64K   : 2.519
/ssd/test.img  cl=1M  step=1M    : 38.919
/test.img      cl=64K step=4K    : 1.758
/test.img      cl=64K step=64K   : 9.838
/test.img      cl=64K step=1M    : 13.384
/test.img      cl=1M  step=4K    : 1.849
/test.img      cl=1M  step=64K   : 19.405
/test.img      cl=1M  step=1M    : 157.090

rerun:

/ssd/test.img  cl=64K step=4K    : 0.407
/ssd/test.img  cl=64K step=64K   : 3.325
/ssd/test.img  cl=64K step=1M    : 5.641
/ssd/test.img  cl=1M  step=4K    : 0.346
/ssd/test.img  cl=1M  step=64K   : 2.583
/ssd/test.img  cl=1M  step=1M    : 39.692
/test.img      cl=64K step=4K    : 1.727
/test.img      cl=64K step=64K   : 10.058
/test.img      cl=64K step=1M    : 13.441
/test.img      cl=1M  step=4K    : 1.926
/test.img      cl=1M  step=64K   : 19.738
/test.img      cl=1M  step=1M    : 158.268

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

Signature · 2 lines
Best regards,
Vladimir
#11 lore raw
Quoted 171 lines · Vladimir Sementsov-Ogievskiy
Quoted 88 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
     I don’t know how we would go about this, so this series doesn’t do it.  (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

     Advantages:
     + Limits the impact to very specific cases
       (And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
     + Works around the bug where it happens, namely in file-posix

     Disadvantages:
     - A bit complex
     - A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS.  The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

     Advantages:
     + Maybe simpler, depending on how difficult it is to handle the layering violation
     + Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

     Disadvantages:
     - Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
     - We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
     To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others.  I concluded that it’s probably worth it because the “some cases” are more likely to occur.

     Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
     (https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/  The report is about 40 % worse performance for an in-guest fio write benchmark.)

     So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is.  How much does performance increase with it actually?  (On non-(ppc64+XFS) machines, obviously)

     Advantages:
     + Trivial
     + No layering violations
     + We wouldn’t need to keep track of whether the kernel bug has been fixed or not
     + Fixes the ppc64+XFS performance problem

     Disadvantages:
     - Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do?  Is (1) really the best choice?

Quoted 7 lines

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time.  (Without this series, it fails like every other time.)

Hi!

First, great thanks for your investigation!

We need c8bb23cbdbe3 patch, because we use 1M clusters, and zeroing 1M is significant in time.

I've tested a bit:

test:
for img in /ssd/test.img /test.img; do for cl in 64K 1M; do for step in 4K 64K 1M; do ./qemu-img create -f qcow2 -o cluster_size=$cl $img 15G > /dev/null; printf '%-15s%-7s%-10s : ' $img cl=$cl step=$step; ./qemu-img bench -c $((15 * 1024)) -n -s 4K -S $step -t none -w $img | tail -1 | awk '{print $4}'; done; done; done

on master:

/ssd/test.img  cl=64K step=4K    : 0.291
/ssd/test.img  cl=64K step=64K   : 0.813
/ssd/test.img  cl=64K step=1M    : 2.799
/ssd/test.img  cl=1M  step=4K    : 0.217
/ssd/test.img  cl=1M  step=64K   : 0.332
/ssd/test.img  cl=1M  step=1M    : 0.685
/test.img      cl=64K step=4K    : 1.751
/test.img      cl=64K step=64K   : 14.811
/test.img      cl=64K step=1M    : 18.321
/test.img      cl=1M  step=4K    : 0.759
/test.img      cl=1M  step=64K   : 13.574
/test.img      cl=1M  step=1M    : 28.970

rerun on master:

/ssd/test.img  cl=64K step=4K    : 0.295
/ssd/test.img  cl=64K step=64K   : 0.803
/ssd/test.img  cl=64K step=1M    : 2.921
/ssd/test.img  cl=1M  step=4K    : 0.233
/ssd/test.img  cl=1M  step=64K   : 0.321
/ssd/test.img  cl=1M  step=1M    : 0.762
/test.img      cl=64K step=4K    : 1.873
/test.img      cl=64K step=64K   : 15.621
/test.img      cl=64K step=1M    : 18.428
/test.img      cl=1M  step=4K    : 0.883
/test.img      cl=1M  step=64K   : 13.484
/test.img      cl=1M  step=1M    : 26.244

on master + revert c8bb23cbdbe32f5c326

/ssd/test.img  cl=64K step=4K    : 0.395
/ssd/test.img  cl=64K step=64K   : 4.231
/ssd/test.img  cl=64K step=1M    : 5.598
/ssd/test.img  cl=1M  step=4K    : 0.352
/ssd/test.img  cl=1M  step=64K   : 2.519
/ssd/test.img  cl=1M  step=1M    : 38.919
/test.img      cl=64K step=4K    : 1.758
/test.img      cl=64K step=64K   : 9.838
/test.img      cl=64K step=1M    : 13.384
/test.img      cl=1M  step=4K    : 1.849
/test.img      cl=1M  step=64K   : 19.405
/test.img      cl=1M  step=1M    : 157.090

rerun:

/ssd/test.img  cl=64K step=4K    : 0.407
/ssd/test.img  cl=64K step=64K   : 3.325
/ssd/test.img  cl=64K step=1M    : 5.641
/ssd/test.img  cl=1M  step=4K    : 0.346
/ssd/test.img  cl=1M  step=64K   : 2.583
/ssd/test.img  cl=1M  step=1M    : 39.692
/test.img      cl=64K step=4K    : 1.727
/test.img      cl=64K step=64K   : 10.058
/test.img      cl=64K step=1M    : 13.441
/test.img      cl=1M  step=4K    : 1.926
/test.img      cl=1M  step=64K   : 19.738
/test.img      cl=1M  step=1M    : 158.268

Quoted 6 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

About degradation in some cases: I think the problem is that one (a bit larger) write may be faster than fast-write-zeroes + small write, as the latter means additional write to metadata. And it's expected for small clusters in conjunction with rotational disk. But the actual limit is dependent on specific disk. So, I think possible solution is just sometimes try work with handle_alloc_space and sometimes without, remember time and length of request and make dynamic limit...

Signature · 2 lines
Best regards,
Vladimir
author
#12 lore raw
Quoted 172 lines · Vladimir Sementsov-Ogievskiy
Quoted 171 lines · Vladimir Sementsov-Ogievskiy
Quoted 88 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
     I don’t know how we would go about this, so this series doesn’t do it.  (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

     Advantages:
     + Limits the impact to very specific cases
       (And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
     + Works around the bug where it happens, namely in file-posix

     Disadvantages:
     - A bit complex
     - A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS.  The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

     Advantages:
     + Maybe simpler, depending on how difficult it is to handle the layering violation
     + Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

     Disadvantages:
     - Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
     - We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
     To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others.  I concluded that it’s probably worth it because the “some cases” are more likely to occur.

     Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
     (https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/  The report is about 40 % worse performance for an in-guest fio write benchmark.)

     So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is.  How much does performance increase with it actually?  (On non-(ppc64+XFS) machines, obviously)

     Advantages:
     + Trivial
     + No layering violations
     + We wouldn’t need to keep track of whether the kernel bug has been fixed or not
     + Fixes the ppc64+XFS performance problem

     Disadvantages:
     - Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do?  Is (1) really the best choice?

Quoted 7 lines

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time.  (Without this series, it fails like every other time.)

Hi!

First, great thanks for your investigation!

We need c8bb23cbdbe3 patch, because we use 1M clusters, and zeroing 1M is significant in time.

I've tested a bit:

test:
for img in /ssd/test.img /test.img; do for cl in 64K 1M; do for step in 4K 64K 1M; do ./qemu-img create -f qcow2 -o cluster_size=$cl $img 15G > /dev/null; printf '%-15s%-7s%-10s : ' $img cl=$cl step=$step; ./qemu-img bench -c $((15 * 1024)) -n -s 4K -S $step -t none -w $img | tail -1 | awk '{print $4}'; done; done; done

on master:

/ssd/test.img  cl=64K step=4K    : 0.291
/ssd/test.img  cl=64K step=64K   : 0.813
/ssd/test.img  cl=64K step=1M    : 2.799
/ssd/test.img  cl=1M  step=4K    : 0.217
/ssd/test.img  cl=1M  step=64K   : 0.332
/ssd/test.img  cl=1M  step=1M    : 0.685
/test.img      cl=64K step=4K    : 1.751
/test.img      cl=64K step=64K   : 14.811
/test.img      cl=64K step=1M    : 18.321
/test.img      cl=1M  step=4K    : 0.759
/test.img      cl=1M  step=64K   : 13.574
/test.img      cl=1M  step=1M    : 28.970

rerun on master:

/ssd/test.img  cl=64K step=4K    : 0.295
/ssd/test.img  cl=64K step=64K   : 0.803
/ssd/test.img  cl=64K step=1M    : 2.921
/ssd/test.img  cl=1M  step=4K    : 0.233
/ssd/test.img  cl=1M  step=64K   : 0.321
/ssd/test.img  cl=1M  step=1M    : 0.762
/test.img      cl=64K step=4K    : 1.873
/test.img      cl=64K step=64K   : 15.621
/test.img      cl=64K step=1M    : 18.428
/test.img      cl=1M  step=4K    : 0.883
/test.img      cl=1M  step=64K   : 13.484
/test.img      cl=1M  step=1M    : 26.244

on master + revert c8bb23cbdbe32f5c326

/ssd/test.img  cl=64K step=4K    : 0.395
/ssd/test.img  cl=64K step=64K   : 4.231
/ssd/test.img  cl=64K step=1M    : 5.598
/ssd/test.img  cl=1M  step=4K    : 0.352
/ssd/test.img  cl=1M  step=64K   : 2.519
/ssd/test.img  cl=1M  step=1M    : 38.919
/test.img      cl=64K step=4K    : 1.758
/test.img      cl=64K step=64K   : 9.838
/test.img      cl=64K step=1M    : 13.384
/test.img      cl=1M  step=4K    : 1.849
/test.img      cl=1M  step=64K   : 19.405
/test.img      cl=1M  step=1M    : 157.090

rerun:

/ssd/test.img  cl=64K step=4K    : 0.407
/ssd/test.img  cl=64K step=64K   : 3.325
/ssd/test.img  cl=64K step=1M    : 5.641
/ssd/test.img  cl=1M  step=4K    : 0.346
/ssd/test.img  cl=1M  step=64K   : 2.583
/ssd/test.img  cl=1M  step=1M    : 39.692
/test.img      cl=64K step=4K    : 1.727
/test.img      cl=64K step=64K   : 10.058
/test.img      cl=64K step=1M    : 13.441
/test.img      cl=1M  step=4K    : 1.926
/test.img      cl=1M  step=64K   : 19.738
/test.img      cl=1M  step=1M    : 158.268

Quoted 5 lines
Quoted 5 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Quoted 7 lines

About degradation in some cases: I think the problem is that one (a bit larger) write may be faster than fast-write-zeroes + small write, as the latter means additional write to metadata. And it's expected for small clusters in conjunction with rotational disk. But the actual limit is dependent on specific disk. So, I think possible solution is just sometimes try work with handle_alloc_space and sometimes without, remember time and length of request and make dynamic limit...

Maybe make a decision based both on the ratio of data size to COW area length (only invoke handle_alloc_space() under a certain threshold), and the absolute COW area length (always invoke it above a certain threshold, unless the ratio doesn’t allow it)?

Max

#13 lore raw
Quoted 173 lines · Max Reitz
Quoted 172 lines · Vladimir Sementsov-Ogievskiy
Quoted 171 lines · Vladimir Sementsov-Ogievskiy
Quoted 88 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
     I don’t know how we would go about this, so this series doesn’t do it.  (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

     Advantages:
     + Limits the impact to very specific cases
       (And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
     + Works around the bug where it happens, namely in file-posix

     Disadvantages:
     - A bit complex
     - A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS.  The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

     Advantages:
     + Maybe simpler, depending on how difficult it is to handle the layering violation
     + Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

     Disadvantages:
     - Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
     - We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
     To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others.  I concluded that it’s probably worth it because the “some cases” are more likely to occur.

     Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
     (https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/  The report is about 40 % worse performance for an in-guest fio write benchmark.)

     So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is.  How much does performance increase with it actually?  (On non-(ppc64+XFS) machines, obviously)

     Advantages:
     + Trivial
     + No layering violations
     + We wouldn’t need to keep track of whether the kernel bug has been fixed or not
     + Fixes the ppc64+XFS performance problem

     Disadvantages:
     - Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do?  Is (1) really the best choice?

Quoted 7 lines

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time.  (Without this series, it fails like every other time.)

Hi!

First, great thanks for your investigation!

We need c8bb23cbdbe3 patch, because we use 1M clusters, and zeroing 1M is significant in time.

I've tested a bit:

test:
for img in /ssd/test.img /test.img; do for cl in 64K 1M; do for step in 4K 64K 1M; do ./qemu-img create -f qcow2 -o cluster_size=$cl $img 15G > /dev/null; printf '%-15s%-7s%-10s : ' $img cl=$cl step=$step; ./qemu-img bench -c $((15 * 1024)) -n -s 4K -S $step -t none -w $img | tail -1 | awk '{print $4}'; done; done; done

on master:

/ssd/test.img  cl=64K step=4K    : 0.291
/ssd/test.img  cl=64K step=64K   : 0.813
/ssd/test.img  cl=64K step=1M    : 2.799
/ssd/test.img  cl=1M  step=4K    : 0.217
/ssd/test.img  cl=1M  step=64K   : 0.332
/ssd/test.img  cl=1M  step=1M    : 0.685
/test.img      cl=64K step=4K    : 1.751
/test.img      cl=64K step=64K   : 14.811
/test.img      cl=64K step=1M    : 18.321
/test.img      cl=1M  step=4K    : 0.759
/test.img      cl=1M  step=64K   : 13.574
/test.img      cl=1M  step=1M    : 28.970

rerun on master:

/ssd/test.img  cl=64K step=4K    : 0.295
/ssd/test.img  cl=64K step=64K   : 0.803
/ssd/test.img  cl=64K step=1M    : 2.921
/ssd/test.img  cl=1M  step=4K    : 0.233
/ssd/test.img  cl=1M  step=64K   : 0.321
/ssd/test.img  cl=1M  step=1M    : 0.762
/test.img      cl=64K step=4K    : 1.873
/test.img      cl=64K step=64K   : 15.621
/test.img      cl=64K step=1M    : 18.428
/test.img      cl=1M  step=4K    : 0.883
/test.img      cl=1M  step=64K   : 13.484
/test.img      cl=1M  step=1M    : 26.244

on master + revert c8bb23cbdbe32f5c326

/ssd/test.img  cl=64K step=4K    : 0.395
/ssd/test.img  cl=64K step=64K   : 4.231
/ssd/test.img  cl=64K step=1M    : 5.598
/ssd/test.img  cl=1M  step=4K    : 0.352
/ssd/test.img  cl=1M  step=64K   : 2.519
/ssd/test.img  cl=1M  step=1M    : 38.919
/test.img      cl=64K step=4K    : 1.758
/test.img      cl=64K step=64K   : 9.838
/test.img      cl=64K step=1M    : 13.384
/test.img      cl=1M  step=4K    : 1.849
/test.img      cl=1M  step=64K   : 19.405
/test.img      cl=1M  step=1M    : 157.090

rerun:

/ssd/test.img  cl=64K step=4K    : 0.407
/ssd/test.img  cl=64K step=64K   : 3.325
/ssd/test.img  cl=64K step=1M    : 5.641
/ssd/test.img  cl=1M  step=4K    : 0.346
/ssd/test.img  cl=1M  step=64K   : 2.583
/ssd/test.img  cl=1M  step=1M    : 39.692
/test.img      cl=64K step=4K    : 1.727
/test.img      cl=64K step=64K   : 10.058
/test.img      cl=64K step=1M    : 13.441
/test.img      cl=1M  step=4K    : 1.926
/test.img      cl=1M  step=64K   : 19.738
/test.img      cl=1M  step=1M    : 158.268

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Very possible, I thought about it too.

Quoted 9 lines
Quoted 8 lines

About degradation in some cases: I think the problem is that one (a bit larger) write may be faster than fast-write-zeroes + small write, as the latter means additional write to metadata. And it's expected for small clusters in conjunction with rotational disk. But the actual limit is dependent on specific disk. So, I think possible solution is just sometimes try work with handle_alloc_space and sometimes without, remember time and length of request and make dynamic limit...

Quoted 5 lines

Maybe make a decision based both on the ratio of data size to COW area length (only invoke handle_alloc_space() under a certain threshold), and the absolute COW area length (always invoke it above a certain threshold, unless the ratio doesn’t allow it)?

Yes, something like this..

without handle_alloc_space, time = time(write aligned up to cluster) with handle_alloc_space, time = time(fast zero write) + time(original write)

If we have some statistics on normal-write vs zero-write timing, we can just calculate both variants and choose faster.

if (predict_zero_write_time(aligned up request) + predict_write_time(request) < predict_write_time(aligned up request)) {
use handle_alloc_space()
}

Signature · 2 lines
Best regards,
Vladimir
#14 lore raw
Quoted 205 lines · Vladimir Sementsov-Ogievskiy
Quoted 173 lines · Max Reitz
Quoted 172 lines · Vladimir Sementsov-Ogievskiy
Quoted 171 lines · Vladimir Sementsov-Ogievskiy
Quoted 88 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
     I don’t know how we would go about this, so this series doesn’t do it.  (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

     Advantages:
     + Limits the impact to very specific cases
       (And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
     + Works around the bug where it happens, namely in file-posix

     Disadvantages:
     - A bit complex
     - A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS.  The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

     Advantages:
     + Maybe simpler, depending on how difficult it is to handle the layering violation
     + Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

     Disadvantages:
     - Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
     - We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
     To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others.  I concluded that it’s probably worth it because the “some cases” are more likely to occur.

     Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
     (https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/  The report is about 40 % worse performance for an in-guest fio write benchmark.)

     So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is.  How much does performance increase with it actually?  (On non-(ppc64+XFS) machines, obviously)

     Advantages:
     + Trivial
     + No layering violations
     + We wouldn’t need to keep track of whether the kernel bug has been fixed or not
     + Fixes the ppc64+XFS performance problem

     Disadvantages:
     - Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do?  Is (1) really the best choice?

Quoted 7 lines

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time.  (Without this series, it fails like every other time.)

Hi!

First, great thanks for your investigation!

We need c8bb23cbdbe3 patch, because we use 1M clusters, and zeroing 1M is significant in time.

I've tested a bit:

test:
for img in /ssd/test.img /test.img; do for cl in 64K 1M; do for step in 4K 64K 1M; do ./qemu-img create -f qcow2 -o cluster_size=$cl $img 15G > /dev/null; printf '%-15s%-7s%-10s : ' $img cl=$cl step=$step; ./qemu-img bench -c $((15 * 1024)) -n -s 4K -S $step -t none -w $img | tail -1 | awk '{print $4}'; done; done; done

on master:

/ssd/test.img  cl=64K step=4K    : 0.291
/ssd/test.img  cl=64K step=64K   : 0.813
/ssd/test.img  cl=64K step=1M    : 2.799
/ssd/test.img  cl=1M  step=4K    : 0.217
/ssd/test.img  cl=1M  step=64K   : 0.332
/ssd/test.img  cl=1M  step=1M    : 0.685
/test.img      cl=64K step=4K    : 1.751
/test.img      cl=64K step=64K   : 14.811
/test.img      cl=64K step=1M    : 18.321
/test.img      cl=1M  step=4K    : 0.759
/test.img      cl=1M  step=64K   : 13.574
/test.img      cl=1M  step=1M    : 28.970

rerun on master:

/ssd/test.img  cl=64K step=4K    : 0.295
/ssd/test.img  cl=64K step=64K   : 0.803
/ssd/test.img  cl=64K step=1M    : 2.921
/ssd/test.img  cl=1M  step=4K    : 0.233
/ssd/test.img  cl=1M  step=64K   : 0.321
/ssd/test.img  cl=1M  step=1M    : 0.762
/test.img      cl=64K step=4K    : 1.873
/test.img      cl=64K step=64K   : 15.621
/test.img      cl=64K step=1M    : 18.428
/test.img      cl=1M  step=4K    : 0.883
/test.img      cl=1M  step=64K   : 13.484
/test.img      cl=1M  step=1M    : 26.244

on master + revert c8bb23cbdbe32f5c326

/ssd/test.img  cl=64K step=4K    : 0.395
/ssd/test.img  cl=64K step=64K   : 4.231
/ssd/test.img  cl=64K step=1M    : 5.598
/ssd/test.img  cl=1M  step=4K    : 0.352
/ssd/test.img  cl=1M  step=64K   : 2.519
/ssd/test.img  cl=1M  step=1M    : 38.919
/test.img      cl=64K step=4K    : 1.758
/test.img      cl=64K step=64K   : 9.838
/test.img      cl=64K step=1M    : 13.384
/test.img      cl=1M  step=4K    : 1.849
/test.img      cl=1M  step=64K   : 19.405
/test.img      cl=1M  step=1M    : 157.090

rerun:

/ssd/test.img  cl=64K step=4K    : 0.407
/ssd/test.img  cl=64K step=64K   : 3.325
/ssd/test.img  cl=64K step=1M    : 5.641
/ssd/test.img  cl=1M  step=4K    : 0.346
/ssd/test.img  cl=1M  step=64K   : 2.583
/ssd/test.img  cl=1M  step=1M    : 39.692
/test.img      cl=64K step=4K    : 1.727
/test.img      cl=64K step=64K   : 10.058
/test.img      cl=64K step=1M    : 13.441
/test.img      cl=1M  step=4K    : 1.926
/test.img      cl=1M  step=64K   : 19.738
/test.img      cl=1M  step=1M    : 158.268

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Very possible, I thought about it too.

Quoted 9 lines
Quoted 8 lines

About degradation in some cases: I think the problem is that one (a bit larger) write may be faster than fast-write-zeroes + small write, as the latter means additional write to metadata. And it's expected for small clusters in conjunction with rotational disk. But the actual limit is dependent on specific disk. So, I think possible solution is just sometimes try work with handle_alloc_space and sometimes without, remember time and length of request and make dynamic limit...

Quoted 5 lines

Maybe make a decision based both on the ratio of data size to COW area length (only invoke handle_alloc_space() under a certain threshold), and the absolute COW area length (always invoke it above a certain threshold, unless the ratio doesn’t allow it)?

Yes, something like this..

without handle_alloc_space, time = time(write aligned up to cluster) with handle_alloc_space, time = time(fast zero write) + time(original write)

Quoted 6 lines

If we have some statistics on normal-write vs zero-write timing, we can just calculate both variants and choose faster.

if (predict_zero_write_time(aligned up request) + predict_write_time(request) < predict_write_time(aligned up request)) {
use handle_alloc_space()
}

Self-tuning based on request latency works great on a quiet host. If there are other processes submitting I/O to the disk then measured latencies may be bogus.

Stefan

#15 lore raw
In reply to Max Reitz

Am 25.10.2019 um 16:19 hat Max Reitz geschrieben:

Quoted 190 lines · Vladimir Sementsov-Ogievskiy
Quoted 172 lines
Quoted 171 lines · Vladimir Sementsov-Ogievskiy
Quoted 88 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
     I don’t know how we would go about this, so this series doesn’t do it.  (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

     Advantages:
     + Limits the impact to very specific cases
       (And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
     + Works around the bug where it happens, namely in file-posix

     Disadvantages:
     - A bit complex
     - A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS.  The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

     Advantages:
     + Maybe simpler, depending on how difficult it is to handle the layering violation
     + Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

     Disadvantages:
     - Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
     - We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
     To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others.  I concluded that it’s probably worth it because the “some cases” are more likely to occur.

     Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
     (https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/  The report is about 40 % worse performance for an in-guest fio write benchmark.)

     So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is.  How much does performance increase with it actually?  (On non-(ppc64+XFS) machines, obviously)

     Advantages:
     + Trivial
     + No layering violations
     + We wouldn’t need to keep track of whether the kernel bug has been fixed or not
     + Fixes the ppc64+XFS performance problem

     Disadvantages:
     - Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

So this is the main reason this is an RFC: What should we do?  Is (1) really the best choice?

Quoted 7 lines

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time.  (Without this series, it fails like every other time.)

Hi!

First, great thanks for your investigation!

We need c8bb23cbdbe3 patch, because we use 1M clusters, and zeroing 1M is significant in time.

I've tested a bit:

test:
for img in /ssd/test.img /test.img; do for cl in 64K 1M; do for step in 4K 64K 1M; do ./qemu-img create -f qcow2 -o cluster_size=$cl $img 15G > /dev/null; printf '%-15s%-7s%-10s : ' $img cl=$cl step=$step; ./qemu-img bench -c $((15 * 1024)) -n -s 4K -S $step -t none -w $img | tail -1 | awk '{print $4}'; done; done; done

on master:

/ssd/test.img  cl=64K step=4K    : 0.291
/ssd/test.img  cl=64K step=64K   : 0.813
/ssd/test.img  cl=64K step=1M    : 2.799
/ssd/test.img  cl=1M  step=4K    : 0.217
/ssd/test.img  cl=1M  step=64K   : 0.332
/ssd/test.img  cl=1M  step=1M    : 0.685
/test.img      cl=64K step=4K    : 1.751
/test.img      cl=64K step=64K   : 14.811
/test.img      cl=64K step=1M    : 18.321
/test.img      cl=1M  step=4K    : 0.759
/test.img      cl=1M  step=64K   : 13.574
/test.img      cl=1M  step=1M    : 28.970

rerun on master:

/ssd/test.img  cl=64K step=4K    : 0.295
/ssd/test.img  cl=64K step=64K   : 0.803
/ssd/test.img  cl=64K step=1M    : 2.921
/ssd/test.img  cl=1M  step=4K    : 0.233
/ssd/test.img  cl=1M  step=64K   : 0.321
/ssd/test.img  cl=1M  step=1M    : 0.762
/test.img      cl=64K step=4K    : 1.873
/test.img      cl=64K step=64K   : 15.621
/test.img      cl=64K step=1M    : 18.428
/test.img      cl=1M  step=4K    : 0.883
/test.img      cl=1M  step=64K   : 13.484
/test.img      cl=1M  step=1M    : 26.244

on master + revert c8bb23cbdbe32f5c326

/ssd/test.img  cl=64K step=4K    : 0.395
/ssd/test.img  cl=64K step=64K   : 4.231
/ssd/test.img  cl=64K step=1M    : 5.598
/ssd/test.img  cl=1M  step=4K    : 0.352
/ssd/test.img  cl=1M  step=64K   : 2.519
/ssd/test.img  cl=1M  step=1M    : 38.919
/test.img      cl=64K step=4K    : 1.758
/test.img      cl=64K step=64K   : 9.838
/test.img      cl=64K step=1M    : 13.384
/test.img      cl=1M  step=4K    : 1.849
/test.img      cl=1M  step=64K   : 19.405
/test.img      cl=1M  step=1M    : 157.090

rerun:

/ssd/test.img  cl=64K step=4K    : 0.407
/ssd/test.img  cl=64K step=64K   : 3.325
/ssd/test.img  cl=64K step=1M    : 5.641
/ssd/test.img  cl=1M  step=4K    : 0.346
/ssd/test.img  cl=1M  step=64K   : 2.583
/ssd/test.img  cl=1M  step=1M    : 39.692
/test.img      cl=64K step=4K    : 1.727
/test.img      cl=64K step=64K   : 10.058
/test.img      cl=64K step=1M    : 13.441
/test.img      cl=1M  step=4K    : 1.926
/test.img      cl=1M  step=64K   : 19.738
/test.img      cl=1M  step=1M    : 158.268

Quoted 5 lines
Quoted 5 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Quoted 7 lines

About degradation in some cases: I think the problem is that one (a bit larger) write may be faster than fast-write-zeroes + small write, as the latter means additional write to metadata. And it's expected for small clusters in conjunction with rotational disk. But the actual limit is dependent on specific disk. So, I think possible solution is just sometimes try work with handle_alloc_space and sometimes without, remember time and length of request and make dynamic limit...

Quoted 4 lines

Maybe make a decision based both on the ratio of data size to COW area length (only invoke handle_alloc_space() under a certain threshold), and the absolute COW area length (always invoke it above a certain threshold, unless the ratio doesn’t allow it)?

I'm not sure that I would like this level of complexity in this code path...

Kevin

#16 lore raw
In reply to Max Reitz
Quoted 9 lines · Max Reitz
Quoted 6 lines
Quoted 6 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Catching up with this now. I was told about this last week at the KVM Forum, but if the problems comes with the use of fallocate() and XFS, the I don't think subclusters will solve it.

handle_alloc_space() is used to fill a cluster with zeroes when there's COW, and that happens the same with subclusters, just at the subcluster level instead of course.

What can happen, if the subcluster size matches the filesystem block size, is that there's no need for any COW and therefore the bug is never triggered. But that's not quite the same as a fix :-)

Quoted 4 lines

Maybe make a decision based both on the ratio of data size to COW area length (only invoke handle_alloc_space() under a certain threshold), and the absolute COW area length (always invoke it above a certain threshold, unless the ratio doesn’t allow it)?

Maybe combining that with the smaller clusters/subclusters can work around the problem. The maximum subcluster size is 64KB (for a 2MB cluster).

Berto

author
#17 lore raw
Quoted 15 lines · Alberto Garcia
Quoted 9 lines · Max Reitz
Quoted 6 lines
Quoted 6 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Catching up with this now. I was told about this last week at the KVM Forum, but if the problems comes with the use of fallocate() and XFS, the I don't think subclusters will solve it.

Quoted 7 lines

handle_alloc_space() is used to fill a cluster with zeroes when there's COW, and that happens the same with subclusters, just at the subcluster level instead of course.

What can happen, if the subcluster size matches the filesystem block size, is that there's no need for any COW and therefore the bug is never triggered. But that's not quite the same as a fix :-)

No, what I meant was that the original problem that led to c8bb23cbdbe would go away.

c8bb23cbdbe was added because small writes to new clusters are slow when the clusters are large (because you need to do a 2 MB write on the host for a 4 kB write from the guest). So handle_alloc_space() was added to alleviate the problem with a zero-write instead of actually writing zeroes.

The question is whether there is no need for handle_alloc_space() with subclusters because a normal write with explicit zeroes being written in the COW areas would be sufficiently quick. (Because the subclusters for 2 MB clusters are just 64 kB in size.)

If that were so (right now it doesn’t look like it), we could revert c8bb23cbdbe and wouldn’t see the bug anymore.

Max

Quoted 11 lines
Quoted 4 lines

Maybe make a decision based both on the ratio of data size to COW area length (only invoke handle_alloc_space() under a certain threshold), and the absolute COW area length (always invoke it above a certain threshold, unless the ratio doesn’t allow it)?

Maybe combining that with the smaller clusters/subclusters can work around the problem. The maximum subcluster size is 64KB (for a 2MB cluster).

Berto

#18 lore raw
Quoted 18 lines · Max Reitz
Quoted 18 lines
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Catching up with this now. I was told about this last week at the KVM Forum, but if the problems comes with the use of fallocate() and XFS, the I don't think subclusters will solve it.

handle_alloc_space() is used to fill a cluster with zeroes when there's COW, and that happens the same with subclusters, just at the subcluster level instead of course.

Quoted 6 lines
Quoted 3 lines

What can happen, if the subcluster size matches the filesystem block size, is that there's no need for any COW and therefore the bug is never triggered. But that's not quite the same as a fix :-)

No, what I meant was that the original problem that led to c8bb23cbdbe would go away.

Ah, right. Not quite, according to my numbers:

|--------------+----------------+-----------------+-------------|
| Cluster size | subclusters=on | subclusters=off | fallocate() |
|--------------+----------------+-----------------+-------------|
|       256 KB |     10182 IOPS |        966 IOPS |  14007 IOPS |
|       512 KB |      7919 IOPS |        563 IOPS |  13442 IOPS |
|      1024 KB |      5050 IOPS |        465 IOPS |  13887 IOPS |
|      2048 KB |      2465 IOPS |        271 IOPS |  13885 IOPS |
|--------------+----------------+-----------------+-------------|

There's obviously no backing image, and only the last column uses handle_alloc_space() / fallocate().

Berto

author
#19 lore raw
Quoted 37 lines · Alberto Garcia
Quoted 18 lines · Max Reitz
Quoted 18 lines
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

So, it's obvious that c8bb23cbdbe32f5c326 is significant for 1M cluster-size, even on rotational disk, which means that previous assumption about calling handle_alloc_space() only for ssd is wrong, we need smarter heuristics..

So, I'd prefer (1) or (2).

OK. I wonder whether that problem would go away with Berto’s subcluster series, though.

Catching up with this now. I was told about this last week at the KVM Forum, but if the problems comes with the use of fallocate() and XFS, the I don't think subclusters will solve it.

handle_alloc_space() is used to fill a cluster with zeroes when there's COW, and that happens the same with subclusters, just at the subcluster level instead of course.

Quoted 6 lines
Quoted 3 lines

What can happen, if the subcluster size matches the filesystem block size, is that there's no need for any COW and therefore the bug is never triggered. But that's not quite the same as a fix :-)

No, what I meant was that the original problem that led to c8bb23cbdbe would go away.

Ah, right. Not quite, according to my numbers:

|--------------+----------------+-----------------+-------------|
| Cluster size | subclusters=on | subclusters=off | fallocate() |
|--------------+----------------+-----------------+-------------|
|       256 KB |     10182 IOPS |        966 IOPS |  14007 IOPS |
|       512 KB |      7919 IOPS |        563 IOPS |  13442 IOPS |
|      1024 KB |      5050 IOPS |        465 IOPS |  13887 IOPS |
|      2048 KB |      2465 IOPS |        271 IOPS |  13885 IOPS |
|--------------+----------------+-----------------+-------------|
Quoted 2 lines

There's obviously no backing image, and only the last column uses handle_alloc_space() / fallocate().

Thanks for providing some numbers!

It was my impression, too, that subclusters wouldn’t solve it. But it didn’t seem like that big of a difference to me. Did you run this with aio=native? (Because that’s where we have the XFS problem)

Max

#20 lore raw
Quoted 14 lines · Max Reitz
Quoted 14 lines
Quoted 2 lines

No, what I meant was that the original problem that led to c8bb23cbdbe would go away.

Ah, right. Not quite, according to my numbers:

|--------------+----------------+-----------------+-------------|
| Cluster size | subclusters=on | subclusters=off | fallocate() |
|--------------+----------------+-----------------+-------------|
|       256 KB |     10182 IOPS |        966 IOPS |  14007 IOPS |
|       512 KB |      7919 IOPS |        563 IOPS |  13442 IOPS |
|      1024 KB |      5050 IOPS |        465 IOPS |  13887 IOPS |
|      2048 KB |      2465 IOPS |        271 IOPS |  13885 IOPS |
|--------------+----------------+-----------------+-------------|
Quoted 8 lines
Quoted 2 lines

There's obviously no backing image, and only the last column uses handle_alloc_space() / fallocate().

Thanks for providing some numbers!

It was my impression, too, that subclusters wouldn’t solve it. But it didn’t seem like that big of a difference to me. Did you run this with aio=native? (Because that’s where we have the XFS problem)

Here's with aio=native

|--------------+----------------+-----------------+-------------|
| Cluster size | subclusters=on | subclusters=off | fallocate() |
|--------------+----------------+-----------------+-------------|
|       256 KB |     19897 IOPS |        891 IOPS |  32194 IOPS |
|       512 KB |     17881 IOPS |        436 IOPS |  33092 IOPS |
|      1024 KB |     17050 IOPS |        341 IOPS |  32768 IOPS |
|      2048 KB |      7854 IOPS |        207 IOPS |  30944 IOPS |
|--------------+----------------+-----------------+-------------|

Berto

author
#21 lore raw
Quoted 27 lines · Alberto Garcia
Quoted 14 lines · Max Reitz
Quoted 14 lines
Quoted 2 lines

No, what I meant was that the original problem that led to c8bb23cbdbe would go away.

Ah, right. Not quite, according to my numbers:

|--------------+----------------+-----------------+-------------|
| Cluster size | subclusters=on | subclusters=off | fallocate() |
|--------------+----------------+-----------------+-------------|
|       256 KB |     10182 IOPS |        966 IOPS |  14007 IOPS |
|       512 KB |      7919 IOPS |        563 IOPS |  13442 IOPS |
|      1024 KB |      5050 IOPS |        465 IOPS |  13887 IOPS |
|      2048 KB |      2465 IOPS |        271 IOPS |  13885 IOPS |
|--------------+----------------+-----------------+-------------|
Quoted 8 lines
Quoted 2 lines

There's obviously no backing image, and only the last column uses handle_alloc_space() / fallocate().

Thanks for providing some numbers!

It was my impression, too, that subclusters wouldn’t solve it. But it didn’t seem like that big of a difference to me. Did you run this with aio=native? (Because that’s where we have the XFS problem)

Here's with aio=native

Quoted 8 lines
|--------------+----------------+-----------------+-------------|
| Cluster size | subclusters=on | subclusters=off | fallocate() |
|--------------+----------------+-----------------+-------------|
|       256 KB |     19897 IOPS |        891 IOPS |  32194 IOPS |
|       512 KB |     17881 IOPS |        436 IOPS |  33092 IOPS |
|      1024 KB |     17050 IOPS |        341 IOPS |  32768 IOPS |
|      2048 KB |      7854 IOPS |        207 IOPS |  30944 IOPS |
|--------------+----------------+-----------------+-------------|

OK, thanks again. :-)

So it seems right not to revert the commit and just work around the XFS bug in file-posix.

Max

author
#23 lore raw
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

Quoted 6 lines
Quoted 4 lines

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

Have we reported that upstream to the xfs folks?

I’ve created an RH BZ here:

https://bugzilla.redhat.com/show_bug.cgi?id=1765547

So at least some XFS folks are aware of it (and I trust them to inform the others as necessary :-)). (Eric Sandeen has been part of the discussion for the last couple of days already.)

Max

#24 lore raw
Quoted 11 lines · Max Reitz
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

Have we reported that upstream to the xfs folks?

I’ve created an RH BZ here:

https://bugzilla.redhat.com/show_bug.cgi?id=1765547

Currently "You are not authorized to access bug #1765547." for anonymous browsers, just fyi.

thanks
-- PMM

author
#25 lore raw
Quoted 15 lines · Peter Maydell
Quoted 14 lines · Max Reitz
Quoted 12 lines · Peter Maydell
Quoted 10 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Have we reported that upstream to the xfs folks?

I’ve created an RH BZ here:

https://bugzilla.redhat.com/show_bug.cgi?id=1765547

Currently "You are not authorized to access bug #1765547." for anonymous browsers, just fyi.

Err. Oops. That wasn’t my intention. I hate that misfeature.

Thanks for telling me, I fixed it. :-)

Max

#26 lore raw
Quoted 5 lines · Max Reitz
Quoted 3 lines · Peter Maydell
Quoted 2 lines · Max Reitz

I’ve created an RH BZ here:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

https://bugzilla.redhat.com/show_bug.cgi?id=1765547

Currently "You are not authorized to access bug #1765547." for anonymous browsers, just fyi.

Err. Oops. That wasn’t my intention. I hate that misfeature.

Thanks for telling me, I fixed it. :-)

Yeah, that's a really well written bug report, you definitely don't want to hide it away :-) Thanks for making it public.

-- PMM

#27 lore raw
In reply to Max Reitz
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

CC block/sheepdog.o
CC block/accounting.o
/tmp/qemu-test/src/block/file-posix.c: In function 'raw_open_common':
/tmp/qemu-test/src/block/file-posix.c:671:5: error: implicit declaration of function 'platform_test_xfs_fd' [-Werror=implicit-function-declaration]

     if (platform_test_xfs_fd(s->fd)) {
     ^

/tmp/qemu-test/src/block/file-posix.c:671:5: error: nested extern declaration of 'platform_test_xfs_fd' [-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [block/file-posix.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 662, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=c74d47e9bfb24107b6e94885fa8a2151', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-ytazf4e4/src/docker-src.2019-10-25-20.11.53.7609:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=c74d47e9bfb24107b6e94885fa8a2151
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-ytazf4e4/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 2m32.235s
user 0m8.092s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#28 lore raw
In reply to Max Reitz
Quoted 81 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
I don’t know how we would go about this, so this series doesn’t do it. (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS. The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

Advantages:
+ Maybe simpler, depending on how difficult it is to handle the layering violation
+ Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

Disadvantages:
- Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
- We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f. To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

Correctness is more important than performance, so this is my preference as a user.

Nir

Quoted 25 lines

So this is the main reason this is an RFC: What should we do? Is (1) really the best choice?

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time. (Without this series, it fails like every other time.)

Max Reitz (3):
block: Make wait/mark serialising requests public block/file-posix: Detect XFS with CONFIG_FALLOCATE block/file-posix: Let post-EOF fallocate serialize

 include/block/block_int.h |  3 +++
 block/file-posix.c        | 46 +++++++++++++++++++++++++++++++++++++--
 block/io.c                | 24 ++++++++++----------
 3 files changed, 59 insertions(+), 14 deletions(-)

--
2.21.0

#29 lore raw
Quoted 82 lines · Nir Soffer
Quoted 81 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
I don’t know how we would go about this, so this series doesn’t do it. (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS. The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

Advantages:
+ Maybe simpler, depending on how difficult it is to handle the layering violation
+ Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

Disadvantages:
- Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
- We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 7 lines
Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

Correctness is more important than performance, so this is my preference as a user.

Hmm, still, incorrect is XFS, not Qemu. This bug may be triggered by another software, or may be another scenario in Qemu (not sure).

Quoted 26 lines
Quoted 26 lines

So this is the main reason this is an RFC: What should we do? Is (1) really the best choice?

In any case, I’ve ran the test case I showed in
https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01282.html
more than ten times with this series applied and the installation succeeded every time. (Without this series, it fails like every other time.)

Max Reitz (3):
block: Make wait/mark serialising requests public block/file-posix: Detect XFS with CONFIG_FALLOCATE block/file-posix: Let post-EOF fallocate serialize

  include/block/block_int.h |  3 +++
  block/file-posix.c        | 46 +++++++++++++++++++++++++++++++++++++--
  block/io.c                | 24 ++++++++++----------
  3 files changed, 59 insertions(+), 14 deletions(-)

--
2.21.0

Signature · 2 lines
Best regards,
Vladimir
author
#30 lore raw
Quoted 87 lines · Vladimir Sementsov-Ogievskiy
Quoted 86 lines · Nir Soffer
Quoted 84 lines · Max Reitz

Hi,

It seems to me that there is a bug in Linux’s XFS kernel driver, as I’ve explained here:

https://lists.nongnu.org/archive/html/qemu-block/2019-10/msg01429.html

In combination with our commit c8bb23cbdbe32f, this may lead to guest data corruption when using qcow2 images on XFS with aio=native.

We can’t wait until the XFS kernel driver is fixed, we should work around the problem ourselves.

This is an RFC for two reasons:
(1) I don’t know whether this is the right way to address the issue,
(2) Ideally, we should detect whether the XFS kernel driver is fixed and if so stop applying the workaround.
I don’t know how we would go about this, so this series doesn’t do it. (Hence it’s an RFC.)
(3) Perhaps it’s a bit of a layering violation to let the file-posix driver access and modify a BdrvTrackedRequest object.

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

(2) Always skip qcow2’s handle_alloc_space() on XFS. The XFS bug only becomes visible due to that function: I don’t think qcow2 writes zeroes in any other I/O path, and raw images are fixed in size so post-EOF writes won’t happen.

Advantages:
+ Maybe simpler, depending on how difficult it is to handle the layering violation
+ Also fixes the performance problem of handle_alloc_space() being slow on ppc64+XFS.

Disadvantages:
- Huge layering violation because qcow2 would need to know whether the image is stored on XFS or not.
- We’d definitely want to skip this workaround when the XFS driver has been fixed, so we need some method to find out whether it has

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

Quoted 6 lines
Quoted 3 lines

Correctness is more important than performance, so this is my preference as a user.

Hmm, still, incorrect is XFS, not Qemu. This bug may be triggered by another software, or may be another scenario in Qemu (not sure).

I don’t see any other image format (but qcow2, raw, and filters) creating zero-writes apart from the parallels format which does so before writes can happen to that area. So with parallels, it’s impossible to get a data write behind an ongoing zero-write.

Raw and filters do not initiate zero-writes on their own. So there must be something else that requests them. Block jobs and guests are limited to generally fixed-size disks, so I don’t see a way to generate zero-writes beyond the EOF there.

Which leaves us with qcow2. To my knowledge the only place where qcow2 generates zero-writes in an I/O path (so they can occur concurrently to data writes) is in handle_alloc_space(). Therefore, dropping it should remove the only place where the XFS bug can be triggered.

That the bug is in XFS and not in qemu is a good argument from a moral standpoint, but it isn’t very pragmatic or reasonable from a technical standpoint. There is no fix for XFS yet, so right now the situation is that there is a bug that causes guest data loss, that qemu can prevent it, and that there is no other workaround or fix.

So we must work around it.

Of course, that doesn’t mean that we have to do everything in our power to implement a work around no matter the cost. We do indeed have to balance between how far we’re willing to go to fix it and how much we impact non-XFS workloads.

Honestly, I caught myself saying “Well, that’s too bad for XFS over gluster if XFS is broken”. But that just isn’t a reasonable thing to say.

I suppose what we could do is drop the is_xfs check in patch 3. The only outcome is that you can no longer do concurrent data writes past zero-writes past the EOF. And as I’ve claimed above, this only affects handle_alloc_space() from qcow2. Would it be so bad if we simply did that on every filesystem?

Max

#31 lore raw
In reply to Max Reitz
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f. To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Stefan

author
#32 lore raw
Quoted 18 lines · Stefan Hajnoczi
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I’ll add a note to the RH BZ.

Quoted 7 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

:-/

I don’t like it, but I suppose it would work. We could also automatically enable this disabling option in configure when we detect uname to report a kernel version that must include the fix. (This wouldn’t work for kernel with backported fixes, but those disappear over time...)

Max

author
#33 lore raw
Quoted 38 lines · Max Reitz
Quoted 18 lines · Stefan Hajnoczi
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I’ll add a note to the RH BZ.

Quoted 7 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 7 lines

:-/

I don’t like it, but I suppose it would work. We could also automatically enable this disabling option in configure when we detect uname to report a kernel version that must include the fix. (This wouldn’t work for kernel with backported fixes, but those disappear over time...)

I just realized that none of this is going to work for the gluster case brought up by Nir. The affected kernel is the remote one and we have no insight into that. I don’t think we can do ioctls to XFS over gluster, can we?

I also realized that uname is a stupid idea because the user may be running a different kernel version than what runs on the build machine... :(

Max

author
#34 lore raw
Quoted 46 lines · Max Reitz
Quoted 38 lines · Max Reitz
Quoted 18 lines · Stefan Hajnoczi
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I’ll add a note to the RH BZ.

Quoted 7 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 7 lines

:-/

I don’t like it, but I suppose it would work. We could also automatically enable this disabling option in configure when we detect uname to report a kernel version that must include the fix. (This wouldn’t work for kernel with backported fixes, but those disappear over time...)

Quoted 4 lines

I just realized that none of this is going to work for the gluster case brought up by Nir. The affected kernel is the remote one and we have no insight into that. I don’t think we can do ioctls to XFS over gluster, can we?

On third thought, we could try to detect whether the file is on a remote filesystem, and if so enable the workaround unconditionally. I suppose it wouldn’t hurt performance-wise, given that it’s a remote filesystem anyway.

Max

#35 lore raw
Quoted 52 lines · Max Reitz
Quoted 46 lines · Max Reitz
Quoted 38 lines · Max Reitz
Quoted 18 lines · Stefan Hajnoczi
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I’ll add a note to the RH BZ.

Quoted 7 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 7 lines

:-/

I don’t like it, but I suppose it would work. We could also automatically enable this disabling option in configure when we detect uname to report a kernel version that must include the fix. (This wouldn’t work for kernel with backported fixes, but those disappear over time...)

Quoted 4 lines

I just realized that none of this is going to work for the gluster case brought up by Nir. The affected kernel is the remote one and we have no insight into that. I don’t think we can do ioctls to XFS over gluster, can we?

Quoted 5 lines

On third thought, we could try to detect whether the file is on a remote filesystem, and if so enable the workaround unconditionally. I suppose it wouldn’t hurt performance-wise, given that it’s a remote filesystem anyway.

I think, for remote, the difference may be even higher than for local, as cost of writing real zeroes through the wire vs fast zero command is high.

Really, can we live with simple config option, is it so bad?

Signature · 2 lines
Best regards,
Vladimir
author
#36 lore raw
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 52 lines · Max Reitz
Quoted 50 lines · Max Reitz
Quoted 38 lines · Max Reitz
Quoted 18 lines · Stefan Hajnoczi
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I’ll add a note to the RH BZ.

Quoted 7 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 7 lines

:-/

I don’t like it, but I suppose it would work. We could also automatically enable this disabling option in configure when we detect uname to report a kernel version that must include the fix. (This wouldn’t work for kernel with backported fixes, but those disappear over time...)

I just realized that none of this is going to work for the gluster case brought up by Nir. The affected kernel is the remote one and we have no insight into that. I don’t think we can do ioctls to XFS over gluster, can we?

Quoted 8 lines
Quoted 5 lines

On third thought, we could try to detect whether the file is on a remote filesystem, and if so enable the workaround unconditionally. I suppose it wouldn’t hurt performance-wise, given that it’s a remote filesystem anyway.

I think, for remote, the difference may be even higher than for local, as cost of writing real zeroes through the wire vs fast zero command is high.

I was speaking of a workaround in general, and that includes the workaround presented in this series.

Quoted 1 line

Really, can we live with simple config option, is it so bad?

The config option won’t work for remote hosts, though. That’s exactly the problem.

Max

#37 lore raw
Quoted 60 lines · Max Reitz
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 57 lines · Max Reitz
Quoted 46 lines · Max Reitz
Quoted 38 lines · Max Reitz
Quoted 18 lines · Stefan Hajnoczi
Quoted 12 lines · Max Reitz

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I’ll add a note to the RH BZ.

Quoted 7 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 7 lines

:-/

I don’t like it, but I suppose it would work. We could also automatically enable this disabling option in configure when we detect uname to report a kernel version that must include the fix. (This wouldn’t work for kernel with backported fixes, but those disappear over time...)

Quoted 4 lines

I just realized that none of this is going to work for the gluster case brought up by Nir. The affected kernel is the remote one and we have no insight into that. I don’t think we can do ioctls to XFS over gluster, can we?

On third thought, we could try to detect whether the file is on a remote filesystem, and if so enable the workaround unconditionally. I suppose it wouldn’t hurt performance-wise, given that it’s a remote filesystem anyway.

Quoted 5 lines
Quoted 2 lines

I think, for remote, the difference may be even higher than for local, as cost of writing real zeroes through the wire vs fast zero command is high.

I was speaking of a workaround in general, and that includes the workaround presented in this series.

Ah, yes, sorry. Then it should be OK.

Quoted 6 lines
Quoted 2 lines

Really, can we live with simple config option, is it so bad?

The config option won’t work for remote hosts, though. That’s exactly the problem.

Still config option will help people who have xfs setups and want to be absolutely safe. (Or, with another default, help people who doesn't have xfs setups (Virtuozzo) and want to be fast)

Signature · 2 lines
Best regards,
Vladimir
#38 lore raw
In reply to Stefan Hajnoczi

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 18 lines · Max Reitz
Quoted 12 lines

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I think the CC list is too short for this question. We should involve the XFS people here.

Quoted 32 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f. To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 7 lines
Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Kevin

#39 lore raw
Quoted 67 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 18 lines · Max Reitz
Quoted 12 lines

As for how we can address the issue, I see three ways:
(1) The one presented in this series: On XFS with aio=native, we extend tracked requests for post-EOF fallocate() calls (i.e., write-zero operations) to reach until infinity (INT64_MAX in practice), mark them serializing and wait for other conflicting requests.

Advantages:
+ Limits the impact to very specific cases
(And that means it wouldn’t hurt too much to keep this workaround even when the XFS driver has been fixed)
+ Works around the bug where it happens, namely in file-posix

Quoted 4 lines

Disadvantages:
- A bit complex
- A bit of a layering violation (should file-posix have access to tracked requests?)

Quoted 8 lines

Your patch series is reasonable. I don't think it's too bad.

The main question is how to detect the XFS fix once it ships. XFS already has a ton of ioctls, so maybe they don't mind adding a feature/quirk bit map ioctl for publishing information about bug fixes to userspace. I didn't see another obvious way of doing it, maybe a mount option that the kernel automatically sets and that gets reported to userspace?

I think the CC list is too short for this question. We should involve the XFS people here.

Quoted 36 lines

If we imagine that XFS will not provide a mechanism to detect the presence of the fix, then could we ask QEMU package maintainers to ./configure --disable-xfs-fallocate-beyond-eof-workaround at some point in the future when their distro has been shipping a fixed kernel for a while? It's ugly because it doesn't work if the user installs an older custom-built kernel on the host. But at least it will cover 98% of users...

Quoted 27 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

Quoted 7 lines
Quoted 3 lines

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

I'm not sure about ssd case, it may need write-zero optimization anyway.

Quoted 6 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Can keeping handle_alloc_space under some config option be an option?

Signature · 2 lines
Best regards,
Vladimir
author
#40 lore raw
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Quoted 5 lines
Quoted 3 lines

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

I'm not sure about ssd case, it may need write-zero optimization anyway.

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

I’m asking because Dave Chinner said
(https://bugzilla.redhat.com/show_bug.cgi?id=1765547#c7) that fallocate() is always slow at least with aio=native because it needs to wait for all concurrent AIO writes to finish, and so it causes the AIO pipeline to stall.

(He suggested using XFS extent size hints to get the same effect as write-zeroes for free, basically, but I don’t know whether that’s really useful to us; as unallocated areas on XFS read back as zero anyway.)

Quoted 7 lines
Quoted 5 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Can keeping handle_alloc_space under some config option be an option?

Hm. A config option is weird if you’re the only one who’s going to enable it. But other than that I don’t have anything against it.

Max

#41 lore raw
Quoted 43 lines · Max Reitz
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 36 lines
Quoted 35 lines
Quoted 24 lines
Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 7 lines
Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

Quoted 6 lines
Quoted 1 line

I'm not sure about ssd case, it may need write-zero optimization anyway.

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

Hmm, what do you mean? We need to zero COW areas. So, original way is to write real zeroes, optimized way is fallocate.. What do you mean by drop? Mark sublusters as zeroes by metadata?

But still we'll have COW areas in subcluster, and we'll need to directly zero them.. And fallocate will most probably be faster on ssd ext4 case..

Quoted 17 lines

I’m asking because Dave Chinner said
(https://bugzilla.redhat.com/show_bug.cgi?id=1765547#c7) that fallocate() is always slow at least with aio=native because it needs to wait for all concurrent AIO writes to finish, and so it causes the AIO pipeline to stall.

(He suggested using XFS extent size hints to get the same effect as write-zeroes for free, basically, but I don’t know whether that’s really useful to us; as unallocated areas on XFS read back as zero anyway.)

Quoted 6 lines
Quoted 5 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Quoted 5 lines
Quoted 1 line

Can keeping handle_alloc_space under some config option be an option?

Hm. A config option is weird if you’re the only one who’s going to enable it. But other than that I don’t have anything against it.

It's just a bit easier for us to maintain config option, than out-of-tree patch. On the other hand, it's not a real problem to maintain this one patch in separate. It may return again to the tree, when XFS bug fixed.

Signature · 2 lines
Best regards,
Vladimir
author
#42 lore raw
Quoted 46 lines · Vladimir Sementsov-Ogievskiy
Quoted 45 lines · Max Reitz
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

Quoted 7 lines
Quoted 3 lines

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

I'm not sure about ssd case, it may need write-zero optimization anyway.

Quoted 8 lines
Quoted 4 lines

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

Hmm, what do you mean? We need to zero COW areas. So, original way is to write real zeroes, optimized way is fallocate.. What do you mean by drop? Mark sublusters as zeroes by metadata?

Why do you need to zero COW areas? For normal files, any data will read as zero if you didn’t write anything there.

Quoted 22 lines

But still we'll have COW areas in subcluster, and we'll need to directly zero them.. And fallocate will most probably be faster on ssd ext4 case..

Quoted 19 lines

I’m asking because Dave Chinner said
(https://bugzilla.redhat.com/show_bug.cgi?id=1765547#c7) that fallocate() is always slow at least with aio=native because it needs to wait for all concurrent AIO writes to finish, and so it causes the AIO pipeline to stall.

(He suggested using XFS extent size hints to get the same effect as write-zeroes for free, basically, but I don’t know whether that’s really useful to us; as unallocated areas on XFS read back as zero anyway.)

Quoted 7 lines
Quoted 5 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Can keeping handle_alloc_space under some config option be an option?

Quoted 7 lines
Quoted 3 lines

Hm. A config option is weird if you’re the only one who’s going to enable it. But other than that I don’t have anything against it.

It's just a bit easier for us to maintain config option, than out-of-tree patch. On the other hand, it's not a real problem to maintain this one patch in separate. It may return again to the tree, when XFS bug fixed.

We’ll still have the problem that fallocate() must stall aio=native requests.

Max

#43 lore raw
Quoted 52 lines · Max Reitz
Quoted 51 lines · Vladimir Sementsov-Ogievskiy
Quoted 49 lines · Max Reitz
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Quoted 5 lines
Quoted 3 lines

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

I'm not sure about ssd case, it may need write-zero optimization anyway.

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

Quoted 6 lines
Quoted 3 lines

Hmm, what do you mean? We need to zero COW areas. So, original way is to write real zeroes, optimized way is fallocate.. What do you mean by drop? Mark sublusters as zeroes by metadata?

Why do you need to zero COW areas? For normal files, any data will read as zero if you didn’t write anything there.

Hmm, but when allocating new cluster in qcow2, it's not guaranteed to be zero, as it may be reused previously allocated cluster..

Quoted 27 lines
Quoted 27 lines

But still we'll have COW areas in subcluster, and we'll need to directly zero them.. And fallocate will most probably be faster on ssd ext4 case..

Quoted 22 lines

I’m asking because Dave Chinner said
(https://bugzilla.redhat.com/show_bug.cgi?id=1765547#c7) that fallocate() is always slow at least with aio=native because it needs to wait for all concurrent AIO writes to finish, and so it causes the AIO pipeline to stall.

(He suggested using XFS extent size hints to get the same effect as write-zeroes for free, basically, but I don’t know whether that’s really useful to us; as unallocated areas on XFS read back as zero anyway.)

Quoted 7 lines
Quoted 5 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Can keeping handle_alloc_space under some config option be an option?

Hm. A config option is weird if you’re the only one who’s going to enable it. But other than that I don’t have anything against it.

Quoted 7 lines
Quoted 3 lines

It's just a bit easier for us to maintain config option, than out-of-tree patch. On the other hand, it's not a real problem to maintain this one patch in separate. It may return again to the tree, when XFS bug fixed.

We’ll still have the problem that fallocate() must stall aio=native requests.

Does it mean that fallocate is bad in general? Practice shows the opposite.. At least I have my examples with qemu-img bench. Can that thing be shown with qemu-img bench or something?

Signature · 2 lines
Best regards,
Vladimir
author
#44 lore raw
Quoted 57 lines · Vladimir Sementsov-Ogievskiy
Quoted 56 lines · Max Reitz
Quoted 54 lines · Vladimir Sementsov-Ogievskiy
Quoted 43 lines · Max Reitz
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 36 lines
Quoted 35 lines
Quoted 24 lines
Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 7 lines
Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

Quoted 6 lines
Quoted 1 line

I'm not sure about ssd case, it may need write-zero optimization anyway.

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

Hmm, what do you mean? We need to zero COW areas. So, original way is to write real zeroes, optimized way is fallocate.. What do you mean by drop? Mark sublusters as zeroes by metadata?

Quoted 5 lines
Quoted 2 lines

Why do you need to zero COW areas? For normal files, any data will read as zero if you didn’t write anything there.

Hmm, but when allocating new cluster in qcow2, it's not guaranteed to be zero, as it may be reused previously allocated cluster..

Hm, right. We could special-case something for beyond the EOF, but I don’t know whether that really makes it better.

OTOH, maybe allocations at the EOF are the real bottleneck. Reusing existing clusters should be rare enough that maybe the existing code which explicitly writes zeroes is sufficient.

Quoted 31 lines
Quoted 31 lines
Quoted 30 lines

But still we'll have COW areas in subcluster, and we'll need to directly zero them.. And fallocate will most probably be faster on ssd ext4 case..

Quoted 17 lines

I’m asking because Dave Chinner said
(https://bugzilla.redhat.com/show_bug.cgi?id=1765547#c7) that fallocate() is always slow at least with aio=native because it needs to wait for all concurrent AIO writes to finish, and so it causes the AIO pipeline to stall.

(He suggested using XFS extent size hints to get the same effect as write-zeroes for free, basically, but I don’t know whether that’s really useful to us; as unallocated areas on XFS read back as zero anyway.)

Quoted 6 lines
Quoted 5 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Quoted 5 lines
Quoted 1 line

Can keeping handle_alloc_space under some config option be an option?

Hm. A config option is weird if you’re the only one who’s going to enable it. But other than that I don’t have anything against it.

It's just a bit easier for us to maintain config option, than out-of-tree patch. On the other hand, it's not a real problem to maintain this one patch in separate. It may return again to the tree, when XFS bug fixed.

Quoted 7 lines
Quoted 3 lines

We’ll still have the problem that fallocate() must stall aio=native requests.

Does it mean that fallocate is bad in general? Practice shows the opposite.. At least I have my examples with qemu-img bench. Can that thing be shown with qemu-img bench or something?

I haven’t done benchmarks yet, but I don’t think Laurent will mind if I paste his fio benchmark results from the unfortunately private BZ here:

         QCOW2 ON |          EXT4         |          XFS          |
                  |                       |                       |
(rw, bs, iodepth) |   2.12.0  |   4.1.0   |   2.12.0  |   4.1.0   |

------------------+-----------+-----------+-----------+-----------+
(write, 16k, 1) | 1868KiB/s | 1865KiB/s | 18.6MiB/s | 13.7MiB/s |
------------------+-----------+-----------+-----------+-----------+
(write, 64k, 1) | 7036KiB/s | 7413KiB/s | 27.0MiB/s | 7465KiB/s |
------------------+-----------+-----------+-----------+-----------+
(write, 4k, 8) | 535KiB/s | 524KiB/s | 13.9MiB/s | 1662KiB/s |
------------------+-----------+-----------+-----------+-----------+

And that just looks like ext4 performs worse with aio=native in general.
But I’ll have to do my own benchmarks first.

Max

#45 lore raw
Quoted 64 lines · Max Reitz
Quoted 57 lines · Vladimir Sementsov-Ogievskiy
Quoted 56 lines · Max Reitz
Quoted 54 lines · Vladimir Sementsov-Ogievskiy
Quoted 43 lines · Max Reitz
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 36 lines
Quoted 35 lines
Quoted 24 lines
Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 7 lines
Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

Quoted 6 lines
Quoted 1 line

I'm not sure about ssd case, it may need write-zero optimization anyway.

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

Hmm, what do you mean? We need to zero COW areas. So, original way is to write real zeroes, optimized way is fallocate.. What do you mean by drop? Mark sublusters as zeroes by metadata?

Quoted 5 lines
Quoted 2 lines

Why do you need to zero COW areas? For normal files, any data will read as zero if you didn’t write anything there.

Hmm, but when allocating new cluster in qcow2, it's not guaranteed to be zero, as it may be reused previously allocated cluster..

Quoted 6 lines

Hm, right. We could special-case something for beyond the EOF, but I don’t know whether that really makes it better.

OTOH, maybe allocations at the EOF are the real bottleneck. Reusing existing clusters should be rare enough that maybe the existing code which explicitly writes zeroes is sufficient.

But, as I understand pre-EOF fallocates are safe in xfs? So, we may just drop calling fallocate past-EOF (it's zero anyway) and do fallocate pre-EOF (it's safe) ? (the only special case is intersecting EOF.. so better is keep file length at cluster-size boundary, truncating on exit)

Quoted 59 lines
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines

But still we'll have COW areas in subcluster, and we'll need to directly zero them.. And fallocate will most probably be faster on ssd ext4 case..

Quoted 17 lines

I’m asking because Dave Chinner said
(https://bugzilla.redhat.com/show_bug.cgi?id=1765547#c7) that fallocate() is always slow at least with aio=native because it needs to wait for all concurrent AIO writes to finish, and so it causes the AIO pipeline to stall.

(He suggested using XFS extent size hints to get the same effect as write-zeroes for free, basically, but I don’t know whether that’s really useful to us; as unallocated areas on XFS read back as zero anyway.)

Quoted 6 lines
Quoted 5 lines

We already have some cases where the existing handle_alloc_space() causes performance to actually become worse, and serialising requests as a workaround isn't going to make performance any better. So even on these grounds, keeping commit c8bb23cbdbe32f is questionable.

Quoted 5 lines
Quoted 1 line

Can keeping handle_alloc_space under some config option be an option?

Hm. A config option is weird if you’re the only one who’s going to enable it. But other than that I don’t have anything against it.

It's just a bit easier for us to maintain config option, than out-of-tree patch. On the other hand, it's not a real problem to maintain this one patch in separate. It may return again to the tree, when XFS bug fixed.

Quoted 7 lines
Quoted 3 lines

We’ll still have the problem that fallocate() must stall aio=native requests.

Does it mean that fallocate is bad in general? Practice shows the opposite.. At least I have my examples with qemu-img bench. Can that thing be shown with qemu-img bench or something?

I haven’t done benchmarks yet, but I don’t think Laurent will mind if I paste his fio benchmark results from the unfortunately private BZ here:

          QCOW2 ON |          EXT4         |          XFS          |
                   |                       |                       |

(rw, bs, iodepth) | 2.12.0 | 4.1.0 | 2.12.0 | 4.1.0 |
------------------+-----------+-----------+-----------+-----------+
(write, 16k, 1) | 1868KiB/s | 1865KiB/s | 18.6MiB/s | 13.7MiB/s |
------------------+-----------+-----------+-----------+-----------+
(write, 64k, 1) | 7036KiB/s | 7413KiB/s | 27.0MiB/s | 7465KiB/s |
------------------+-----------+-----------+-----------+-----------+
(write, 4k, 8) | 535KiB/s | 524KiB/s | 13.9MiB/s | 1662KiB/s |
------------------+-----------+-----------+-----------+-----------+

And that just looks like ext4 performs worse with aio=native in general.
But I’ll have to do my own benchmarks first.

Max

Signature · 2 lines
Best regards,
Vladimir
author
#46 lore raw
Quoted 68 lines · Vladimir Sementsov-Ogievskiy
Quoted 67 lines · Max Reitz
Quoted 57 lines · Vladimir Sementsov-Ogievskiy
Quoted 56 lines · Max Reitz
Quoted 54 lines · Vladimir Sementsov-Ogievskiy
Quoted 43 lines · Max Reitz
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Quoted 2 lines · Kevin Wolf

Am 27.10.2019 um 13:35 hat Stefan Hajnoczi geschrieben:

Quoted 1 line · Max Reitz

[...]

Quoted 36 lines
Quoted 35 lines
Quoted 24 lines
Quoted 24 lines

(3) Drop handle_alloc_space(), i.e. revert c8bb23cbdbe32f.
To my knowledge I’m the only one who has provided any benchmarks for this commit, and even then I was a bit skeptical because it performs well in some cases and bad in others. I concluded that it’s probably worth it because the “some cases” are more likely to occur.

Now we have this problem of corruption here (granted due to a bug in the XFS driver), and another report of massively degraded performance on ppc64
(https://bugzilla.redhat.com/show_bug.cgi?id=1745823 – sorry, a private BZ; I hate that :-/ The report is about 40 % worse performance for an in-guest fio write benchmark.)

So I have to ask the question about what the justification for keeping c8bb23cbdbe32f is. How much does performance increase with it actually? (On non-(ppc64+XFS) machines, obviously)

Advantages:
+ Trivial
+ No layering violations
+ We wouldn’t need to keep track of whether the kernel bug has been fixed or not
+ Fixes the ppc64+XFS performance problem

Quoted 7 lines
Quoted 3 lines

Disadvantages:
- Reverts cluster allocation performance to pre-c8bb23cbdbe32f levels, whatever that means

My favorite because it is clean and simple, but Vladimir has a valid use-case for requiring this performance optimization so reverting isn't an option.

Vladimir also said that qcow2 subclusters would probably also solve his problem, so maybe reverting and applying the subcluster patches instead is a possible solution, too?

Quoted 6 lines
Quoted 1 line

I'm not sure about ssd case, it may need write-zero optimization anyway.

What exactly do you need? Do you actually need to write zeroes (e.g. because you’re storing images on block devices) or would it be sufficient to just drop the COW areas when bdrv_has_zero_init() and bdrv_has_zero_init_truncate() are true?

Hmm, what do you mean? We need to zero COW areas. So, original way is to write real zeroes, optimized way is fallocate.. What do you mean by drop? Mark sublusters as zeroes by metadata?

Quoted 5 lines
Quoted 2 lines

Why do you need to zero COW areas? For normal files, any data will read as zero if you didn’t write anything there.

Hmm, but when allocating new cluster in qcow2, it's not guaranteed to be zero, as it may be reused previously allocated cluster..

Hm, right. We could special-case something for beyond the EOF, but I don’t know whether that really makes it better.

Quoted 6 lines
Quoted 3 lines

OTOH, maybe allocations at the EOF are the real bottleneck. Reusing existing clusters should be rare enough that maybe the existing code which explicitly writes zeroes is sufficient.

But, as I understand pre-EOF fallocates are safe in xfs? So, we may just drop calling fallocate past-EOF (it's zero anyway) and do fallocate pre-EOF (it's safe) ?

But probably slow still. And there’s the question of how much complexity we want to heap onto this.

Max