From nobody Sun Feb 8 17:21:09 2026 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=1571246354; cv=none; d=zoho.com; s=zohoarc; b=naLISUUnIucVZ2KrgZJZr33cZ6UiL4TT0ZCTQINqzMRtUA5kRPFoOFUKS0ioe1jd7f69IG9tbXE30jPu3PHdEvlI29kmIPIuixun4KrqbAyDEkJqchMY3rT+z5/EqwLksuxPuKrMnbX0mgI7f6x93WYIa2hy/vMzFdAVZUePnAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571246354; 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; bh=D7dTWJHn28G60Gv1ztRnxziPA8sYMseCtfjtpWUTZsQ=; b=Qu8zjis1ZZS7fFyF9hQy8MNK3mZqK+/+N8JHaJQnGl93G/TA5e4WHYU/8lhM0tbSxkhq2pM1HYh0/pBGtb1mWQBzlqfVAm3FguOrJiBCtKB/0n60azu1dLgf4sL+Jrtbrpq7K5NgUpvtNI2R2ozv343WwmYOM2MupzTyn0kSJu0= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571246354568173.46956889169223; Wed, 16 Oct 2019 10:19:14 -0700 (PDT) Received: from localhost ([::1]:46122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKmx1-0005lf-FY for importer@patchew.org; Wed, 16 Oct 2019 13:19:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42178) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKmnb-0005xz-V4 for qemu-devel@nongnu.org; Wed, 16 Oct 2019 13:09:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKmna-0003UG-1m for qemu-devel@nongnu.org; Wed, 16 Oct 2019 13:09:23 -0400 Received: from relay.sw.ru ([185.231.240.75]:52736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKmnS-0003QL-AI; Wed, 16 Oct 2019 13:09:14 -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 1iKmnN-0002PI-5C; Wed, 16 Oct 2019 20:09:09 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 6/6] block/block-copy: increase buffered copy request Date: Wed, 16 Oct 2019 20:09:05 +0300 Message-Id: <20191016170905.8325-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191016170905.8325-1-vsementsov@virtuozzo.com> References: <20191016170905.8325-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 | 48 +++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index edcdf0072d..0a161724d7 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 d5042e46fd..74eb235972 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, @@ -75,10 +76,8 @@ 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(MAX(cluster_size, BLOCK_COPY_MAX_COPY_RANGE), + MIN_NON_ZERO(INT_MAX, MIN_NON_ZERO(source->bs->bl.max_transfer, target->bs->bl.max_transfer)); =20 @@ -100,17 +99,28 @@ BlockCopyState *block_copy_state_new(BdrvChild *source= , BdrvChild *target, .mem =3D shres_create(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,12 +166,19 @@ 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); /* Fallback to read+write with allocated buffer */ } else { goto out; } } =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); @@ -290,8 +307,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