qemu/block
Alberto Garcia 7061a07898 qcow2: Optimize the refcount-block overlap check
The metadata overlap checks introduced in a40f1c2add help detect
corruption in the qcow2 image by verifying that data writes don't
overlap with existing metadata sections.

The 'refcount-block' check in particular iterates over the refcount
table in order to get the addresses of all refcount blocks and check
that none of them overlap with the region where we want to write.

The problem with the refcount table is that since it always occupies
complete clusters its size is usually very big. With the default
values of cluster_size=64KB and refcount_bits=16 this table holds 8192
entries, each one of them enough to map 2GB worth of host clusters.

So unless we're using images with several TB of allocated data this
table is going to be mostly empty, and iterating over it is a waste of
CPU. If the storage backend is fast enough this can have an effect on
I/O performance.

This patch keeps the index of the last used (i.e. non-zero) entry in
the refcount table and updates it every time the table changes. The
refcount-block overlap check then uses that index instead of reading
the whole table.

In my tests with a 4GB qcow2 file stored in RAM this doubles the
amount of write IOPS.

Signed-off-by: Alberto Garcia <berto@igalia.com>
Message-id: 20170201123828.4815-1-berto@igalia.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-02-12 00:47:43 +01:00
..
Makefile.objs block/iscsi: statically link qemu_iscsi_opts 2017-01-27 18:07:58 +01:00
accounting.c block: Clean up includes 2016-01-20 13:36:23 +01:00
archipelago.c block: use aio_bh_schedule_oneshot 2016-10-07 13:34:07 +02:00
backup.c blockjob: refactor backup_start as backup_job_create 2016-11-14 22:47:34 -05:00
blkdebug.c blkdebug: Implement bdrv_co_preadv/pwritev/flush 2017-01-09 13:30:52 +01:00
blkreplay.c replay: allow replay stopping and restarting 2016-09-27 11:57:30 +02:00
blkverify.c blkverify: Implement bdrv_co_preadv/pwritev/flush 2017-01-09 13:30:52 +01:00
block-backend.c block-backend: Always notify on blk_eject 2016-11-14 11:15:54 -05:00
bochs.c block: Convert bdrv_co_preadv/pwritev to BdrvChild 2016-07-05 16:46:27 +02:00
cloop.c block: Convert bdrv_pread(v) to BdrvChild 2016-07-05 16:46:27 +02:00
commit.c blockjob: add block_job_start 2016-11-14 22:47:34 -05:00
crypto.c crypto: make PBKDF iterations configurable for LUKS format 2016-09-19 16:30:45 +01:00
curl.c aio: add AioPollFn and io_poll() interface 2017-01-03 16:38:48 +00:00
dirty-bitmap.c block: More operations for meta dirty bitmap 2016-10-24 17:56:07 +02:00
dmg-bz2.c dmg: Move libbz2 code to dmg-bz2.so 2016-10-07 14:14:06 +02:00
dmg.c dmg: Move libbz2 code to dmg-bz2.so 2016-10-07 14:14:06 +02:00
dmg.h dmg: Move libbz2 code to dmg-bz2.so 2016-10-07 14:14:06 +02:00
file-posix.c block: get max_transfer limit for char (scsi-generic) devices 2017-01-27 18:07:31 +01:00
file-win32.c block: Rename raw-{posix,win32} to file-*.c 2017-01-09 13:30:53 +01:00
gluster.c block: Rename raw-{posix,win32} to file-*.c 2017-01-09 13:30:53 +01:00
io.c block: get rid of bdrv_io_unplugged_begin/end 2017-01-16 13:25:17 +00:00
iscsi-opts.c block/iscsi: statically link qemu_iscsi_opts 2017-01-27 18:07:58 +01:00
iscsi.c block/iscsi: avoid data corruption with cache=writeback 2017-01-27 18:07:31 +01:00
linux-aio.c linux-aio: poll ring for completions 2017-01-03 16:38:48 +00:00
mirror.c mirror: do not flush every time the disks are synced 2016-11-14 22:49:26 -05:00
nbd-client.c aio: add AioPollFn and io_poll() interface 2017-01-03 16:38:48 +00:00
nbd-client.h nbd: Implement NBD_CMD_WRITE_ZEROES on client 2016-11-02 09:28:56 +01:00
nbd.c block/nbd: Fix the leaked visitor 2016-11-11 15:54:55 +01:00
nfs.c block/nfs: fix naming of runtime opts 2017-02-12 00:47:42 +01:00
null.c block: use aio_bh_schedule_oneshot 2016-10-07 13:34:07 +02:00
parallels.c block/parallels: check new image size 2016-08-05 09:59:06 +01:00
qapi.c block/qapi: reduce the execution time of qmp_query_blockstats 2017-02-12 00:47:42 +01:00
qcow.c migration: disallow migrate_add_blocker during migration 2017-01-24 18:00:30 +00:00
qcow2-cache.c qcow2: Remove stale comment 2016-11-25 13:51:30 +01:00
qcow2-cluster.c qcow2: Support BDRV_REQ_MAY_UNMAP 2016-10-24 17:54:03 +02:00
qcow2-refcount.c qcow2: Optimize the refcount-block overlap check 2017-02-12 00:47:43 +01:00
qcow2-snapshot.c block: Convert bdrv_pwrite(v/_sync) to BdrvChild 2016-07-05 16:46:27 +02:00
qcow2.c qcow2: Optimize the refcount-block overlap check 2017-02-12 00:47:43 +01:00
qcow2.h qcow2: Optimize the refcount-block overlap check 2017-02-12 00:47:43 +01:00
qed-check.c qed: Use DIV_ROUND_UP 2016-06-07 18:19:24 +03:00
qed-cluster.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-gencb.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-l2-cache.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-table.c block: introduce BDRV_POLL_WHILE 2016-10-28 21:50:18 +08:00
qed.c qed: Implement .bdrv_drain 2016-10-28 21:50:18 +08:00
qed.h block: use aio_bh_schedule_oneshot 2016-10-07 13:34:07 +02:00
quorum.c quorum: Clean up quorum_aio_get() 2017-01-09 13:30:52 +01:00
raw-format.c block: Rename raw_bsd to raw-format.c 2017-01-09 13:30:52 +01:00
rbd.c rbd: make the code more readable 2016-11-01 07:55:57 -04:00
replication.c blockjob: refactor backup_start as backup_job_create 2016-11-14 22:47:34 -05:00
sheepdog.c sheepdog: reorganize check for overlapping requests 2017-02-01 00:17:20 -05:00
snapshot.c error: Remove NULL checks on error_propagate() calls 2016-06-20 16:38:13 +02:00
ssh.c aio: add AioPollFn and io_poll() interface 2017-01-03 16:38:48 +00:00
stream.c blockjob: add block_job_start 2016-11-14 22:47:34 -05:00
throttle-groups.c throttle: Correct access to wrong BlockBackendPublic structures 2016-10-24 17:54:03 +02:00
trace-events trace: clean up trace-events files 2017-01-31 17:12:15 +00:00
vdi.c migration: disallow migrate_add_blocker during migration 2017-01-24 18:00:30 +00:00
vhdx-endian.c vhdx: Use QEMU UUID API 2016-09-23 11:42:52 +08:00
vhdx-log.c block: Convert bdrv_pwrite(v/_sync) to BdrvChild 2016-07-05 16:46:27 +02:00
vhdx.c migration: disallow migrate_add_blocker during migration 2017-01-24 18:00:30 +00:00
vhdx.h block: vhdx - update PAYLOAD_BLOCK_UNMAPPED value to match 1.00 spec 2014-12-12 15:42:22 +00:00
vmdk.c block/vmdk: Fix the endian problem of buf_len and lba 2017-02-12 00:47:42 +01:00
vpc.c migration: disallow migrate_add_blocker during migration 2017-01-24 18:00:30 +00:00
vvfat.c migration: disallow migrate_add_blocker during migration 2017-01-24 18:00:30 +00:00
win32-aio.c aio: add AioPollFn and io_poll() interface 2017-01-03 16:38:48 +00:00
write-threshold.c block: use bdrv_add_before_write_notifier 2016-10-07 13:34:07 +02:00