[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [RFC 3/3] qcow2: Evaluate rotational info
From: |
Max Reitz |
Subject: |
[Qemu-block] [RFC 3/3] qcow2: Evaluate rotational info |
Date: |
Fri, 24 May 2019 19:28:12 +0200 |
The new handle_alloc_space() function only speeds up the allocation of
new ranges on solid-state drives. We should skip it if we know that the
file is stored on a rotating disk.
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2.h | 3 +++
block/qcow2.c | 34 ++++++++++++++++++++++++++++++----
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/block/qcow2.h b/block/qcow2.h
index fc1b0d3c1e..5052ab187f 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -359,6 +359,9 @@ typedef struct BDRVQcow2State {
bool metadata_preallocation_checked;
bool metadata_preallocation;
+
+ /* True if the image is stored on a rotating disk */
+ bool optimize_for_rotating;
} BDRVQcow2State;
typedef struct Qcow2COWRegion {
diff --git a/block/qcow2.c b/block/qcow2.c
index 14f914117f..b4df6d5085 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1197,6 +1197,22 @@ static int qcow2_update_options(BlockDriverState *bs,
QDict *options,
return ret;
}
+static void qcow2_update_rotational_info(BlockDriverState *bs)
+{
+ BDRVQcow2State *s = bs->opaque;
+ BlockDriverInfo file_bdi;
+
+ s->optimize_for_rotating = false;
+
+ if (bdrv_get_info(bs->file->bs, &file_bdi) < 0) {
+ return;
+ }
+
+ s->optimize_for_rotating =
+ file_bdi.has_rotational_info &&
+ file_bdi.rotational_info == IMAGE_ROTATIONAL_INFO_ROTATING;
+}
+
/* Called with s->lock held. */
static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
int flags, Error **errp)
@@ -1461,6 +1477,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState
*bs, QDict *options,
}
}
+ qcow2_update_rotational_info(bs);
+
/* Parse driver-specific options */
ret = qcow2_update_options(bs, options, flags, errp);
if (ret < 0) {
@@ -1829,6 +1847,8 @@ static void qcow2_reopen_commit(BDRVReopenState *state)
{
qcow2_update_options_commit(state->bs, state->opaque);
g_free(state->opaque);
+
+ qcow2_update_rotational_info(state->bs);
}
static void qcow2_reopen_abort(BDRVReopenState *state)
@@ -2297,10 +2317,16 @@ static coroutine_fn int
qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
qemu_iovec_add(&hd_qiov, cluster_data, cur_bytes);
}
- /* Try to efficiently initialize the physical space with zeroes */
- ret = handle_alloc_space(bs, l2meta);
- if (ret < 0) {
- goto out_unlocked;
+ /*
+ * Try to efficiently initialize the physical space with zeroes.
+ * This incurs a performance penalty on rotating disks, so
+ * avoid doing it there.
+ */
+ if (!s->optimize_for_rotating) {
+ ret = handle_alloc_space(bs, l2meta);
+ if (ret < 0) {
+ goto out_unlocked;
+ }
}
/* If we need to do COW, check if it's possible to merge the
--
2.21.0
- [Qemu-block] [RFC 0/3] block: Inquire images’ rotational info, Max Reitz, 2019/05/24
- [Qemu-block] [RFC 3/3] qcow2: Evaluate rotational info,
Max Reitz <=
- [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Max Reitz, 2019/05/24
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Alberto Garcia, 2019/05/26
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Max Reitz, 2019/05/27
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Alberto Garcia, 2019/05/27
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Max Reitz, 2019/05/27
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Anton Nefedov, 2019/05/27
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Max Reitz, 2019/05/27
- Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Alberto Garcia, 2019/05/27
Re: [Qemu-block] [RFC 1/3] block: Add ImageRotationalInfo, Kevin Wolf, 2019/05/29