From nobody Fri May 3 10:26:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570123549; cv=none; d=zoho.com; s=zohoarc; b=aE8MeGolq5FpE2FHYrAmRQDw158c3yXp7+PmpMePj0MSTk1kBpyY8bN1B0nDsaxAIPJEOaLe86rm0S+elEJhK3P+4G0y+oKMqEgFpd7LbSH1bPAS8i+8IN/ay8+iHhaI9/GqbjDF5kevvE+8b4zBOntJ11gZCM6irGm7AqfwBgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570123549; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=a87sjfsIC0ElSBEk5BabldNCdCmCGufHQNj/E+W6Mgw=; b=NTZjuFP6XON/ob9Gmniya7rVH1NssC52yKa0TfCDGjcA9m6Bwb5t5ozHGztjQ+lqGSXWXktVKGk19VUGwQiCSPJHZbSuOOEcxv/cFeO0Va+dTW0tbiL5xstkHnDGq5oO7Y91knWEKBH0jzN9bL56W5aVPrP+rF21H92aAAhv7VU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570123549400405.20769653385764; Thu, 3 Oct 2019 10:25:49 -0700 (PDT) Received: from localhost ([::1]:38842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4rM-0007AG-2J for importer@patchew.org; Thu, 03 Oct 2019 13:25:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60971) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4hk-00074g-VU for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG4hj-00006C-IS for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:50278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG4hb-0008Ts-Ua; Thu, 03 Oct 2019 13:15:45 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iG4hY-0002ks-5m; Thu, 03 Oct 2019 20:15:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 1/6] block/block-copy: allocate buffer in block_copy_with_bounce_buffer Date: Thu, 3 Oct 2019 20:15:34 +0300 Message-Id: <20191003171539.12327-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191003171539.12327-1-vsementsov@virtuozzo.com> References: <20191003171539.12327-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Move bounce_buffer allocation block_copy_with_bounce_buffer. This commit simplifies further work on implementing copying by larger chunks (of different size) and further asynchronous handling of block_copy iterations (with help of block/aio_task API). Allocation works fast, a lot faster than disk io, so it's not a problem that we now allocate/free bounce_buffer more times. And we anyway will have to allocate several bounce_buffers for parallel execution of loop iterations in future. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 5404bc921d..aca0f893d7 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -126,20 +126,17 @@ void block_copy_set_callbacks( static int coroutine_fn block_copy_with_bounce_buffer(BlockCopyState *s, int64_t start, int64_t end, - bool *error_is_read, - void **bounce_buffer) + bool *error_is_read) { int ret; int nbytes; + void *bounce_buffer =3D qemu_blockalign(s->source->bs, s->cluster_size= ); =20 assert(QEMU_IS_ALIGNED(start, s->cluster_size)); bdrv_reset_dirty_bitmap(s->copy_bitmap, start, s->cluster_size); nbytes =3D MIN(s->cluster_size, s->len - start); - if (!*bounce_buffer) { - *bounce_buffer =3D qemu_blockalign(s->source->bs, s->cluster_size); - } =20 - ret =3D bdrv_co_pread(s->source, start, nbytes, *bounce_buffer, 0); + ret =3D bdrv_co_pread(s->source, start, nbytes, bounce_buffer, 0); if (ret < 0) { trace_block_copy_with_bounce_buffer_read_fail(s, start, ret); if (error_is_read) { @@ -148,7 +145,7 @@ static int coroutine_fn block_copy_with_bounce_buffer(B= lockCopyState *s, goto fail; } =20 - ret =3D bdrv_co_pwrite(s->target, start, nbytes, *bounce_buffer, + ret =3D bdrv_co_pwrite(s->target, start, nbytes, bounce_buffer, s->write_flags); if (ret < 0) { trace_block_copy_with_bounce_buffer_write_fail(s, start, ret); @@ -158,8 +155,11 @@ static int coroutine_fn block_copy_with_bounce_buffer(= BlockCopyState *s, goto fail; } =20 + qemu_vfree(bounce_buffer); + return nbytes; fail: + qemu_vfree(bounce_buffer); bdrv_set_dirty_bitmap(s->copy_bitmap, start, s->cluster_size); return ret; =20 @@ -271,7 +271,6 @@ int coroutine_fn block_copy(BlockCopyState *s, { int ret =3D 0; int64_t end =3D bytes + start; /* bytes */ - void *bounce_buffer =3D NULL; int64_t status_bytes; BlockCopyInFlightReq req; =20 @@ -324,7 +323,7 @@ int coroutine_fn block_copy(BlockCopyState *s, } if (!s->use_copy_range) { ret =3D block_copy_with_bounce_buffer(s, start, dirty_end, - error_is_read, &bounce_buf= fer); + error_is_read); } if (ret < 0) { break; @@ -335,10 +334,6 @@ int coroutine_fn block_copy(BlockCopyState *s, ret =3D 0; } =20 - if (bounce_buffer) { - qemu_vfree(bounce_buffer); - } - block_copy_inflight_req_end(&req); =20 return ret; --=20 2.21.0 From nobody Fri May 3 10:26:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570123327; cv=none; d=zoho.com; s=zohoarc; b=J9xoF2PBMvAvwwThOKi/rAbXuhVxtkUpROEbQXRQzwNWIohdzOctySKXHJ7udfNtf/S34ln9LNxcKfwKlRrXT/sCKZJMfuYEYjpzxxDr6dnBUVOF31Nax+9Upasbbbq9nxfWvL8jhjtu5olAmu1eeKzbmktSH8535nckB1440pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570123327; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=oNI3v3X4u23gc0dDfnl4SDAQkKLaXz8VtDqWguW/y7I=; b=RGW2bW40wymBojmHzq7aQxGZW+zkv1BjPVKv8QSElHY45V9tlKpDJJIHLULaiRN5mj72+LsrURYBNnP+JKzUqf+ubZ+biJ8jcUlctU/EaW5PqEFidPbOTIKtvbP5lgKyqyuRcmOvsEkaUy3U8IVQmyLQEYQuZu0P63QPXjNPDm4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570123327492607.4419007032359; Thu, 3 Oct 2019 10:22:07 -0700 (PDT) Received: from localhost ([::1]:38802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4ng-0003K7-5v for importer@patchew.org; Thu, 03 Oct 2019 13:22:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60966) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4hk-00074e-Qd for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG4hj-00006T-LQ for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:50260) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG4hd-0008To-Pg; Thu, 03 Oct 2019 13:15:45 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iG4hY-0002ks-9X; Thu, 03 Oct 2019 20:15:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 2/6] block/block-copy: limit copy_range_size to 16 MiB Date: Thu, 3 Oct 2019 20:15:35 +0300 Message-Id: <20191003171539.12327-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191003171539.12327-1-vsementsov@virtuozzo.com> References: <20191003171539.12327-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Large copy range may imply memory allocation and large io effort, so using 2G copy range request may be bad idea. Let's limit it to 16 MiB. It also helps the following patch to refactor copy-with-offload fallback to copy-with-bounce-buffer. Note, that total memory usage of backup is still not limited, it will be fixed in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index aca0f893d7..75287ce24d 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -18,6 +18,9 @@ #include "qapi/error.h" #include "block/block-copy.h" #include "sysemu/block-backend.h" +#include "qemu/units.h" + +#define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB) =20 static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, int64_t start, @@ -70,9 +73,12 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, = BdrvChild *target, { BlockCopyState *s; BdrvDirtyBitmap *copy_bitmap; + + /* Ignore BLOCK_COPY_MAX_COPY_RANGE if requested cluster_size is large= r */ uint32_t max_transfer =3D - MIN_NON_ZERO(INT_MAX, MIN_NON_ZERO(source->bs->bl.max_transfer, - target->bs->bl.max_transfer= )); + MIN_NON_ZERO(MAX(cluster_size, BLOCK_COPY_MAX_COPY_RANGE), + MIN_NON_ZERO(source->bs->bl.max_transfer, + target->bs->bl.max_transfer)); =20 copy_bitmap =3D bdrv_create_dirty_bitmap(source->bs, cluster_size, NUL= L, errp); --=20 2.21.0 From nobody Fri May 3 10:26:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570123531; cv=none; d=zoho.com; s=zohoarc; b=VqsrOL2pmZX1sVVz6fl+MeR5zHYjzct3arpan/lpXNmj3C1JFBjjPIgsht0cItR44uRnj0+yXQpAzMM2djcGiRkwR/bI+sakkT9+kk9kC2MjnIF4d6uPDkazzpU6R8u8NEHMMiLK9CxAYcesUJeB2zz/uCg6QMN7t6zqUc6G4Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570123531; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QSG04pbkEb5siB0aKIyMFEfkdhCD02ZCxwM+hZE3fCs=; b=K2exObMWA6WoBnni2RudlRaU40qc9oGKzRmcwH9LKaTnWI3lAPK+9YTxI0L/oFtv8j64k3aZalGOMbpaiCGv3mDDiI5SdC/9lay6pIO4f3b+OPxMl40ucGvMZ5Mm8FUauXhSC2qHZnUAqOZSj6xl0SC7e/XtZfMdsTrFf8Nc2+M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570123531250548.8723036223618; Thu, 3 Oct 2019 10:25:31 -0700 (PDT) Received: from localhost ([::1]:38836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4r3-0006gK-EC for importer@patchew.org; Thu, 03 Oct 2019 13:25:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60993) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4hl-00075d-KW for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG4hj-00006c-Mh for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:53 -0400 Received: from relay.sw.ru ([185.231.240.75]:50262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG4hd-0008Tq-R9; Thu, 03 Oct 2019 13:15:46 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iG4hY-0002ks-CI; Thu, 03 Oct 2019 20:15:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 3/6] block/block-copy: refactor copying Date: Thu, 3 Oct 2019 20:15:36 +0300 Message-Id: <20191003171539.12327-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191003171539.12327-1-vsementsov@virtuozzo.com> References: <20191003171539.12327-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Merge copying code into one function block_copy_do_copy, which only calls bdrv_ io functions and don't do any synchronization (like dirty bitmap set/reset). Refactor block_copy() function so that it takes full decision about size of chunk to be copied and does all the synchronization (checking intersecting requests, set/reset dirty bitmaps). It will help: - introduce parallel processing of block_copy iterations: we need to calculate chunk size, start async chunk copying and go to the next iteration - simplify synchronization improvement (like memory limiting in further commit and reducing critical section (now we lock the whole requested range, when actually we need to lock only dirty region which we handle at the moment)) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/block-copy.c | 113 ++++++++++++++++++++------------------------- block/trace-events | 6 +-- 2 files changed, 53 insertions(+), 66 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 75287ce24d..cc49d2345d 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -126,25 +126,43 @@ void block_copy_set_callbacks( } =20 /* - * Copy range to target with a bounce buffer and return the bytes copied. = If - * error occurred, return a negative error number + * block_copy_do_copy + * + * Do copy of cluser-aligned chunk. @end is allowed to exceed s->len only = to + * cover last cluster when s->len is not aligned to clusters. + * + * No sync here: nor bitmap neighter intersecting requests handling, only = copy. + * + * Returns 0 on success. */ -static int coroutine_fn block_copy_with_bounce_buffer(BlockCopyState *s, - int64_t start, - int64_t end, - bool *error_is_read) +static int coroutine_fn block_copy_do_copy(BlockCopyState *s, + int64_t start, int64_t end, + bool *error_is_read) { int ret; - int nbytes; - void *bounce_buffer =3D qemu_blockalign(s->source->bs, s->cluster_size= ); + int nbytes =3D MIN(end, s->len) - start; + void *bounce_buffer =3D NULL; =20 assert(QEMU_IS_ALIGNED(start, s->cluster_size)); - bdrv_reset_dirty_bitmap(s->copy_bitmap, start, s->cluster_size); - nbytes =3D MIN(s->cluster_size, s->len - start); + assert(QEMU_IS_ALIGNED(end, s->cluster_size)); + assert(end < s->len || end =3D=3D QEMU_ALIGN_UP(s->len, s->cluster_siz= e)); + + if (s->use_copy_range) { + ret =3D bdrv_co_copy_range(s->source, start, s->target, start, nby= tes, + 0, s->write_flags); + if (ret < 0) { + trace_block_copy_copy_range_fail(s, start, ret); + s->use_copy_range =3D false; + } else { + return ret; + } + } + + bounce_buffer =3D qemu_blockalign(s->source->bs, nbytes); =20 ret =3D bdrv_co_pread(s->source, start, nbytes, bounce_buffer, 0); if (ret < 0) { - trace_block_copy_with_bounce_buffer_read_fail(s, start, ret); + trace_block_copy_read_fail(s, start, ret); if (error_is_read) { *error_is_read =3D true; } @@ -154,7 +172,7 @@ static int coroutine_fn block_copy_with_bounce_buffer(B= lockCopyState *s, ret =3D bdrv_co_pwrite(s->target, start, nbytes, bounce_buffer, s->write_flags); if (ret < 0) { - trace_block_copy_with_bounce_buffer_write_fail(s, start, ret); + trace_block_copy_write_fail(s, start, ret); if (error_is_read) { *error_is_read =3D false; } @@ -163,42 +181,12 @@ static int coroutine_fn block_copy_with_bounce_buffer= (BlockCopyState *s, =20 qemu_vfree(bounce_buffer); =20 - return nbytes; + return 0; + fail: qemu_vfree(bounce_buffer); - bdrv_set_dirty_bitmap(s->copy_bitmap, start, s->cluster_size); - return ret; - -} - -/* - * Copy range to target and return the bytes copied. If error occurred, re= turn a - * negative error number. - */ -static int coroutine_fn block_copy_with_offload(BlockCopyState *s, - int64_t start, - int64_t end) -{ - int ret; - int nr_clusters; - int nbytes; =20 - assert(QEMU_IS_ALIGNED(s->copy_range_size, s->cluster_size)); - assert(QEMU_IS_ALIGNED(start, s->cluster_size)); - nbytes =3D MIN(s->copy_range_size, MIN(end, s->len) - start); - nr_clusters =3D DIV_ROUND_UP(nbytes, s->cluster_size); - bdrv_reset_dirty_bitmap(s->copy_bitmap, start, - s->cluster_size * nr_clusters); - ret =3D bdrv_co_copy_range(s->source, start, s->target, start, nbytes, - 0, s->write_flags); - if (ret < 0) { - trace_block_copy_with_offload_fail(s, start, ret); - bdrv_set_dirty_bitmap(s->copy_bitmap, start, - s->cluster_size * nr_clusters); - return ret; - } - - return nbytes; + return ret; } =20 /* @@ -294,7 +282,7 @@ int coroutine_fn block_copy(BlockCopyState *s, block_copy_inflight_req_begin(s, &req, start, end); =20 while (start < end) { - int64_t dirty_end; + int64_t next_zero, chunk_end; =20 if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) { trace_block_copy_skip(s, start); @@ -302,10 +290,15 @@ int coroutine_fn block_copy(BlockCopyState *s, continue; /* already copied */ } =20 - dirty_end =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start, - (end - start)); - if (dirty_end < 0) { - dirty_end =3D end; + chunk_end =3D MIN(end, start + (s->use_copy_range ? + s->copy_range_size : s->cluster_size= )); + + next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start, + chunk_end - start); + if (next_zero >=3D 0) { + assert(next_zero > start); /* start is dirty */ + assert(next_zero < chunk_end); /* no need to do MIN() */ + chunk_end =3D next_zero; } =20 if (s->skip_unallocated) { @@ -316,27 +309,21 @@ int coroutine_fn block_copy(BlockCopyState *s, continue; } /* Clamp to known allocated region */ - dirty_end =3D MIN(dirty_end, start + status_bytes); + chunk_end =3D MIN(chunk_end, start + status_bytes); } =20 trace_block_copy_process(s, start); =20 - if (s->use_copy_range) { - ret =3D block_copy_with_offload(s, start, dirty_end); - if (ret < 0) { - s->use_copy_range =3D false; - } - } - if (!s->use_copy_range) { - ret =3D block_copy_with_bounce_buffer(s, start, dirty_end, - error_is_read); - } + bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start); + + ret =3D block_copy_do_copy(s, start, chunk_end, error_is_read); if (ret < 0) { + bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start= ); break; } =20 - start +=3D ret; - s->progress_bytes_callback(ret, s->progress_opaque); + s->progress_bytes_callback(chunk_end - start, s->progress_opaque); + start =3D chunk_end; ret =3D 0; } =20 diff --git a/block/trace-events b/block/trace-events index b8d70f5242..ccde15a14c 100644 --- a/block/trace-events +++ b/block/trace-events @@ -45,9 +45,9 @@ backup_do_cow_return(void *job, int64_t offset, uint64_t = bytes, int ret) "job %p block_copy_skip(void *bcs, int64_t start) "bcs %p start %"PRId64 block_copy_skip_range(void *bcs, int64_t start, uint64_t bytes) "bcs %p st= art %"PRId64" bytes %"PRId64 block_copy_process(void *bcs, int64_t start) "bcs %p start %"PRId64 -block_copy_with_bounce_buffer_read_fail(void *bcs, int64_t start, int ret)= "bcs %p start %"PRId64" ret %d" -block_copy_with_bounce_buffer_write_fail(void *bcs, int64_t start, int ret= ) "bcs %p start %"PRId64" ret %d" -block_copy_with_offload_fail(void *bcs, int64_t start, int ret) "bcs %p st= art %"PRId64" ret %d" +block_copy_copy_range_fail(void *bcs, int64_t start, int ret) "bcs %p star= t %"PRId64" ret %d" +block_copy_read_fail(void *bcs, int64_t start, int ret) "bcs %p start %"PR= Id64" ret %d" +block_copy_write_fail(void *bcs, int64_t start, int ret) "bcs %p start %"P= RId64" ret %d" =20 # ../blockdev.c qmp_block_job_cancel(void *job) "job %p" --=20 2.21.0 From nobody Fri May 3 10:26:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570123329; cv=none; d=zoho.com; s=zohoarc; b=F0zprhu1QUxNJHUTx8MlGentD+O6HtNe6Y3Q4FyPrSe/Kv45wE+LbVZEOWAVIqvnDtLiFiCUIb8OkS3neWzJW1DPv6ZC9kc5/CHIz+6tHkXZL8Y0h4bFdBLDZ1KvXZcA9xm9LZLv+tusJzTU3NhJfYkIV22jSz1XrAokQgOuV4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570123329; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=bw9p57frAU8iDjf72MkK8o6UgQaeUp3RBVn1Xp20mN8=; b=nooVmsCnTrTeoD9XwrdQnPeMwZDl6wSkqiaIlkXAwxLhq6FQC03pN630K2en9lhnP6kNiAEZOENSCpfmS4lm9/5CVXYV3UK/XswxLRgdrFJbas5QBOVfobruw4ram6yA/NnNGJTeqjrqsASllLqeW3tZOvyjErnpEK6oXCcdN1U= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570123329099749.2809052352832; Thu, 3 Oct 2019 10:22:09 -0700 (PDT) Received: from localhost ([::1]:38804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4ni-0003Kz-EY for importer@patchew.org; Thu, 03 Oct 2019 13:22:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4hl-00074h-Ak for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG4hj-00006X-LY for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:53 -0400 Received: from relay.sw.ru ([185.231.240.75]:50280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG4hc-0008Tr-3i; Thu, 03 Oct 2019 13:15:45 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iG4hY-0002ks-Io; Thu, 03 Oct 2019 20:15:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 4/6] util: introduce co-shared-amount Date: Thu, 3 Oct 2019 20:15:37 +0300 Message-Id: <20191003171539.12327-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191003171539.12327-1-vsementsov@virtuozzo.com> References: <20191003171539.12327-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Introduce an API for some shared splitable resource, like memory. It's going to be used by backup. Backup uses both read/write io and copy_range. copy_range may consume memory implictly, so new API is abstract: it don't allocate any real memory but only handling out tickets. The idea is that we have some total amount of something and callers should wait in coroutine queue if there is not enough of the resource at the moment. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qemu/co-shared-amount.h | 66 ++++++++++++++++++++++++++++ util/qemu-co-shared-amount.c | 77 +++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + 3 files changed, 144 insertions(+) create mode 100644 include/qemu/co-shared-amount.h create mode 100644 util/qemu-co-shared-amount.c diff --git a/include/qemu/co-shared-amount.h b/include/qemu/co-shared-amoun= t.h new file mode 100644 index 0000000000..e2dbc43dfd --- /dev/null +++ b/include/qemu/co-shared-amount.h @@ -0,0 +1,66 @@ +/* + * Generic shared amount for coroutines + * + * Copyright (c) 2019 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef QEMU_CO_SHARED_AMOUNT_H +#define QEMU_CO_SHARED_AMOUNT_H + + +typedef struct QemuCoSharedAmount QemuCoSharedAmount; + +/* + * Create QemuCoSharedAmount structure + * + * @total: total amount to be shared between clients + * + * Note: this API is not thread-safe as it originally designed to be used = in + * backup block-job and called from one aio context. If multiple threads s= upport + * is needed it should be implemented (for ex., protect QemuCoSharedAmount= by + * mutex). + */ +QemuCoSharedAmount *qemu_co_shared_amount_new(uint64_t total); + +/* + * Release QemuCoSharedAmount structure + */ +void qemu_co_shared_amount_free(QemuCoSharedAmount *s); + +/* + * Try to get n peaces. If not enough free peaces returns false, otherwise= true. + */ +bool qemu_co_try_get_amount(QemuCoSharedAmount *s, uint64_t n); + +/* + * Get n peaces. If not enough yields. Return on success. + */ +void coroutine_fn qemu_co_get_amount(QemuCoSharedAmount *s, uint64_t n); + +/* + * Put n peaces. Client must not put more than it gets, still it may put in + * split: for example, get(5) and then put(3), put(2). All peaces must be = put + * back before qemu_co_shared_amount_free call. + */ +void coroutine_fn qemu_co_put_amount(QemuCoSharedAmount *s, uint64_t n); + + +#endif /* QEMU_CO_SHARED_AMOUNT_H */ diff --git a/util/qemu-co-shared-amount.c b/util/qemu-co-shared-amount.c new file mode 100644 index 0000000000..8855ce5705 --- /dev/null +++ b/util/qemu-co-shared-amount.c @@ -0,0 +1,77 @@ +/* + * Generic shared amount for coroutines + * + * Copyright (c) 2019 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/coroutine.h" +#include "qemu/co-shared-amount.h" + +struct QemuCoSharedAmount { + uint64_t total; + uint64_t taken; + + CoQueue queue; +}; + +QemuCoSharedAmount *qemu_co_shared_amount_new(uint64_t total) +{ + QemuCoSharedAmount *s =3D g_new0(QemuCoSharedAmount, 1); + + s->total =3D total; + qemu_co_queue_init(&s->queue); + + return s; +} + +void qemu_co_shared_amount_free(QemuCoSharedAmount *s) +{ + assert(s->taken =3D=3D 0); + g_free(s); +} + +bool qemu_co_try_get_amount(QemuCoSharedAmount *s, uint64_t n) +{ + if (n < s->total && s->total - n >=3D s->taken) { + s->taken +=3D n; + return true; + } + + return false; +} + +void coroutine_fn qemu_co_get_amount(QemuCoSharedAmount *s, uint64_t n) +{ + assert(n < s->total); + while (s->total - n < s->taken) { + qemu_co_queue_wait(&s->queue, NULL); + } + + assert(qemu_co_try_get_amount(s, n)); +} + +void coroutine_fn qemu_co_put_amount(QemuCoSharedAmount *s, uint64_t n) +{ + assert(n <=3D s->taken); + s->taken -=3D n; + qemu_co_queue_restart_all(&s->queue); +} diff --git a/util/Makefile.objs b/util/Makefile.objs index 41bf59d127..65ae18993a 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -37,6 +37,7 @@ util-obj-y +=3D rcu.o util-obj-$(CONFIG_MEMBARRIER) +=3D sys_membarrier.o util-obj-y +=3D qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o util-obj-y +=3D qemu-coroutine-sleep.o +util-obj-y +=3D qemu-co-shared-amount.o util-obj-y +=3D coroutine-$(CONFIG_COROUTINE_BACKEND).o util-obj-y +=3D buffer.o util-obj-y +=3D timed-average.o --=20 2.21.0 From nobody Fri May 3 10:26:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570123100; cv=none; d=zoho.com; s=zohoarc; b=HXuErDI7diigHM3BTvhnbP7rsBQdkkxbZGN1MOl8E0TV1KmYPEGMzpDFj+s+wZF7qRKQqeBHkriqlOi8W39cm15PKTtTx7bUmmAKnWz/Y1BARsjdB3V3BRbMqJjqlhWkJ4c564pfU7KaSdNithda3TJOQv10NYqgRaxdfWFbIhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570123100; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SUvxQBKPijhVos89UnwfTNShJq/JNSnhddTy4X9lcUU=; b=oJV8cdrhhtQHEDnPN1D9Or0iz6lcNFx0lb3xFtJzAm1U6qSV6j43fe+cxHb3ycEmZGCmR8ZGaer3M90+yWT1rwe4/I92T9SkxBoIndp0QAizwA9YsWHjhlSuN1ouwnf7HVMMP2oxmyDYoOP4emTq98YblZyTvZJ5tVSZxr+Thmk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157012310075645.39642853254418; Thu, 3 Oct 2019 10:18:20 -0700 (PDT) Received: from localhost ([::1]:38776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4k4-0000Nh-LL for importer@patchew.org; Thu, 03 Oct 2019 13:18:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60970) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4hk-00074f-UV for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG4hj-00006K-Kr for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:50264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG4hd-0008Tp-Qm; Thu, 03 Oct 2019 13:15:46 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iG4hY-0002ks-RD; Thu, 03 Oct 2019 20:15:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 5/6] block/block-copy: add memory limit Date: Thu, 3 Oct 2019 20:15:38 +0300 Message-Id: <20191003171539.12327-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191003171539.12327-1-vsementsov@virtuozzo.com> References: <20191003171539.12327-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently total allocation for parallel requests to block-copy instance is unlimited. Let's limit it to 128 MiB. For now block-copy is used only in backup, so actually we limit total allocation for backup job. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block-copy.h | 3 +++ block/block-copy.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index e2e135ff1b..bb666e7068 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -16,6 +16,7 @@ #define BLOCK_COPY_H =20 #include "block/block.h" +#include "qemu/co-shared-amount.h" =20 typedef struct BlockCopyInFlightReq { int64_t start_byte; @@ -69,6 +70,8 @@ typedef struct BlockCopyState { */ ProgressResetCallbackFunc progress_reset_callback; void *progress_opaque; + + QemuCoSharedAmount *mem; } BlockCopyState; =20 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, diff --git a/block/block-copy.c b/block/block-copy.c index cc49d2345d..e700c20d0f 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -21,6 +21,7 @@ #include "qemu/units.h" =20 #define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB) +#define BLOCK_COPY_MAX_MEM (128 * MiB) =20 static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, int64_t start, @@ -64,6 +65,7 @@ void block_copy_state_free(BlockCopyState *s) } =20 bdrv_release_dirty_bitmap(s->source->bs, s->copy_bitmap); + qemu_co_shared_amount_free(s->mem); g_free(s); } =20 @@ -95,6 +97,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, B= drvChild *target, .cluster_size =3D cluster_size, .len =3D bdrv_dirty_bitmap_size(copy_bitmap), .write_flags =3D write_flags, + .mem =3D qemu_co_shared_amount_new(BLOCK_COPY_MAX_MEM), }; =20 s->copy_range_size =3D QEMU_ALIGN_DOWN(max_transfer, cluster_size), @@ -316,7 +319,9 @@ int coroutine_fn block_copy(BlockCopyState *s, =20 bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start); =20 + qemu_co_get_amount(s->mem, chunk_end - start); ret =3D block_copy_do_copy(s, start, chunk_end, error_is_read); + qemu_co_put_amount(s->mem, chunk_end - start); if (ret < 0) { bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start= ); break; --=20 2.21.0 From nobody Fri May 3 10:26:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570123354; cv=none; d=zoho.com; s=zohoarc; b=Vj+x4NDQyo3qRjet3ni240KWcoLXfTE3ZyYBY83fB2dHMGIeQnDToSfDYq675vIyf9wdIEPFdvhLPq52A4PfkpjD2I7TiHGNtecjc8QasBLinCqL6n2Wnk0C6RgSaWfkdLkWL+x3f1FC3GE1KeAAtxfTKRqi6b/ox4jYN5at7K0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570123354; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7hqQSgLplNJA6QDvZMcVkUV810BYQY2X8j08R27C+lI=; b=Z3MpVNtM3reFANHmfGmsRUgg1tVGY/pWQEX7zexjQsJVLOHdrxpPFhS75Tv/+JDlVi7UUWxc2to5euJaBrQ7mdeV262GjpjHhnYxUA4AIbektj0GfMjd/c/zCQSv3YsaQa3unrXHCGwiK05KFkrzgWVUYCp8fChY9lHiZx/4AfM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570123354153577.1136625915844; Thu, 3 Oct 2019 10:22:34 -0700 (PDT) Received: from localhost ([::1]:38810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4oD-0003mM-07 for importer@patchew.org; Thu, 03 Oct 2019 13:22:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60959) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG4hk-00074d-Hn for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG4hj-000063-7T for qemu-devel@nongnu.org; Thu, 03 Oct 2019 13:15:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:50282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG4hb-0008Tv-U2; Thu, 03 Oct 2019 13:15:44 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iG4hY-0002ks-Vg; Thu, 03 Oct 2019 20:15:41 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 6/6] block/block-copy: increase buffered copy request Date: Thu, 3 Oct 2019 20:15:39 +0300 Message-Id: <20191003171539.12327-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191003171539.12327-1-vsementsov@virtuozzo.com> References: <20191003171539.12327-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" No reason to limit buffered copy to one cluster. Let's allow up to 1 MiB. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- include/block/block-copy.h | 2 +- block/block-copy.c | 44 +++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index bb666e7068..6a6f5ce73a 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -38,7 +38,7 @@ typedef struct BlockCopyState { BdrvDirtyBitmap *copy_bitmap; int64_t cluster_size; bool use_copy_range; - int64_t copy_range_size; + int64_t copy_size; uint64_t len; QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs; =20 diff --git a/block/block-copy.c b/block/block-copy.c index e700c20d0f..12cb540494 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -21,6 +21,7 @@ #include "qemu/units.h" =20 #define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB) +#define BLOCK_COPY_MAX_BUFFER (1 * MiB) #define BLOCK_COPY_MAX_MEM (128 * MiB) =20 static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s, @@ -100,17 +101,28 @@ BlockCopyState *block_copy_state_new(BdrvChild *sourc= e, BdrvChild *target, .mem =3D qemu_co_shared_amount_new(BLOCK_COPY_MAX_MEM), }; =20 - s->copy_range_size =3D QEMU_ALIGN_DOWN(max_transfer, cluster_size), - /* - * Set use_copy_range, consider the following: - * 1. Compression is not supported for copy_range. - * 2. copy_range does not respect max_transfer (it's a TODO), so we fa= ctor - * that in here. If max_transfer is smaller than the job->cluster_s= ize, - * we do not use copy_range (in that case it's zero after aligning = down - * above). - */ - s->use_copy_range =3D - !(write_flags & BDRV_REQ_WRITE_COMPRESSED) && s->copy_range_size >= 0; + if (max_transfer < cluster_size) { + /* + * copy_range does not respect max_transfer. We don't want to both= er + * with requests smaller than block-copy cluster size, so fallback= to + * buffered copying (read and write respect max_transfer on their + * behalf). + */ + s->use_copy_range =3D false; + s->copy_size =3D cluster_size; + } else if (write_flags & BDRV_REQ_WRITE_COMPRESSED) { + /* Compression is not supported for copy_range */ + s->use_copy_range =3D false; + s->copy_size =3D MAX(cluster_size, BLOCK_COPY_MAX_BUFFER); + } else { + /* + * copy_range does not respect max_transfer (it's a TODO), so we f= actor + * that in here. + */ + s->use_copy_range =3D true; + s->copy_size =3D MIN(MAX(cluster_size, BLOCK_COPY_MAX_COPY_RANGE), + QEMU_ALIGN_DOWN(max_transfer, cluster_size)); + } =20 QLIST_INIT(&s->inflight_reqs); =20 @@ -156,11 +168,18 @@ static int coroutine_fn block_copy_do_copy(BlockCopyS= tate *s, if (ret < 0) { trace_block_copy_copy_range_fail(s, start, ret); s->use_copy_range =3D false; + s->copy_size =3D MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER); } else { return ret; } } =20 + /* + * In case of failed copy_range request above, we may proceed with buf= fered + * request larger than BLOCK_COPY_MAX_BUFFER. Still, further requests = will + * be properly limited, so don't care too much. + */ + bounce_buffer =3D qemu_blockalign(s->source->bs, nbytes); =20 ret =3D bdrv_co_pread(s->source, start, nbytes, bounce_buffer, 0); @@ -293,8 +312,7 @@ int coroutine_fn block_copy(BlockCopyState *s, continue; /* already copied */ } =20 - chunk_end =3D MIN(end, start + (s->use_copy_range ? - s->copy_range_size : s->cluster_size= )); + chunk_end =3D MIN(end, start + s->copy_size); =20 next_zero =3D bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start, chunk_end - start); --=20 2.21.0