From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86C06C32750 for ; Tue, 13 Aug 2019 14:24:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4F81420679 for ; Tue, 13 Aug 2019 14:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F81420679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hxXiX-0005QB-Gr for qemu-devel@archiver.kernel.org; Tue, 13 Aug 2019 10:24:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38428) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hxXi6-0004sh-Ft for qemu-devel@nongnu.org; Tue, 13 Aug 2019 10:23:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxXi4-0003Js-SX for qemu-devel@nongnu.org; Tue, 13 Aug 2019 10:23:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50002) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxXi1-0003IP-Db; Tue, 13 Aug 2019 10:23:33 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B742C8535C; Tue, 13 Aug 2019 14:23:32 +0000 (UTC) Received: from dresden.str.redhat.com (unknown [10.40.205.136]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3DF7F26FDB; Tue, 13 Aug 2019 14:23:24 +0000 (UTC) To: Vladimir Sementsov-Ogievskiy , "qemu-block@nongnu.org" References: <20190810193155.58637-1-vsementsov@virtuozzo.com> <20190810193155.58637-7-vsementsov@virtuozzo.com> <5102eac9-125b-0719-910f-4adb240732f1@redhat.com> <89c87c83-276a-7663-a239-57dbd9f91a30@virtuozzo.com> <4093762b-a1bc-d6b1-8358-4f9d1ab52557@virtuozzo.com> From: Max Reitz Openpgp: preference=signencrypt Autocrypt: addr=mreitz@redhat.com; prefer-encrypt=mutual; keydata= mQENBFXOJlcBCADEyyhOTsoa/2ujoTRAJj4MKA21dkxxELVj3cuILpLTmtachWj7QW+TVG8U /PsMCFbpwsQR7oEy8eHHZwuGQsNpEtNC2G/L8Yka0BIBzv7dEgrPzIu+W3anZXQW4702+uES U29G8TP/NGfXRRHGlbBIH9KNUnOSUD2vRtpOLXkWsV5CN6vQFYgQfFvmp5ZpPeUe6xNplu8V mcTw8OSEDW/ZnxJc8TekCKZSpdzYoxfzjm7xGmZqB18VFwgJZlIibt1HE0EB4w5GsD7x5ekh awIe3RwoZgZDLQMdOitJ1tUc8aqaxvgA4tz6J6st8D8pS//m1gAoYJWGwwIVj1DjTYLtABEB AAG0HU1heCBSZWl0eiA8bXJlaXR6QHJlZGhhdC5jb20+iQFTBBMBCAA9AhsDBQkSzAMABQsJ CA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+1fwZu+7Io5+B bkhSVPb/QdOVTpnz7zWNyNw+OONo1aBUKkhq2UIByYXgORPFnbfMY7QWHcjpBVw9MgC4tGeF R4bv+1nAMMxKmb5VvQCExr0eFhJUAHAhVg== Message-ID: Date: Tue, 13 Aug 2019 16:23:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <4093762b-a1bc-d6b1-8358-4f9d1ab52557@virtuozzo.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KGibZFBdNKZvrzAWTKzoUlblCFAOBp8oz" X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 13 Aug 2019 14:23:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] [PATCH v3 6/7] block/backup: teach backup_cow_with_bounce_buffer to copy more at once 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: "fam@euphon.net" , "kwolf@redhat.com" , Denis Lunev , "qemu-devel@nongnu.org" , "armbru@redhat.com" , "stefanha@redhat.com" , "jsnow@redhat.com" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --KGibZFBdNKZvrzAWTKzoUlblCFAOBp8oz Content-Type: multipart/mixed; boundary="s7ioJMMUvepzcbnMIPoKJkZhSYUBpVGmC"; protected-headers="v1" From: Max Reitz To: Vladimir Sementsov-Ogievskiy , "qemu-block@nongnu.org" Cc: "qemu-devel@nongnu.org" , "armbru@redhat.com" , "fam@euphon.net" , "stefanha@redhat.com" , "kwolf@redhat.com" , "jsnow@redhat.com" , Denis Lunev Message-ID: Subject: Re: [PATCH v3 6/7] block/backup: teach backup_cow_with_bounce_buffer to copy more at once References: <20190810193155.58637-1-vsementsov@virtuozzo.com> <20190810193155.58637-7-vsementsov@virtuozzo.com> <5102eac9-125b-0719-910f-4adb240732f1@redhat.com> <89c87c83-276a-7663-a239-57dbd9f91a30@virtuozzo.com> <4093762b-a1bc-d6b1-8358-4f9d1ab52557@virtuozzo.com> In-Reply-To: <4093762b-a1bc-d6b1-8358-4f9d1ab52557@virtuozzo.com> --s7ioJMMUvepzcbnMIPoKJkZhSYUBpVGmC Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 13.08.19 16:14, Vladimir Sementsov-Ogievskiy wrote: > 12.08.2019 19:37, Vladimir Sementsov-Ogievskiy wrote: >> 12.08.2019 19:11, Max Reitz wrote: >>> On 12.08.19 17:47, Vladimir Sementsov-Ogievskiy wrote: >>>> 12.08.2019 18:10, Max Reitz wrote: >>>>> On 10.08.19 21:31, Vladimir Sementsov-Ogievskiy wrote: >>>>>> backup_cow_with_offload can transfer more than one cluster. Let >>>>>> backup_cow_with_bounce_buffer behave similarly. It reduces the num= ber >>>>>> of IO requests, since there is no need to copy cluster by cluster.= >>>>>> >>>>>> Logic around bounce_buffer allocation changed: we can't just alloc= ate >>>>>> one-cluster-sized buffer to share for all iterations. We can't als= o >>>>>> allocate buffer of full-request length it may be too large, so >>>>>> BACKUP_MAX_BOUNCE_BUFFER is introduced. And finally, allocation lo= gic >>>>>> is to allocate a buffer sufficient to handle all remaining iterati= ons >>>>>> at the point where we need the buffer for the first time. >>>>>> >>>>>> Bonus: get rid of pointer-to-pointer. >>>>>> >>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy >>>>>> --- >>>>>> =C2=A0=C2=A0 block/backup.c | 65 +++++++++++++++++++++++++++++++--= ----------------- >>>>>> =C2=A0=C2=A0 1 file changed, 41 insertions(+), 24 deletions(-) >>>>>> >>>>>> diff --git a/block/backup.c b/block/backup.c >>>>>> index d482d93458..65f7212c85 100644 >>>>>> --- a/block/backup.c >>>>>> +++ b/block/backup.c >>>>>> @@ -27,6 +27,7 @@ >>>>>> =C2=A0=C2=A0 #include "qemu/error-report.h" >>>>>> =C2=A0=C2=A0 #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) >>>>>> +#define BACKUP_MAX_BOUNCE_BUFFER (64 * 1024 * 1024) >>>>>> =C2=A0=C2=A0 typedef struct CowRequest { >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int64_t start_byte; >>>>>> @@ -98,44 +99,55 @@ static void cow_request_end(CowRequest *req) >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 qemu_co_queue_restart_all(&re= q->wait_queue); >>>>>> =C2=A0=C2=A0 } >>>>>> -/* Copy range to target with a bounce buffer and return the bytes= copied. If >>>>>> - * error occurred, return a negative error number */ >>>>>> +/* >>>>>> + * Copy range to target with a bounce buffer and return the bytes= copied. If >>>>>> + * error occurred, return a negative error number >>>>>> + * >>>>>> + * @bounce_buffer is assumed to enough to store >>>>> >>>>> s/to/to be/ >>>>> >>>>>> + * MIN(BACKUP_MAX_BOUNCE_BUFFER, @end - @start) bytes >>>>>> + */ >>>>>> =C2=A0=C2=A0 static int coroutine_fn backup_cow_with_bounce_buffer= (BackupBlockJob *job, >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A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=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool *error_is_read, >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 void **bounce_buffer) >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 void *bounce_buffer) >>>>>> =C2=A0=C2=A0 { >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int ret; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BlockBackend *blk =3D job->co= mmon.blk; >>>>>> -=C2=A0=C2=A0=C2=A0 int nbytes; >>>>>> +=C2=A0=C2=A0=C2=A0 int nbytes, remaining_bytes; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int read_flags =3D is_write_n= otifier ? BDRV_REQ_NO_SERIALISING : 0; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assert(QEMU_IS_ALIGNED(start,= job->cluster_size)); >>>>>> -=C2=A0=C2=A0=C2=A0 bdrv_reset_dirty_bitmap(job->copy_bitmap, star= t, job->cluster_size); >>>>>> -=C2=A0=C2=A0=C2=A0 nbytes =3D MIN(job->cluster_size, job->len - s= tart); >>>>>> -=C2=A0=C2=A0=C2=A0 if (!*bounce_buffer) { >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *bounce_buffer =3D blk= _blockalign(blk, job->cluster_size); >>>>>> -=C2=A0=C2=A0=C2=A0 } >>>>>> +=C2=A0=C2=A0=C2=A0 bdrv_reset_dirty_bitmap(job->copy_bitmap, star= t, end - start); >>>>>> +=C2=A0=C2=A0=C2=A0 nbytes =3D MIN(end - start, job->len - start);= >>>>>> -=C2=A0=C2=A0=C2=A0 ret =3D blk_co_pread(blk, start, nbytes, *boun= ce_buffer, read_flags); >>>>>> -=C2=A0=C2=A0=C2=A0 if (ret < 0) { >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 trace_backup_do_cow_re= ad_fail(job, start, ret); >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (error_is_read) { >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= *error_is_read =3D true; >>>>>> + >>>>>> +=C2=A0=C2=A0=C2=A0 remaining_bytes =3D nbytes; >>>>>> +=C2=A0=C2=A0=C2=A0 while (remaining_bytes) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int chunk =3D MIN(BACK= UP_MAX_BOUNCE_BUFFER, remaining_bytes); >>>>>> + >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D blk_co_pread(b= lk, start, chunk, bounce_buffer, read_flags); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret < 0) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= trace_backup_do_cow_read_fail(job, start, ret); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if (error_is_read) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 *error_is_read =3D true; >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= } >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= goto fail; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto fail; >>>>>> -=C2=A0=C2=A0=C2=A0 } >>>>>> -=C2=A0=C2=A0=C2=A0 ret =3D blk_co_pwrite(job->target, start, nbyt= es, *bounce_buffer, >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = job->write_flags); >>>>>> -=C2=A0=C2=A0=C2=A0 if (ret < 0) { >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 trace_backup_do_cow_wr= ite_fail(job, start, ret); >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (error_is_read) { >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= *error_is_read =3D false; >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D blk_co_pwrite(= job->target, start, chunk, bounce_buffer, >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 job->write_flags); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret < 0) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= trace_backup_do_cow_write_fail(job, start, ret); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if (error_is_read) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 *error_is_read =3D false; >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= } >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= goto fail; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto fail; >>>>>> + >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 start +=3D chunk; >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 remaining_bytes -=3D c= hunk; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return nbytes; >>>>>> @@ -301,9 +313,14 @@ static int coroutine_fn backup_do_cow(BackupB= lockJob *job, >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 } >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!= job->use_copy_range) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if (!bounce_buffer) { >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 size_t len =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 MAX(dirty_end - start= , end - dirty_end)); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 bounce_buffer =3D blk_try_blockalign(job->common= =2Eblk, len); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= } >>>>> >>>>> If you use _try_, you should probably also check whether it succeed= ed. >>>> >>>> Oops, you are right, of course. >>>> >>>>> >>>>> Anyway, I wonder whether it=E2=80=99d be better to just allocate th= is buffer >>>>> once per job (the first time we get here, probably) to be of size >>>>> BACKUP_MAX_BOUNCE_BUFFER and put it into BackupBlockJob.=C2=A0 (And= maybe add >>>>> a buf-size parameter similar to what the mirror jobs have.) >>>>> >>>> >>>> Once per job will not work, as we may have several guest writes in p= arallel and therefore >>>> several parallel copy-before-write operations. >>> >>> Hm.=C2=A0 I=E2=80=99m not quite happy with that because if the guest = just issues many >>> large discards in parallel, this means that qemu will allocate a larg= e >>> amount of memory. >>> >>> It would be nice if there was a simple way to keep track of the total= >>> memory usage and let requests yield if they would exceed it. >> >> Agree, it should be fixed anyway. >> >=20 >=20 > But still.. >=20 > Synchronous mirror allocates full-request buffers on guest write. Is it= correct? >=20 > If we assume that it is correct to double memory usage of guest operati= ons, than for backup > the problem is only in write_zero and discard where guest-assumed memor= y usage should be zero. Well, but that is the problem. I didn=E2=80=99t say anything in v2, beca= use I only thought of normal writes and I found it fine to double the memory usage there (a guest won=E2=80=99t issue huge write requests in parallel)= =2E But discard/write-zeroes are a different matter. > And if we should distinguish writes from write_zeroes and discard, it's= better to postpone this > improvement to be after backup-top filter merged. But do you need to distinguish it? Why not just keep track of memory usage and put the current I/O coroutine to sleep in a CoQueue or something, and wake that up at the end of backup_do_cow()? Max --s7ioJMMUvepzcbnMIPoKJkZhSYUBpVGmC-- --KGibZFBdNKZvrzAWTKzoUlblCFAOBp8oz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEkb62CjDbPohX0Rgp9AfbAGHVz0AFAl1Sx9oACgkQ9AfbAGHV z0B+PQf/eF3R6p0ymuBviKisk1+iJtKHV44uQsd5J7vBugOMVfLpK+c9uMl82m1T 1ZekmVEdTZRqaOBTxzJoo5IcXIk0Ki4RapKva101Op0zMRGCTq09AQeYfeiKo4xP 6N5sIUASKVcAJSn6hDsHO0qTUOUScvzW/Zunz5VKCw9fQxu2lwifydNQqc5w1wFd 5bNkPHa7ZhoD9Ml1KrEZFC0FrD89CWdFXsmNVds70wLb7i8jjVfH6+KF+HqgMGmF 6SwotbtE2aGdex9ycfDrnLNTfej3zZb5c+ojtjfVStQr7J8kRa7rusN9hN0zej/w jTuvbeRLdGM1Ms5KL+lc3GwV04urNw== =hRIC -----END PGP SIGNATURE----- --KGibZFBdNKZvrzAWTKzoUlblCFAOBp8oz--