From: Peter Lieven <pl@kamp.de>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 06/20] block: make bdrv_co_do_write_zeroes stricter in producing aligned requests
Date: Thu, 21 Nov 2013 12:30:54 +0100 [thread overview]
Message-ID: <528DEEEE.8050105@kamp.de> (raw)
In-Reply-To: <1384880863-10434-7-git-send-email-pbonzini@redhat.com>
On 19.11.2013 18:07, Paolo Bonzini wrote:
> Right now, bdrv_co_do_write_zeroes will only try to align the
> beginning of the request. However, it is simpler for many
> formats to expect the block layer to separate both the head *and*
> the tail. This makes sure that the format's bdrv_co_write_zeroes
> function will be called with aligned sector_num and nb_sectors for
> the bulk of the request.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block.c | 30 +++++++++++++++---------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/block.c b/block.c
> index 4897649..567d669 100644
> --- a/block.c
> +++ b/block.c
> @@ -2761,14 +2761,19 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
> while (nb_sectors > 0 && !ret) {
> int num = nb_sectors;
>
> - /* align request */
> - if (bs->bl.write_zeroes_alignment &&
> - num >= bs->bl.write_zeroes_alignment &&
> - sector_num % bs->bl.write_zeroes_alignment) {
> - if (num > bs->bl.write_zeroes_alignment) {
> + /* Align request. Block drivers can expect the "bulk" of the request
> + * to be aligned.
> + */
> + if (bs->bl.write_zeroes_alignment
> + && num > bs->bl.write_zeroes_alignment) {
> + if (sector_num % bs->bl.write_zeroes_alignment != 0) {
> + /* Make a small request up to the first aligned sector. */
> num = bs->bl.write_zeroes_alignment;
> + num -= sector_num % bs->bl.write_zeroes_alignment;
> + } else if (num >= bs->bl.write_zeroes_alignment) {
> + /* Shorten the request to the last aligned sector. */
> + num -= (sector_num + num) % bs->bl.write_zeroes_alignment;
> }
> - num -= sector_num % bs->bl.write_zeroes_alignment;
> }
>
> /* limit request size */
> @@ -2785,24 +2790,27 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
> if (ret == -ENOTSUP) {
> /* Fall back to bounce buffer if write zeroes is unsupported */
> iov.iov_len = num * BDRV_SECTOR_SIZE;
> if (iov.iov_base == NULL) {
> - /* allocate bounce buffer only once and ensure that it
> - * is big enough for this and all future requests.
> - */
> - size_t bufsize = num <= nb_sectors ? num : max_write_zeroes;
> - iov.iov_base = qemu_blockalign(bs, bufsize * BDRV_SECTOR_SIZE);
> - memset(iov.iov_base, 0, bufsize * BDRV_SECTOR_SIZE);
> + iov.iov_base = qemu_blockalign(bs, num * BDRV_SECTOR_SIZE);
> + memset(iov.iov_base, 0, num * BDRV_SECTOR_SIZE);
> }
> qemu_iovec_init_external(&qiov, &iov, 1);
>
> ret = drv->bdrv_co_writev(bs, sector_num, num, &qiov);
> + if (num <= max_write_zeroes) {
This frees the bounce buffer ever and ever. num can never be greater than
max_write_zeroes. So you need a num < max_write_zeroes here.
Peter
> + /* Allocate bounce buffer only once if it is
> + * big enough for this and all future requests.
> + */
> + qemu_vfree(iov.iov_base);
> + iov.iov_base = NULL;
> + }
> }
>
> sector_num += num;
> nb_sectors -= num;
> }
>
> qemu_vfree(iov.iov_base);
> return ret;
> }
>
--
Mit freundlichen Grüßen
Peter Lieven
...........................................................
KAMP Netzwerkdienste GmbH
Vestische Str. 89-91 | 46117 Oberhausen
Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
pl@kamp.de | http://www.kamp.de
Geschäftsführer: Heiner Lante | Michael Lante
Amtsgericht Duisburg | HRB Nr. 12154
USt-Id-Nr.: DE 120607556
...........................................................
next prev parent reply other threads:[~2013-11-21 11:30 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-19 17:07 [Qemu-devel] [PATCH v2 00/20] block & scsi: write_zeroes support through the whole stack Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 01/20] block: generalize BlockLimits handling to cover bdrv_aio_discard too Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 02/20] block: add flags to BlockRequest Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 03/20] block: add flags argument to bdrv_co_write_zeroes tracepoint Paolo Bonzini
2013-11-20 9:59 ` Stefan Hajnoczi
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 04/20] block: add bdrv_aio_write_zeroes Paolo Bonzini
2013-11-20 10:02 ` Stefan Hajnoczi
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 05/20] block: handle ENOTSUP from discard in generic code Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 06/20] block: make bdrv_co_do_write_zeroes stricter in producing aligned requests Paolo Bonzini
2013-11-20 10:22 ` Stefan Hajnoczi
2013-11-20 11:01 ` Paolo Bonzini
2013-11-20 14:29 ` Stefan Hajnoczi
2013-11-21 11:30 ` Peter Lieven [this message]
2013-11-21 11:37 ` Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 07/20] vpc, vhdx: add get_info Paolo Bonzini
2013-11-20 12:39 ` Stefan Hajnoczi
2013-11-20 12:50 ` Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 08/20] block drivers: add discard/write_zeroes properties to bdrv_get_info implementation Paolo Bonzini
2013-11-21 11:33 ` Peter Lieven
2013-11-21 11:39 ` Paolo Bonzini
2013-11-21 11:48 ` Peter Lieven
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 09/20] block drivers: expose requirement for write same alignment from formats Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 10/20] block/iscsi: remove .bdrv_has_zero_init Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 11/20] block/iscsi: updated copyright Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 12/20] block/iscsi: check WRITE SAME support differently depending on MAY_UNMAP Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 13/20] block/iscsi: use UNMAP to write zeroes if LBPRZ=1 Paolo Bonzini
2013-11-21 11:43 ` Peter Lieven
2013-11-21 11:49 ` Paolo Bonzini
2013-11-21 11:54 ` Peter Lieven
2013-11-21 12:05 ` Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 14/20] raw-posix: implement write_zeroes with MAY_UNMAP for files Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 15/20] raw-posix: implement write_zeroes with MAY_UNMAP for block devices Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 16/20] raw-posix: add support for write_zeroes on XFS and " Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 17/20] qemu-iotests: 033 is fast Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 18/20] scsi-disk: catch write protection errors in UNMAP Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 19/20] scsi-disk: reject ANCHOR=1 for UNMAP and WRITE SAME commands Paolo Bonzini
2013-11-19 17:07 ` [Qemu-devel] [PATCH v2 20/20] scsi-disk: correctly implement WRITE SAME Paolo Bonzini
2013-11-19 17:23 ` ronnie sahlberg
2013-11-19 17:27 ` ronnie sahlberg
2013-11-19 17:31 ` Paolo Bonzini
2013-11-20 14:18 ` Stefan Hajnoczi
2013-11-20 14:19 ` Paolo Bonzini
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=528DEEEE.8050105@kamp.de \
--to=pl@kamp.de \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--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).