From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Anton Nefedov <anton.nefedov@virtuozzo.com>,
Alberto Garcia <berto@igalia.com>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Subject: [Qemu-devel] [RFC 3/3] qcow2: Evaluate rotational info
Date: Fri, 24 May 2019 19:28:12 +0200 [thread overview]
Message-ID: <20190524172812.27308-4-mreitz@redhat.com> (raw)
In-Reply-To: <20190524172812.27308-1-mreitz@redhat.com>
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 <mreitz@redhat.com>
---
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
next prev parent reply other threads:[~2019-05-24 17:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 17:28 [Qemu-devel] [RFC 0/3] block: Inquire images’ rotational info Max Reitz
2019-05-24 17:28 ` [Qemu-devel] [RFC 1/3] block: Add ImageRotationalInfo Max Reitz
2019-05-26 15:08 ` Alberto Garcia
2019-05-27 12:16 ` Max Reitz
2019-05-27 12:37 ` Alberto Garcia
2019-05-27 12:57 ` Max Reitz
2019-05-27 13:44 ` Anton Nefedov
2019-05-27 13:51 ` Max Reitz
2019-05-27 13:53 ` Alberto Garcia
2019-05-29 22:10 ` Kevin Wolf
2019-05-31 11:51 ` Max Reitz
2019-05-31 14:02 ` Kevin Wolf
2019-05-24 17:28 ` [Qemu-devel] [RFC 2/3] file-posix: Inquire rotational status Max Reitz
2019-05-24 17:28 ` Max Reitz [this message]
2019-05-24 17:52 ` [Qemu-devel] [RFC 0/3] block: Inquire images’ rotational info Eric Blake
2019-06-13 16:12 ` Stefan Hajnoczi
2019-06-13 16:20 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190524172812.27308-4-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=anton.nefedov@virtuozzo.com \
--cc=berto@igalia.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).