OSDN Git Service

block: Add flag to avoid wasted work in bdrv_is_allocated()
authorEric Blake <eblake@redhat.com>
Thu, 12 Oct 2017 03:46:58 +0000 (22:46 -0500)
committerKevin Wolf <kwolf@redhat.com>
Thu, 26 Oct 2017 12:45:57 +0000 (14:45 +0200)
commitc9ce8c4da65b0c2b1dc82cbf2328ff3e23d76943
tree09c5f8509ccd75d44a0a3686820166c8fcc3705e
parent298a1665a2800f7264e483c2dd1f551574243a2f
block: Add flag to avoid wasted work in bdrv_is_allocated()

Not all callers care about which BDS owns the mapping for a given
range of the file, or where the zeroes lie within that mapping.  In
particular, bdrv_is_allocated() cares more about finding the
largest run of allocated data from the guest perspective, whether
or not that data is consecutive from the host perspective, and
whether or not the data reads as zero.  Therefore, doing subsequent
refinements such as checking how much of the format-layer
allocation also satisfies BDRV_BLOCK_ZERO at the protocol layer is
wasted work - in the best case, it just costs extra CPU cycles
during a single bdrv_is_allocated(), but in the worst case, it
results in a smaller *pnum, and forces callers to iterate through
more status probes when visiting the entire file for even more
extra CPU cycles.

This patch only optimizes the block layer (no behavior change when
want_zero is true, but skip unnecessary effort when it is false).
Then when subsequent patches tweak the driver callback to be
byte-based, we can also pass this hint through to the driver.

Tweak BdrvCoGetBlockStatusData to declare arguments in parameter
order, rather than mixing things up (minimizing padding is not
necessary here).

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/io.c