qemu-img: align result of is_allocated_sectors
commit8dcd3c9b91a300c86e315d7e5427dce1383f7387
authorPeter Lieven <pl@kamp.de>
Thu, 12 Jul 2018 13:00:10 +0000 (12 15:00 +0200)
committerKevin Wolf <kwolf@redhat.com>
Thu, 12 Jul 2018 16:24:08 +0000 (12 18:24 +0200)
tree3f227987ac0ce9f53daf8508ba5ca6f14527ddc2
parent740842c9656cd5dbc9ccf2ea0c3a74f0ba35144a
qemu-img: align result of is_allocated_sectors

We currently don't enforce that the sparse segments we detect during convert are
aligned. This leads to unnecessary and costly read-modify-write cycles either
internally in Qemu or in the background on the storage device as nearly all
modern filesystems or hardware have a 4k alignment internally.

This patch modifies is_allocated_sectors so that its *pnum result will always
end at an alignment boundary. This way all requests will end at an alignment
boundary. The start of all requests will also be aligned as long as the results
of get_block_status do not lead to an unaligned offset.

The number of RMW cycles when converting an example image [1] to a raw device that
has 4k sector size is about 4600 4k read requests to perform a total of about 15000
write requests. With this path the additional 4600 read requests are eliminated while
the number of total write requests stays constant.

[1] https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.vmdk

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-img.c
tests/qemu-iotests/122.out