All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Anton Nefedov <anton.nefedov@virtuozzo.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	"kwolf@redhat.com" <kwolf@redhat.com>,
	"mreitz@redhat.com" <mreitz@redhat.com>,
	"eblake@redhat.com" <eblake@redhat.com>,
	Denis Lunev <den@virtuozzo.com>,
	"berto@igalia.com" <berto@igalia.com>
Subject: Re: [Qemu-devel] [PATCH v10 8/9] qcow2: skip writing zero buffers to empty COW areas
Date: Thu, 13 Dec 2018 12:02:35 +0000	[thread overview]
Message-ID: <1133b70c-6b8f-1622-18a8-188a4b9fe142@virtuozzo.com> (raw)
In-Reply-To: <20181203101429.88735-9-anton.nefedov@virtuozzo.com>

03.12.2018 13:14, Anton Nefedov wrote:
> If COW areas of the newly allocated clusters are zeroes on the backing image,
> efficient bdrv_write_zeroes(flags=BDRV_REQ_ALLOCATE) can be used on the whole
> cluster instead of writing explicit zero buffers later in perform_cow().
> 

[...]

> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2015,6 +2015,11 @@ static bool merge_cow(uint64_t offset, unsigned bytes,
>               continue;
>           }
>   
> +        /* If COW regions are handled already, skip this too */
> +        if (m->skip_cow) {
> +            continue;
> +        }
> +
>           /* The data (middle) region must be immediately after the
>            * start region */
>           if (l2meta_cow_start(m) + m->cow_start.nb_bytes != offset) {
> @@ -2040,6 +2045,68 @@ static bool merge_cow(uint64_t offset, unsigned bytes,
>       return false;
>   }
>   
> +static bool is_unallocated(BlockDriverState *bs, int64_t offset, int64_t bytes)
> +{
> +    int64_t nr;
> +    return !bytes ||
> +        (!bdrv_is_allocated_above(bs, NULL, offset, bytes, &nr) && nr == bytes);

hm, nr may be < bytes if it is up to file length. And we lose this case, when, it
may be considered as unallocated too.

Doesn't harm, however.

> +}
> +
> +static bool is_zero_cow(BlockDriverState *bs, QCowL2Meta *m)
> +{
> +    /* This check is designed for optimization shortcut so it must be
> +     * efficient.
> +     * Instead of is_zero(), use is_unallocated() as it is faster (but not
> +     * as accurate and can result in false negatives). */

But, in case of allocated zeros, we'll read them anyway (as part of COW process),
so, it may be handled in the same way too. May be not here, but after read we can
check for zeroes, and again effectively write zeros to the whole cluster.

Again it may be done separately, I don't sure it worth doing.

> +    return is_unallocated(bs, m->offset + m->cow_start.offset,
> +                          m->cow_start.nb_bytes) &&
> +           is_unallocated(bs, m->offset + m->cow_end.offset,
> +                          m->cow_end.nb_bytes);
> +}
> +
> +static int handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta)
> +{
> +    BDRVQcow2State *s = bs->opaque;
> +    QCowL2Meta *m;
> +
> +    if (!(bs->file->bs->supported_zero_flags & BDRV_REQ_ALLOCATE)) {
> +        return 0;
> +    }
> +
> +    if (bs->encrypted) {
> +        return 0;
> +    }
> +
> +    for (m = l2meta; m != NULL; m = m->next) {
> +        int ret;
> +
> +        if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) {
> +            continue;
> +        }
> +
> +        if (!is_zero_cow(bs, m)) {
> +            continue;
> +        }

pre_write_overlap_check should be here

> +
> +        BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE);
> +        /* instead of writing zero COW buffers,
> +           efficiently zero out the whole clusters */
> +        ret = bdrv_co_pwrite_zeroes(bs->file, m->alloc_offset,
> +                                    m->nb_clusters * s->cluster_size,
> +                                    BDRV_REQ_ALLOCATE);
> +        if (ret < 0) {
> +            if (ret != -ENOTSUP && ret != -EAGAIN) {
> +                return ret;
> +            }
> +            continue;
> +        }
> +
> +        trace_qcow2_skip_cow(qemu_coroutine_self(), m->offset, m->nb_clusters);
> +        m->skip_cow = true;
> +    }
> +    return 0;
> +}
> +


-- 
Best regards,
Vladimir

  parent reply	other threads:[~2018-12-13 12:03 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03 10:14 [Qemu-devel] [PATCH v10 0/9] qcow2: cluster space preallocation Anton Nefedov
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 1/9] mirror: inherit supported write/zero flags Anton Nefedov
2018-12-05 12:43   ` Vladimir Sementsov-Ogievskiy
2018-12-05 13:27     ` Anton Nefedov
2018-12-07 14:31   ` Alberto Garcia
2018-12-12 12:15   ` Vladimir Sementsov-Ogievskiy
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 2/9] blkverify: set " Anton Nefedov
2018-12-07 14:32   ` Alberto Garcia
2018-12-12 12:26   ` Vladimir Sementsov-Ogievskiy
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 3/9] quorum: set supported write flags Anton Nefedov
2018-12-07 14:33   ` Alberto Garcia
2018-12-07 14:46     ` Anton Nefedov
2018-12-07 14:54       ` Alberto Garcia
2018-12-12 12:33   ` Vladimir Sementsov-Ogievskiy
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 4/9] block: introduce BDRV_REQ_ALLOCATE flag Anton Nefedov
2018-12-05 12:59   ` Vladimir Sementsov-Ogievskiy
2018-12-05 13:38     ` Anton Nefedov
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 5/9] block: treat BDRV_REQ_ALLOCATE as serialising Anton Nefedov
2018-12-05 13:14   ` Vladimir Sementsov-Ogievskiy
2018-12-05 14:01     ` Anton Nefedov
2018-12-12 12:48       ` Vladimir Sementsov-Ogievskiy
2018-12-13 11:57         ` Anton Nefedov
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 6/9] file-posix: support BDRV_REQ_ALLOCATE Anton Nefedov
2018-12-05 13:25   ` Vladimir Sementsov-Ogievskiy
2018-12-05 14:11     ` Anton Nefedov
2018-12-12 17:19       ` Vladimir Sementsov-Ogievskiy
2018-12-13 12:01         ` Anton Nefedov
2018-12-07 15:09   ` Alberto Garcia
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 7/9] block: support BDRV_REQ_ALLOCATE in passthrough drivers Anton Nefedov
2018-12-05 13:28   ` Vladimir Sementsov-Ogievskiy
2018-12-07 15:00   ` Alberto Garcia
2018-12-03 10:14 ` [Qemu-devel] [PATCH v10 8/9] qcow2: skip writing zero buffers to empty COW areas Anton Nefedov
2018-12-03 13:59   ` Alberto Garcia
2018-12-03 14:04     ` Anton Nefedov
2018-12-05 14:01   ` Vladimir Sementsov-Ogievskiy
2018-12-05 16:59     ` Anton Nefedov
2018-12-05 17:42       ` Vladimir Sementsov-Ogievskiy
2018-12-13 12:02   ` Vladimir Sementsov-Ogievskiy [this message]
2018-12-13 13:57     ` Anton Nefedov
2018-12-14 16:20   ` Vladimir Sementsov-Ogievskiy
2018-12-17 10:17     ` Anton Nefedov
2018-12-03 10:15 ` [Qemu-devel] [PATCH v10 9/9] iotest 134: test cluster-misaligned encrypted write Anton Nefedov

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=1133b70c-6b8f-1622-18a8-188a4b9fe142@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=anton.nefedov@virtuozzo.com \
    --cc=berto@igalia.com \
    --cc=den@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.