qemu-e2k/block
Nir Soffer 3a20013fbb block: posix: Always allocate the first block
When creating an image with preallocation "off" or "falloc", the first
block of the image is typically not allocated. When using Gluster
storage backed by XFS filesystem, reading this block using direct I/O
succeeds regardless of request length, fooling alignment detection.

In this case we fallback to a safe value (4096) instead of the optimal
value (512), which may lead to unneeded data copying when aligning
requests.  Allocating the first block avoids the fallback.

Since we allocate the first block even with preallocation=off, we no
longer create images with zero disk size:

    $ ./qemu-img create -f raw test.raw 1g
    Formatting 'test.raw', fmt=raw size=1073741824

    $ ls -lhs test.raw
    4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw

And converting the image requires additional cluster:

    $ ./qemu-img measure -f raw -O qcow2 test.raw
    required size: 458752
    fully allocated size: 1074135040

When using format like vmdk with multiple files per image, we allocate
one block per file:

    $ ./qemu-img create -f vmdk -o subformat=twoGbMaxExtentFlat test.vmdk 4g
    Formatting 'test.vmdk', fmt=vmdk size=4294967296 compat6=off hwversion=undefined subformat=twoGbMaxExtentFlat

    $ ls -lhs test*.vmdk
    4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f001.vmdk
    4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f002.vmdk
    4.0K -rw-r--r--. 1 nsoffer nsoffer  353 Aug 27 03:23 test.vmdk

I did quick performance test for copying disks with qemu-img convert to
new raw target image to Gluster storage with sector size of 512 bytes:

    for i in $(seq 10); do
        rm -f dst.raw
        sleep 10
        time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.raw
    done

Here is a table comparing the total time spent:

Type    Before(s)   After(s)    Diff(%)
---------------------------------------
real      530.028    469.123      -11.4
user       17.204     10.768      -37.4
sys        17.881      7.011      -60.7

We can see very clear improvement in CPU usage.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Message-id: 20190827010528.8818-2-nsoffer@redhat.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-09-03 14:55:35 +02:00
..
Makefile.objs ssh: switch from libssh2 to libssh 2019-06-24 16:01:04 +02:00
accounting.c block/accounting: introduce latency histogram 2018-03-19 14:58:37 -05:00
backup.c block: define .*_part io handlers in BlockDriver 2019-08-27 14:58:42 +01:00
blkdebug.c blkdebug: Inject errors on .bdrv_co_block_status() 2019-06-14 14:16:57 +02:00
blklogwrites.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
blkreplay.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
blkverify.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
block-backend.c Block layer patches: 2019-08-16 16:43:46 +01:00
bochs.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
cloop.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
commit.c block-backend: Queue requests while drained 2019-08-16 10:25:16 +02:00
copy-on-read.c block/copy-on-read: Fix permissions for inactive node 2019-07-30 12:25:43 +02:00
create.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
crypto.c LUKS: support preallocation 2019-08-19 17:13:26 +02:00
crypto.h Clean up ill-advised or unusual header guards 2019-05-13 08:58:55 +02:00
curl.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
dirty-bitmap.c qapi: implement block-dirty-bitmap-remove transaction action 2019-08-16 16:28:03 -04:00
dmg-bz2.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
dmg-lzfse.c block: adding lzfse decompressing support as a module. 2018-12-14 11:52:40 +01:00
dmg.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
dmg.h Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
file-posix.c block: posix: Always allocate the first block 2019-09-03 14:55:35 +02:00
file-win32.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
gluster.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
io.c block/io: introduce bdrv_co_p{read, write}v_part 2019-08-27 14:58:42 +01:00
iscsi-opts.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
iscsi.c iscsi: base all handling of check condition on scsi_sense_to_errno 2019-07-15 11:20:42 +02:00
linux-aio.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
mirror.c mirror: Fix bdrv_has_zero_init() use 2019-08-19 17:13:26 +02:00
nbd.c nbd patches for 2019-08-15 2019-08-16 15:53:37 +01:00
nfs.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
null.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
nvme.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
parallels.c block: Use bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
parallels.h Clean up includes 2018-02-09 05:05:11 +01:00
qapi.c qapi: add dirty-bitmaps to query-named-block-nodes result 2019-08-16 18:29:43 -04:00
qcow.c block/qcow: Improve error when opening qcow2 files as qcow 2019-07-08 16:00:26 +02:00
qcow2-bitmap.c qcow2-bitmap: initialize bitmap directory alignment 2019-05-28 20:30:55 +02:00
qcow2-cache.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
qcow2-cluster.c block/qcow2: implement .bdrv_co_pwritev(_compressed)_part 2019-08-27 14:58:42 +01:00
qcow2-refcount.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
qcow2-snapshot.c qcow2.h: add missing include 2019-05-28 20:30:55 +02:00
qcow2-threads.c qcow2: do encryption in threads 2019-05-28 20:30:55 +02:00
qcow2.c block/qcow2: implement .bdrv_co_pwritev(_compressed)_part 2019-08-27 14:58:42 +01:00
qcow2.h block/qcow2: implement .bdrv_co_pwritev(_compressed)_part 2019-08-27 14:58:42 +01:00
qed-check.c block/qed: add missed coroutine_fn markers 2019-04-30 15:29:00 +02:00
qed-cluster.c qed: protect table cache with CoMutex 2017-07-17 11:34:11 +08:00
qed-l2-cache.c qed: protect table cache with CoMutex 2017-07-17 11:34:11 +08:00
qed-table.c block/qed: add missed coroutine_fn markers 2019-04-30 15:29:00 +02:00
qed.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
qed.h block/qed: add missed coroutine_fn markers 2019-04-30 15:29:00 +02:00
quorum.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
raw-format.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
rbd.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
replication.c block/backup: Add mirror sync mode 'bitmap' 2019-08-16 16:28:02 -04:00
sheepdog.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
snapshot.c block/snapshot: remove bdrv_snapshot_delete_by_id_or_name 2019-02-25 15:03:18 +01:00
ssh.c block: Implement .bdrv_has_zero_init_truncate() 2019-08-19 17:13:26 +02:00
stream.c block/stream: use BDRV_REQ_PREFETCH 2019-08-15 13:22:13 -05:00
throttle-groups.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
throttle.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
trace-events block/backup: teach TOP to never copy unallocated regions 2019-08-16 16:28:03 -04:00
vdi.c vdi: Make block_status recurse for fixed images 2019-08-19 17:13:26 +02:00
vhdx-endian.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
vhdx-log.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
vhdx.c vhdx: Fix .bdrv_has_zero_init() 2019-08-19 17:13:26 +02:00
vhdx.h block/vhdx: Use IEC binary prefixes for size constants 2019-04-30 15:29:00 +02:00
vmdk.c vmdk: Make block_status recurse for flat extents 2019-08-19 17:13:26 +02:00
vpc.c vpc: Do not return RAW from block_status 2019-08-19 17:13:26 +02:00
vvfat.c qemu-common: Move qemu_isalnum() etc. to qemu/ctype.h 2019-06-11 20:22:09 +02:00
vxhs.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
win32-aio.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
write-threshold.c qapi: Drop qapi_event_send_FOO()'s Error ** argument 2018-08-28 18:21:38 +02:00