Skip to contentSkip to conversation

Change in qemu 2.12 causes qemu-img convert to NBD to write more data

Qemu-devel Richard W.M. Jones 4 participants 15 messages Nov 7, 2018 – Nov 19, 2018

lore
Share & tools
lore

Richard W.M. Jones

author Reviewed-by Paolo Bonzini
#0 lore raw

(I'm not going to claim this is a bug, but it causes a large, easily measurable performance regression in virt-v2v).

In qemu 2.10, when you do ‘qemu-img convert’ to an NBD target, qemu interleaves write and zero requests. We can observe this as follows:

  $ virt-builder fedora-28
  $ nbdkit --filter=log memory size=6G logfile=/tmp/log \
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
      1 Write
      2 Zero
      1 Write
      3 Zero
      1 Write
      1 Zero
      1 Write
    [etc for over 1000 lines]

Looking at the log file in detail we can see it is writing serially from the beginning to the end of the disk.

In qemu 2.12 this behaviour changed:

  $ nbdkit --filter=log memory size=6G logfile=/tmp/log \
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
      193 Zero
     1246 Write

It now zeroes the whole disk up front and then writes data over the top of the zeroed blocks.

The reason for the performance regression is that in the first case we write 6G in total. In the second case we write 6G of zeroes up front, followed by the amount of data in the disk image (in this case the test disk image contains 1G of non-sparse data, so we write about 7G in total).

In real world cases this makes a great difference: we might have 100s of G of data in the disk. The ultimate backend storage (a Linux block device) doesn't support efficient BLKZEROOUT so zeroing is pretty slow too.

I bisected the change to the commit shown at the end of this email.

Any suggestions how to fix or work around this problem welcome.

Rich.

commit 9776f0db6a19a0510e89b7aae38190b4811c95ba

Author: Edgar Kaziakhmedov <[email protected]>
Date:   Thu Jan 18 14:51:58 2018 +0300

nbd: implement bdrv_get_info callback

Since mirror job supports efficient zero out target mechanism (see in mirror_dirty_init()), implement bdrv_get_info to make it work over NBD. Such improvement will allow using the largest chunk possible and will decrease the number of NBD_CMD_WRITE_ZEROES requests on the wire.

Message-Id: <[email protected]>

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
#1 lore raw

Another thing I tried was to change the NBD server (nbdkit) so that it doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G logfile=/tmp/log \
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c 
   2154 Write

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per block of zeroes or data.

Nir: If we could get information from imageio about whether zeroing is implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
#2 lore raw
Quoted 8 lines · Richard W.M. Jones

Another thing I tried was to change the NBD server (nbdkit) so that it doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G logfile=/tmp/log \
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
   2154 Write
Quoted 8 lines

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per block of zeroes or data.

Nir: If we could get information from imageio about whether zeroing is implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse performance, so it should not be enabled by default.

Nir

#3 lore raw
Quoted 19 lines · Nir Soffer
Quoted 8 lines · Richard W.M. Jones

Another thing I tried was to change the NBD server (nbdkit) so that it doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G logfile=/tmp/log \
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
   2154 Write
Quoted 8 lines

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per block of zeroes or data.

Nir: If we could get information from imageio about whether zeroing is implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

Quoted 5 lines

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Even if we could, sending zero on the wire from qemu may be even slower,

Yes this is a very good point. Sending zeroes would be terrible.

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
#4 lore raw
In reply to Nir Soffer

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 21 lines
Quoted 8 lines · Richard W.M. Jones

Another thing I tried was to change the NBD server (nbdkit) so that it doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G logfile=/tmp/log \
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
   2154 Write
Quoted 7 lines

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per block of zeroes or data.

Nir: If we could get information from imageio about whether zeroing is implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Quoted 6 lines

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse performance, so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common case, generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the operation will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it appears to me that we'll have to have a command line option.

However, I'm curious what your exact use case and the backend used in it is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

Kevin

#5 lore raw
Quoted 41 lines · Kevin Wolf

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines

Another thing I tried was to change the NBD server (nbdkit) so that it doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 15 lines
Quoted 11 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
   2154 Write

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per block of zeroes or data.

Nir: If we could get information from imageio about whether zeroing is implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Quoted 6 lines

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse performance, so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common case, generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the operation will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it appears to me that we'll have to have a command line option.

Quoted 4 lines

However, I'm curious what your exact use case and the backend used in it is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage, which is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to manual zeroing when the server advertise wrong value of write_same_max_bytes.

Having a command line option to control this behavior sounds good. I don't have enough data to tell what should be the default, but I think the safe way would be to keep old behavior.

Nir

#6 lore raw
Quoted 50 lines · Nir Soffer
Quoted 42 lines · Kevin Wolf

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines

Another thing I tried was to change the NBD server (nbdkit) so that it doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq

-c

Quoted 13 lines
Quoted 9 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per block of zeroes or data.

Nir: If we could get information from imageio about whether zeroing is implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Quoted 6 lines

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse performance, so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common case, generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the operation will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it appears to me that we'll have to have a command line option.

Quoted 4 lines

However, I'm curious what your exact use case and the backend used in it is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

Quoted 7 lines

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage, which is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to manual zeroing when the server advertise wrong value of write_same_max_bytes.

We eliminated this using blkdiscard. This is what we get on with this storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m /dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade; done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

real 2m10.153s
user 0m0.003s
sys 0m0.100s

We are investigating why we get low throughput on this server, and also will check
several other servers.

Having a command line option to control this behavior sounds good. I don't

Quoted 3 lines

have enough data to tell what should be the default, but I think the safe way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

Nir

#7 lore raw
Quoted 99 lines · Nir Soffer
Quoted 53 lines · Nir Soffer
Quoted 45 lines · Kevin Wolf

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

Another thing I tried was to change the NBD server (nbdkit) so that

it

Quoted 3 lines
Quoted 3 lines

doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq

-c

Quoted 4 lines
Quoted 4 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per

block

Quoted 3 lines
Quoted 3 lines

of zeroes or data.

Nir: If we could get information from imageio about whether zeroing

is

Quoted 6 lines
Quoted 2 lines

implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Quoted 6 lines

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse performance, so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common case, generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the operation will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it appears to me that we'll have to have a command line option.

Quoted 4 lines

However, I'm curious what your exact use case and the backend used in it is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

Quoted 7 lines

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage, which is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to manual zeroing when the server advertise wrong value of write_same_max_bytes.

We eliminated this using blkdiscard. This is what we get on with this storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m /dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade; done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

real 2m10.153s
user 0m0.003s
sys 0m0.100s

We are investigating why we get low throughput on this server, and also will check
several other servers.

Quoted 8 lines

Having a command line option to control this behavior sounds good. I don't

Quoted 3 lines

have enough data to tell what should be the default, but I think the safe way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

More data from even slower storage - zeroing 10G lv on Kaminario K2

# time blkdiscard -z -p 32m /dev/test_vg/test_lv2
real    50m12.425s
user    0m0.018s
sys     2m6.785s

Maybe something is wrong with this storage, since we see this:

# grep -s "" /sys/block/dm-29/queue/* | grep write_same_max_bytes
/sys/block/dm-29/queue/write_same_max_bytes:512

Since BLKZEROOUT always fallback to manual slow zeroing silently, maybe we can disable the aggressive pre-zero of the entire device for block devices, and keep this optimization for files when fallocate() is supported?

Nir

#8 lore raw

Am 15.11.2018 um 23:27 hat Nir Soffer geschrieben:

Quoted 120 lines · Nir Soffer
Quoted 100 lines · Nir Soffer
Quoted 54 lines · Kevin Wolf
Quoted 46 lines

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

Another thing I tried was to change the NBD server (nbdkit) so that

it

Quoted 3 lines
Quoted 3 lines

doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq

-c

Quoted 4 lines
Quoted 4 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of the write commands is very uneven -- it appears to be send one command per

block

Quoted 3 lines
Quoted 3 lines

of zeroes or data.

Nir: If we could get information from imageio about whether zeroing

is

Quoted 6 lines
Quoted 2 lines

implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Quoted 6 lines

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse performance, so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common case, generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the operation will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it appears to me that we'll have to have a command line option.

Quoted 4 lines

However, I'm curious what your exact use case and the backend used in it is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

Quoted 7 lines

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage, which is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to manual zeroing when the server advertise wrong value of write_same_max_bytes.

We eliminated this using blkdiscard. This is what we get on with this storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m /dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade; done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

real 2m10.153s
user 0m0.003s
sys 0m0.100s

We are investigating why we get low throughput on this server, and also will check
several other servers.

Quoted 8 lines

Having a command line option to control this behavior sounds good. I don't

Quoted 3 lines

have enough data to tell what should be the default, but I think the safe way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

More data from even slower storage - zeroing 10G lv on Kaminario K2

# time blkdiscard -z -p 32m /dev/test_vg/test_lv2
real    50m12.425s
user    0m0.018s
sys     2m6.785s

Maybe something is wrong with this storage, since we see this:

Quoted 7 lines
# grep -s "" /sys/block/dm-29/queue/* | grep write_same_max_bytes
/sys/block/dm-29/queue/write_same_max_bytes:512

Since BLKZEROOUT always fallback to manual slow zeroing silently, maybe we can disable the aggressive pre-zero of the entire device for block devices, and keep this optimization for files when fallocate() is supported?

I'm not sure what the detour through NBD changes, but qemu-img directly on a block device doesn't use BLKZEROOUT first, but FALLOC_FL_PUNCH_HOLE. Maybe we can add a flag that avoids anything that could be slow, such as BLKZEROOUT, as a fallback (and also the slow emulation that QEMU itself would do if all kernel calls fail).

Kevin

#9 lore raw
Quoted 138 lines · Kevin Wolf

Am 15.11.2018 um 23:27 hat Nir Soffer geschrieben:

Quoted 11 lines · Nir Soffer
Quoted 10 lines · Nir Soffer
Quoted 8 lines · Kevin Wolf
Quoted 6 lines

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

Another thing I tried was to change the NBD server (nbdkit) so

that

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

it

Quoted 3 lines
Quoted 3 lines

doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' |

uniq

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-c

Quoted 3 lines
Quoted 3 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of the

write

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

commands is very uneven -- it appears to be send one command per

block

Quoted 3 lines
Quoted 3 lines

of zeroes or data.

Nir: If we could get information from imageio about whether

zeroing

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

is

Quoted 3 lines
Quoted 2 lines

implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse

performance,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common

case,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the

operation

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it

appears

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

to me that we'll have to have a command line option.

However, I'm curious what your exact use case and the backend used

in it

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage,

which

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to

manual

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

zeroing when the server advertise wrong value of write_same_max_bytes.

We eliminated this using blkdiscard. This is what we get on with this storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m

/dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade;

Quoted 26 lines
Quoted 26 lines

done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

real 2m10.153s
user 0m0.003s
sys 0m0.100s

Quoted 5 lines
Quoted 5 lines

We are investigating why we get low throughput on this server, and also will check
several other servers.

Having a command line option to control this behavior sounds good. I

don't

Quoted 1 line
Quoted 1 line
Quoted 1 line

have enough data to tell what should be the default, but I think the

safe

Quoted 20 lines
Quoted 6 lines
Quoted 2 lines

way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

More data from even slower storage - zeroing 10G lv on Kaminario K2

# time blkdiscard -z -p 32m /dev/test_vg/test_lv2
real    50m12.425s
user    0m0.018s
sys     2m6.785s

Maybe something is wrong with this storage, since we see this:

# grep -s "" /sys/block/dm-29/queue/* | grep write_same_max_bytes
/sys/block/dm-29/queue/write_same_max_bytes:512
Quoted 8 lines
Quoted 4 lines

Since BLKZEROOUT always fallback to manual slow zeroing silently, maybe we can disable the aggressive pre-zero of the entire device for block devices, and keep this optimization for files when fallocate() is supported?

I'm not sure what the detour through NBD changes, but qemu-img directly on a block device doesn't use BLKZEROOUT first, but FALLOC_FL_PUNCH_HOLE.

Looking at block/file-posix.c (83c496599cc04926ecbc3e47a37debaa3e38b686) we don't use PUNCH_HOLE for block devices:

1472 if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
1473 return handle_aiocb_write_zeroes_block(aiocb);
1474 }

qemu uses BLKZEROOUT, which is not guaranteed to be fast on storage side, and even worse fallback silently to manual zero if storage does not support WRITE_SAME.

Maybe we can add a flag that avoids anything that

Quoted 3 lines

could be slow, such as BLKZEROOUT, as a fallback (and also the slow emulation that QEMU itself would do if all kernel calls fail).

But the issue here is not how qemu-img handles this case, but how NBD server can handle it. NBD may support zeroing, but there is no way to tell if zeroing is going to be fast, since the backend writing zeros to storage has the same limits of qemu-img.

So I think we need to fix the performance regression in 2.12 by enabling pre-zero of entire disk only if FALLOCATE_FL_PUNCH_HOLE can be used and only if it can be used without a fallback to slow zero method.

Enabling this optimization for anything else requires changing the entire stack (storage, kernel, NBD protocol) to support reporting fast zero capability
or limit zero to fast operations.

Nir

#10 lore raw
Quoted 171 lines · Nir Soffer
Quoted 138 lines · Kevin Wolf

Am 15.11.2018 um 23:27 hat Nir Soffer geschrieben:

Quoted 11 lines · Nir Soffer
Quoted 10 lines · Nir Soffer
Quoted 8 lines · Kevin Wolf
Quoted 6 lines

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

Another thing I tried was to change the NBD server (nbdkit) so

that

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

it

Quoted 3 lines
Quoted 3 lines

doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' |

uniq

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-c

Quoted 3 lines
Quoted 3 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of the

write

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

commands is very uneven -- it appears to be send one command per

block

Quoted 3 lines
Quoted 3 lines

of zeroes or data.

Nir: If we could get information from imageio about whether

zeroing

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

is

Quoted 3 lines
Quoted 2 lines

implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse

performance,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common

case,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the

operation

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it

appears

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

to me that we'll have to have a command line option.

However, I'm curious what your exact use case and the backend used

in it

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage,

which

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to

manual

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

zeroing when the server advertise wrong value of write_same_max_bytes.

We eliminated this using blkdiscard. This is what we get on with this storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m

/dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade;

Quoted 26 lines
Quoted 26 lines

done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

real 2m10.153s
user 0m0.003s
sys 0m0.100s

Quoted 5 lines
Quoted 5 lines

We are investigating why we get low throughput on this server, and also will check
several other servers.

Having a command line option to control this behavior sounds good. I

don't

Quoted 1 line
Quoted 1 line
Quoted 1 line

have enough data to tell what should be the default, but I think the

safe

Quoted 20 lines
Quoted 6 lines
Quoted 2 lines

way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

More data from even slower storage - zeroing 10G lv on Kaminario K2

# time blkdiscard -z -p 32m /dev/test_vg/test_lv2
real    50m12.425s
user    0m0.018s
sys     2m6.785s

Maybe something is wrong with this storage, since we see this:

# grep -s "" /sys/block/dm-29/queue/* | grep write_same_max_bytes
/sys/block/dm-29/queue/write_same_max_bytes:512
Quoted 8 lines
Quoted 4 lines

Since BLKZEROOUT always fallback to manual slow zeroing silently, maybe we can disable the aggressive pre-zero of the entire device for block devices, and keep this optimization for files when fallocate() is supported?

I'm not sure what the detour through NBD changes, but qemu-img directly on a block device doesn't use BLKZEROOUT first, but FALLOC_FL_PUNCH_HOLE.

Looking at block/file-posix.c (83c496599cc04926ecbc3e47a37debaa3e38b686) we don't use PUNCH_HOLE for block devices:

1472 if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
1473 return handle_aiocb_write_zeroes_block(aiocb);
1474 }

qemu uses BLKZEROOUT, which is not guaranteed to be fast on storage side, and even worse fallback silently to manual zero if storage does not support WRITE_SAME.

Maybe we can add a flag that avoids anything that

Quoted 3 lines

could be slow, such as BLKZEROOUT, as a fallback (and also the slow emulation that QEMU itself would do if all kernel calls fail).

But the issue here is not how qemu-img handles this case, but how NBD server can handle it. NBD may support zeroing, but there is no way to tell if zeroing is going to be fast, since the backend writing zeros to storage has the same limits of qemu-img.

Quoted 8 lines

So I think we need to fix the performance regression in 2.12 by enabling pre-zero of entire disk only if FALLOCATE_FL_PUNCH_HOLE can be used and only if it can be used without a fallback to slow zero method.

Enabling this optimization for anything else requires changing the entire stack (storage, kernel, NBD protocol) to support reporting fast zero capability
or limit zero to fast operations.

I may be missing something here, but doesn't imageio know if the backing block device starts out as all zeroes? If so couldn't it maintain a bitmap and simply ignore zero requests sent for unwritten disk blocks?

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
#11 lore raw
Quoted 206 lines · Richard W.M. Jones
Quoted 4 lines · Nir Soffer
Quoted 2 lines · Kevin Wolf

Am 15.11.2018 um 23:27 hat Nir Soffer geschrieben:

Quoted 1 line

On Sun, Nov 11, 2018 at 6:11 PM Nir Soffer <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Wed, Nov 7, 2018 at 7:55 PM Nir Soffer <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Wed, Nov 7, 2018 at 7:27 PM Kevin Wolf <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <

[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines · wrote:
Quoted 2 lines

Another thing I tried was to change the NBD server (nbdkit)

so

Quoted 8 lines
Quoted 8 lines

that

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

it

Quoted 3 lines
Quoted 3 lines

doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed

's/.*\([A-Z][a-z]*\).*/\1/' |

Quoted 5 lines
Quoted 5 lines

uniq

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-c

Quoted 3 lines
Quoted 3 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of

the

Quoted 2 lines
Quoted 2 lines

write

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

commands is very uneven -- it appears to be send one command

per

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

block

Quoted 3 lines
Quoted 3 lines

of zeroes or data.

Nir: If we could get information from imageio about whether

zeroing

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

is

Quoted 1 line
Quoted 1 line

implemented efficiently or not by the backend, we could

change

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

virt-v2v / nbdkit to advertise this back to qemu.

There is no way to detect the capability, ioctl(BLKZEROOUT)

always

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

succeeds, falling back to manual zeroing in the kernel silently

Even if we could, sending zero on the wire from qemu may be

even

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

slower, and it looks like qemu send even more requests in this

case

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

(2154 vs ~1300).

Looks like this optimization in qemu side leads to worse

performance,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend

does

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

support efficient zero writes (which file systems, the most

common

Quoted 2 lines
Quoted 2 lines

case,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

generally do), doing one big write_zeroes request at the start

can

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

improve performance quite a bit.

It seems the problem is that we can't really know whether the

operation

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

will be efficient because the backends generally don't tell us.

Maybe

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

NBD could introduce a flag for this, but in the general case it

appears

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

to me that we'll have to have a command line option.

However, I'm curious what your exact use case and the backend

used

Quoted 2 lines
Quoted 2 lines

in it

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

is? Can something be improved there to actually get efficient

zero

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

writes and get even better performance than by just disabling

the big

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

zero write?

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage,

which

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback

to

Quoted 2 lines
Quoted 2 lines

manual

Quoted 1 line
Quoted 1 line
Quoted 1 line

zeroing when the server advertise wrong value of

write_same_max_bytes.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

We eliminated this using blkdiscard. This is what we get on with

this

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m

/dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade;

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

real 2m10.153s
user 0m0.003s
sys 0m0.100s

We are investigating why we get low throughput on this server, and

also

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

will check
several other servers.

Having a command line option to control this behavior sounds good.

I

Quoted 2 lines
Quoted 2 lines

don't

Quoted 1 line
Quoted 1 line
Quoted 1 line

have enough data to tell what should be the default, but I think

the

Quoted 16 lines
Quoted 16 lines

safe

Quoted 15 lines
Quoted 6 lines
Quoted 2 lines

way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

More data from even slower storage - zeroing 10G lv on Kaminario K2

# time blkdiscard -z -p 32m /dev/test_vg/test_lv2
real    50m12.425s
user    0m0.018s
sys     2m6.785s
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Maybe something is wrong with this storage, since we see this:

# grep -s "" /sys/block/dm-29/queue/* | grep write_same_max_bytes
/sys/block/dm-29/queue/write_same_max_bytes:512

Since BLKZEROOUT always fallback to manual slow zeroing silently, maybe we can disable the aggressive pre-zero of the entire device for block devices, and keep this optimization for files when

fallocate()

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

is supported?

I'm not sure what the detour through NBD changes, but qemu-img directly on a block device doesn't use BLKZEROOUT first, but FALLOC_FL_PUNCH_HOLE.

Looking at block/file-posix.c (83c496599cc04926ecbc3e47a37debaa3e38b686) we don't use PUNCH_HOLE for block devices:

Quoted 6 lines

1472 if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
1473 return handle_aiocb_write_zeroes_block(aiocb);
1474 }

qemu uses BLKZEROOUT, which is not guaranteed to be fast on storage side, and even worse fallback silently to manual zero if storage does not

support

Quoted 9 lines

WRITE_SAME.

Maybe we can add a flag that avoids anything that

Quoted 3 lines

could be slow, such as BLKZEROOUT, as a fallback (and also the slow emulation that QEMU itself would do if all kernel calls fail).

But the issue here is not how qemu-img handles this case, but how NBD server can handle it. NBD may support zeroing, but there is no way to

tell

Quoted 1 line

if zeroing is going to be fast, since the backend writing zeros to

storage

Quoted 6 lines

has the same limits of qemu-img.

So I think we need to fix the performance regression in 2.12 by enabling pre-zero of entire disk only if FALLOCATE_FL_PUNCH_HOLE can be used and only if it can be used without a fallback to slow zero method.

Quoted 7 lines
Quoted 4 lines

Enabling this optimization for anything else requires changing the entire stack (storage, kernel, NBD protocol) to support reporting fast zero capability
or limit zero to fast operations.

I may be missing something here, but doesn't imageio know if the backing block device starts out as all zeroes?

imageio cannot know since it is stateless. When you send a request we don't know what happened before your request.

Engine knows if an image is zeroed when creating a disk for some disks (raw sparse on file storage) so it can report this info, and nbdkit can use this when writing zeros...

Quoted 4 lines

If so couldn't it
maintain a bitmap and simply ignore zero requests sent for unwritten disk blocks?

But if nbdkit knows that it is writing to a new zeroed image, it would be better to report it back to qemu, so qemu can skip zeroing the entire device.

This does not solve the issue with block storage which is the most interesting
use case for oVirt.

Nir

#12 lore raw
In reply to Nir Soffer

Am 17.11.2018 um 21:59 hat Nir Soffer geschrieben:

Quoted 153 lines · Kevin Wolf
Quoted 139 lines

Am 15.11.2018 um 23:27 hat Nir Soffer geschrieben:

Quoted 11 lines · Nir Soffer
Quoted 10 lines · Nir Soffer
Quoted 8 lines · Kevin Wolf
Quoted 6 lines

Am 07.11.2018 um 15:56 hat Nir Soffer geschrieben:

Quoted 1 line

Wed, Nov 7, 2018 at 4:36 PM Richard W.M. Jones <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

Another thing I tried was to change the NBD server (nbdkit) so

that

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

it

Quoted 3 lines
Quoted 3 lines

doesn't advertise zero support to the client:

  $ nbdkit --filter=log --filter=nozero memory size=6G

logfile=/tmp/log \

Quoted 2 lines
Quoted 2 lines
      --run './qemu-img convert ./fedora-28.img -n $nbd'
  $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' |

uniq

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-c

Quoted 3 lines
Quoted 3 lines
   2154 Write

Not surprisingly no zero commands are issued. The size of the

write

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

commands is very uneven -- it appears to be send one command per

block

Quoted 3 lines
Quoted 3 lines

of zeroes or data.

Nir: If we could get information from imageio about whether

zeroing

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

is

Quoted 3 lines
Quoted 2 lines

implemented efficiently or not by the backend, we could change virt-v2v / nbdkit to advertise this back to qemu.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

There is no way to detect the capability, ioctl(BLKZEROOUT) always succeeds, falling back to manual zeroing in the kernel silently

Even if we could, sending zero on the wire from qemu may be even slower, and it looks like qemu send even more requests in this case (2154 vs ~1300).

Looks like this optimization in qemu side leads to worse

performance,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

so it should not be enabled by default.

Well, that's overgeneralising your case a bit. If the backend does support efficient zero writes (which file systems, the most common

case,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

generally do), doing one big write_zeroes request at the start can improve performance quite a bit.

It seems the problem is that we can't really know whether the

operation

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

will be efficient because the backends generally don't tell us. Maybe NBD could introduce a flag for this, but in the general case it

appears

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

to me that we'll have to have a command line option.

However, I'm curious what your exact use case and the backend used

in it

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

is? Can something be improved there to actually get efficient zero writes and get even better performance than by just disabling the big zero write?

The backend is some NetApp storage connected via FC. I don't have more info on this. We get zero rate of about 1G/s on this storage,

which

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

is quite slow compared with other storage we tested.

One option we check now is if this is the kernel silent fallback to

manual

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

zeroing when the server advertise wrong value of write_same_max_bytes.

We eliminated this using blkdiscard. This is what we get on with this storage
zeroing 100G LV:

for i in 1 2 4 8 16 32; do time blkdiscard -z -p ${i}m

/dev/6e1d84f9-f939-46e9-b108-0427a08c280c/2d5c06ce-6536-4b3c-a7b6-13c6d8e55ade;

Quoted 26 lines
Quoted 26 lines

done

real 4m50.851s
user 0m0.065s
sys 0m1.482s

real 4m30.504s
user 0m0.047s
sys 0m0.870s

real 4m19.443s
user 0m0.029s
sys 0m0.508s

real 4m13.016s
user 0m0.020s
sys 0m0.284s

real 2m45.888s
user 0m0.011s
sys 0m0.162s

real 2m10.153s
user 0m0.003s
sys 0m0.100s

Quoted 5 lines
Quoted 5 lines

We are investigating why we get low throughput on this server, and also will check
several other servers.

Having a command line option to control this behavior sounds good. I

don't

Quoted 1 line
Quoted 1 line
Quoted 1 line

have enough data to tell what should be the default, but I think the

safe

Quoted 20 lines
Quoted 6 lines
Quoted 2 lines

way would be to keep old behavior.

We file this bug:
https://bugzilla.redhat.com/1648622

More data from even slower storage - zeroing 10G lv on Kaminario K2

# time blkdiscard -z -p 32m /dev/test_vg/test_lv2
real    50m12.425s
user    0m0.018s
sys     2m6.785s

Maybe something is wrong with this storage, since we see this:

# grep -s "" /sys/block/dm-29/queue/* | grep write_same_max_bytes
/sys/block/dm-29/queue/write_same_max_bytes:512
Quoted 8 lines
Quoted 4 lines

Since BLKZEROOUT always fallback to manual slow zeroing silently, maybe we can disable the aggressive pre-zero of the entire device for block devices, and keep this optimization for files when fallocate() is supported?

I'm not sure what the detour through NBD changes, but qemu-img directly on a block device doesn't use BLKZEROOUT first, but FALLOC_FL_PUNCH_HOLE.

Looking at block/file-posix.c (83c496599cc04926ecbc3e47a37debaa3e38b686) we don't use PUNCH_HOLE for block devices:

Quoted 7 lines

1472 if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
1473 return handle_aiocb_write_zeroes_block(aiocb);
1474 }

qemu uses BLKZEROOUT, which is not guaranteed to be fast on storage side, and even worse fallback silently to manual zero if storage does not support WRITE_SAME.

We only get there as a fallback. The normal path for supported zero writes is like this:

1. convert_do_copy()
2. blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP)
3. bdrv_make_zero(blk->root, flags)
4. a. bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL) Skip the zero write if the block is already zero
Why don't we hit this path with NBD?
b. bdrv_pwrite_zeroes(child, offset, bytes, flags)
5. bdrv_prwv_co(BDRV_REQ_ZERO_WRITE | flags)
flags is now BDRV_REQ_ZERO_WRITE | BDRV_REQ_MAY_UNMAP
6. bdrv_co_pwritev()
bdrv_co_do_zero_pwritev()
7. bdrv_aligned_pwritev(BDRV_REQ_ZERO_WRITE | BDRV_REQ_MAY_UNMAP)
8. bdrv_co_do_pwrite_zeroes(BDRV_REQ_ZERO_WRITE | BDRV_REQ_MAY_UNMAP)
9. drv->bdrv_co_pwrite_zeroes(flags & bs->supported_zero_flags)
file-posix: bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP

10. raw_co_pwrite_zeroes(BDRV_REQ_MAY_UNMAP=
11. paio_submit_co(QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD)
12. aio_worker()
13. handle_aiocb_write_zeroes_unmap()
14. do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,

                 aiocb->aio_offset, aiocb->aio_nbytes);

Only if this fails, we try other methods. And without the BDRV_REQ_MAY_UNMAP flag, we would immediately try BLKZEROOUT.

Quoted 9 lines

Maybe we can add a flag that avoids anything that

Quoted 3 lines

could be slow, such as BLKZEROOUT, as a fallback (and also the slow emulation that QEMU itself would do if all kernel calls fail).

But the issue here is not how qemu-img handles this case, but how NBD server can handle it. NBD may support zeroing, but there is no way to tell if zeroing is going to be fast, since the backend writing zeros to storage has the same limits of qemu-img.

I suppose we could add the same flag to NBD (write zeroes, but only if it's efficient). But first we need to solve the local case because NBD will always build on that.

Quoted 7 lines

So I think we need to fix the performance regression in 2.12 by enabling pre-zero of entire disk only if FALLOCATE_FL_PUNCH_HOLE can be used and only if it can be used without a fallback to slow zero method.

Enabling this optimization for anything else requires changing the entire stack (storage, kernel, NBD protocol) to support reporting fast zero capability or limit zero to fast operations.

Yes, I agree.

Kevin

#13 lore raw
In reply to Richard W.M. Jones
Quoted 2 lines · Richard W.M. Jones

(I'm not going to claim this is a bug, but it causes a large, easily measurable performance regression in virt-v2v).

I haven't closely looked at at this email thread yet, but a quick first impression:

Quoted 8 lines

In qemu 2.12 this behaviour changed:

   $ nbdkit --filter=log memory size=6G logfile=/tmp/log \
       --run './qemu-img convert ./fedora-28.img -n $nbd'
   $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
       193 Zero
      1246 Write
Quoted 8 lines

It now zeroes the whole disk up front and then writes data over the top of the zeroed blocks.

The reason for the performance regression is that in the first case we write 6G in total. In the second case we write 6G of zeroes up front, followed by the amount of data in the disk image (in this case the test disk image contains 1G of non-sparse data, so we write about 7G in total).

There was talk on the NBD list a while ago about the idea of letting the server advertise to the client when the image is known to start in an all-zero state, so that the client doesn't have to waste time writing zeroes (or relying on repeated NBD_CMD_BLOCK_STATUS calls to learn the same). This may be justification for reviving that topic.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#14 lore raw
Quoted 25 lines · Eric Blake
Quoted 2 lines · Richard W.M. Jones

(I'm not going to claim this is a bug, but it causes a large, easily measurable performance regression in virt-v2v).

I haven't closely looked at at this email thread yet, but a quick first impression:

Quoted 8 lines

In qemu 2.12 this behaviour changed:

   $ nbdkit --filter=log memory size=6G logfile=/tmp/log \
       --run './qemu-img convert ./fedora-28.img -n $nbd'
   $ grep '\.\.\.$' /tmp/log | sed 's/.*\([A-Z][a-z]*\).*/\1/' | uniq -c
       193 Zero
      1246 Write
Quoted 8 lines

It now zeroes the whole disk up front and then writes data over the top of the zeroed blocks.

The reason for the performance regression is that in the first case we write 6G in total. In the second case we write 6G of zeroes up front, followed by the amount of data in the disk image (in this case the test disk image contains 1G of non-sparse data, so we write about 7G in total).

Quoted 6 lines

There was talk on the NBD list a while ago about the idea of letting the server advertise to the client when the image is known to start in an all-zero state, so that the client doesn't have to waste time writing zeroes (or relying on repeated NBD_CMD_BLOCK_STATUS calls to learn the same). This may be justification for reviving that topic.

This is a good idea in general, since in some cases we know that a volume is already zeroed (e.g. new file on NFS/Gluster storage). But with block storage, we typically don't have any guarantee about storage content, and qemu need to zero or write the entire device, so this does not solve the issue discussed in this thread.

Nir