From: Eric Blake <eblake@redhat.com>
To: Alberto Garcia <berto@igalia.com>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>, "Denis V . Lunev" <den@openvz.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 4/7] qcow2: Split do_perform_cow() into _read(), _encrypt() and _write()
Date: Fri, 9 Jun 2017 09:53:05 -0500 [thread overview]
Message-ID: <36215351-07f7-43ab-bad5-96ed1f6ecd61@redhat.com> (raw)
In-Reply-To: <643c9f0a83c8f5c913a55a556dcddd13754d1275.1496844254.git.berto@igalia.com>
[-- Attachment #1: Type: text/plain, Size: 3321 bytes --]
On 06/07/2017 09:08 AM, Alberto Garcia wrote:
> This patch splits do_perform_cow() into three separate functions to
> read, encrypt and write the COW regions.
>
> perform_cow() can now read both regions first, then encrypt them and
> finally write them to disk. The memory allocation is also done in
> this function now, using one single buffer large enough to hold both
> regions.
>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
> block/qcow2-cluster.c | 114 +++++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 84 insertions(+), 30 deletions(-)
>
Let's suppose we have a guest issuing 512-byte aligned requests and a
host that requires 4k alignment; and the guest does an operation that
needs a COW with one sector at both the front and end of the cluster.
> @@ -760,22 +776,59 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
> BDRVQcow2State *s = bs->opaque;
> Qcow2COWRegion *start = &m->cow_start;
> Qcow2COWRegion *end = &m->cow_end;
> + unsigned buffer_size = start->nb_bytes + end->nb_bytes;
This sets buffer_size to 1024 initially.
> + uint8_t *start_buffer, *end_buffer;
> int ret;
>
> + assert(start->nb_bytes <= UINT_MAX - end->nb_bytes);
> +
> if (start->nb_bytes == 0 && end->nb_bytes == 0) {
> return 0;
> }
>
> + /* Reserve a buffer large enough to store the data from both the
> + * start and end COW regions */
> + start_buffer = qemu_try_blockalign(bs, buffer_size);
This is going to allocate a bigger buffer, namely one that is at least
4k in size (at least, that's my understanding - the block device is able
to track its preferred IO size/alignment).
> + if (start_buffer == NULL) {
> + return -ENOMEM;
> + }
> + /* The part of the buffer where the end region is located */
> + end_buffer = start_buffer + start->nb_bytes;
But now end_buffer does not have optimal alignment. In the old code, we
called qemu_try_blockalign() twice, so that both read()s were called on
a 4k boundary; but now, the end read() is called unaligned to a 4k
boundary. Of course, since we're only reading 512 bytes, instead of 4k,
it MIGHT not matter, but I don't know if we are going to cause a bounce
buffer to come into play that we could otherwise avoid if we were
smarter with our alignments. Is that something we need to analyze
further, or even possibly intentionally over-allocate our buffer to
ensure optimal read alignments?
> + /* And now we can write everything */
> + ret = do_perform_cow_write(bs, m->alloc_offset, start->offset,
> + start_buffer, start->nb_bytes);
> + if (ret < 0) {
> + goto fail;
> + }
>
> + ret = do_perform_cow_write(bs, m->alloc_offset, end->offset,
> + end_buffer, end->nb_bytes);
At any rate, other than the potential of a pessimization due to poor
alignments, your split looks sane, and it makes it more obvious that if
we set up the write iov, a later patch could then call a single
do_perform_cow_write using pwritev() over both chunks in one syscall.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2017-06-09 14:53 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-07 14:08 [Qemu-devel] [PATCH v2 0/7] qcow2: Reduce the number of I/O ops when doing COW Alberto Garcia
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 1/7] qcow2: Remove unused Error variable in do_perform_cow() Alberto Garcia
2017-06-07 15:44 ` Eric Blake
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 2/7] qcow2: Use unsigned int for both members of Qcow2COWRegion Alberto Garcia
2017-06-07 16:02 ` Eric Blake
2017-06-08 13:06 ` Alberto Garcia
2017-06-08 13:38 ` Eric Blake
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 3/7] qcow2: Make perform_cow() call do_perform_cow() twice Alberto Garcia
2017-06-07 21:43 ` Eric Blake
2017-06-08 7:09 ` Alberto Garcia
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 4/7] qcow2: Split do_perform_cow() into _read(), _encrypt() and _write() Alberto Garcia
2017-06-09 14:53 ` Eric Blake [this message]
2017-06-12 13:00 ` Alberto Garcia
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 5/7] qcow2: Allow reading both COW regions with only one request Alberto Garcia
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 6/7] qcow2: Pass a QEMUIOVector to do_perform_cow_{read, write}() Alberto Garcia
2017-06-07 16:20 ` Manos Pitsidianakis
2017-06-16 15:31 ` Kevin Wolf
2017-06-07 14:08 ` [Qemu-devel] [PATCH v2 7/7] qcow2: Merge the writing of the COW regions with the guest data Alberto Garcia
2017-06-16 15:31 ` Kevin Wolf
2017-06-19 11:50 ` Alberto Garcia
2017-06-16 15:31 ` [Qemu-devel] [PATCH v2 0/7] qcow2: Reduce the number of I/O ops when doing COW Kevin Wolf
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=36215351-07f7-43ab-bad5-96ed1f6ecd61@redhat.com \
--to=eblake@redhat.com \
--cc=berto@igalia.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).