From nobody Tue Nov 11 03:20:46 2025 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=1560875099; cv=none; d=zoho.com; s=zohoarc; b=DddYpF2sydoIdymUjXFe2ZXSqB2w40yyATJbtfLjTSopFlaizwSQcBlX1id5ljfSSP8HA2yIO2AsFPDUOKRvnqrs++SnWHXDfRRxGmgFV1teiSQl/cYipPSdglfusbc0CmdQQaPOjtdhlpOpBt9ogPrwGixPw4PagGcQ52ifO4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560875099; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=eEnh/7YypT5sIm7e6f+MfbzStchEyhQQai+JX11gR/o=; b=gm58L+KqFYhd5TlxUq/RBIgj9IzpOXL3IuuHg1FPaF3styKuamr+8Htvk/7E4aZvprUyo4L3bXVLjIYMYSfOqgHZFcqSdlG8k+Rzgl+pNX8XS6Nsuyv7stvwVifiwnszXxcc1D23mhRly5af82aoWEtTXcANWiDJoRZeH0J5K8k= 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 1560875099914177.14715275450874; Tue, 18 Jun 2019 09:24:59 -0700 (PDT) Received: from localhost ([::1]:59542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdGui-0003gi-VQ for importer@patchew.org; Tue, 18 Jun 2019 12:24:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34215) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdGFf-0007QI-M5 for qemu-devel@nongnu.org; Tue, 18 Jun 2019 11:42:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdGFY-0005vE-Ti for qemu-devel@nongnu.org; Tue, 18 Jun 2019 11:42:24 -0400 Received: from relay.sw.ru ([185.231.240.75]:38517) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdGFT-0005Vb-Bx; Tue, 18 Jun 2019 11:42:17 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hdGFH-0002Sc-OG; Tue, 18 Jun 2019 18:42:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 18 Jun 2019 18:42:01 +0300 Message-Id: <20190618154202.89107-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190618154202.89107-1-vsementsov@virtuozzo.com> References: <20190618154202.89107-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 2/3] block/stream: use BDRV_REQ_PREFETCH 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, fam@euphon.net, vsementsov@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This helps to avoid extra io, allocations and memory copying. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/stream.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/block/stream.c b/block/stream.c index 1a906fd860..b316bfb290 100644 --- a/block/stream.c +++ b/block/stream.c @@ -22,11 +22,11 @@ =20 enum { /* - * Size of data buffer for populating the image file. This should be = large + * Maximum chunk size to feed it to copy-on-read. This should be large * enough to process multiple clusters in a single call, so that popul= ating * contiguous regions of the image is efficient. */ - STREAM_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ + STREAM_CHUNK =3D 512 * 1024, /* in bytes */ }; =20 typedef struct StreamBlockJob { @@ -39,13 +39,12 @@ typedef struct StreamBlockJob { } StreamBlockJob; =20 static int coroutine_fn stream_populate(BlockBackend *blk, - int64_t offset, uint64_t bytes, - void *buf) + int64_t offset, uint64_t bytes) { assert(bytes < SIZE_MAX); =20 - /* Copy-on-read the unallocated clusters */ - return blk_co_pread(blk, offset, bytes, buf, BDRV_REQ_COPY_ON_READ); + return blk_co_preadv(blk, offset, bytes, NULL, + BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); } =20 static void stream_abort(Job *job) @@ -117,7 +116,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) int error =3D 0; int ret =3D 0; int64_t n =3D 0; /* bytes */ - void *buf; =20 if (!bs->backing) { goto out; @@ -130,8 +128,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } job_progress_set_remaining(&s->common.job, len); =20 - buf =3D qemu_blockalign(bs, STREAM_BUFFER_SIZE); - /* Turn on copy-on-read for the whole block device so that guest read * requests help us make progress. Only do this when copying the enti= re * backing chain since the copy-on-read operation does not take base i= nto @@ -154,7 +150,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n); + ret =3D bdrv_is_allocated(bs, offset, STREAM_CHUNK, &n); if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { @@ -172,7 +168,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } trace_stream_one_iteration(s, offset, n, ret); if (copy) { - ret =3D stream_populate(blk, offset, n, buf); + ret =3D stream_populate(blk, offset, n); } if (ret < 0) { BlockErrorAction action =3D @@ -206,8 +202,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) /* Do not remove the backing file if an error was there but ignored. = */ ret =3D error; =20 - qemu_vfree(buf); - out: /* Modify backing chain and close BDSes in main loop */ return ret; --=20 2.18.0