From nobody Mon Feb 9 00:19:31 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=1565465687; cv=none; d=zoho.com; s=zohoarc; b=C9Qdl73PfSOoCJpS/fpHGGHvCCvfQRdRIvdmEBqJIl9zFvTvxEXAq0Z12p7/bN0/siXBpcWuGZlWjKg4WsU/8c2CLynleEfmpSGTeY+nIugT/YVmULtQF7Mmv1ZNlL/oGxjJNr6P0Cctax3O37iqVOzpFy5Tm5S/hkuy0TswFk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465687; 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=sVP2tI1e6f7dZaMiHs1iq7kO1Ba8bSKvu5BAguB9d/w=; b=GrdAoZxGHQ2kNXhqY4VzOmzFLStEa4BOWJ1BtRYs7pbGrvH9E4F2KnvDp6qrVOX/vpla1WGMwe8X1koFsshzz5FVLeFUwqbpbQKbJ7CfrIIalJ5Ce55CdyAT8NB5b7bXzSsvGVMDHStlHWM0hXKzkI+bzDtwoQAOQvFTtPi1ly0= 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 1565465687879205.4063213745012; Sat, 10 Aug 2019 12:34:47 -0700 (PDT) Received: from localhost ([::1]:37882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX8Y-0005Ua-Rm for importer@patchew.org; Sat, 10 Aug 2019 15:34:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44035) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5z-0000Jn-9p for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007CC-RV for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:48776) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-00076z-FR; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5p-0000nK-Ho; Sat, 10 Aug 2019 22:31:57 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:54 +0300 Message-Id: <20190810193155.58637-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 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, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, 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" backup_cow_with_offload can transfer more than one cluster. Let backup_cow_with_bounce_buffer behave similarly. It reduces the number of IO requests, since there is no need to copy cluster by cluster. Logic around bounce_buffer allocation changed: we can't just allocate one-cluster-sized buffer to share for all iterations. We can't also allocate buffer of full-request length it may be too large, so BACKUP_MAX_BOUNCE_BUFFER is introduced. And finally, allocation logic is to allocate a buffer sufficient to handle all remaining iterations 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 --- block/backup.c | 65 +++++++++++++++++++++++++++++++------------------- 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 @@ #include "qemu/error-report.h" =20 #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) +#define BACKUP_MAX_BOUNCE_BUFFER (64 * 1024 * 1024) =20 typedef struct CowRequest { int64_t start_byte; @@ -98,44 +99,55 @@ static void cow_request_end(CowRequest *req) qemu_co_queue_restart_all(&req->wait_queue); } =20 -/* 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 + * MIN(BACKUP_MAX_BOUNCE_BUFFER, @end - @start) bytes + */ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job, int64_t start, int64_t end, bool is_write_notifi= er, bool *error_is_read, - void **bounce_buffer) + void *bounce_buffer) { int ret; BlockBackend *blk =3D job->common.blk; - int nbytes; + int nbytes, remaining_bytes; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; =20 assert(QEMU_IS_ALIGNED(start, job->cluster_size)); - bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); - nbytes =3D MIN(job->cluster_size, job->len - start); - if (!*bounce_buffer) { - *bounce_buffer =3D blk_blockalign(blk, job->cluster_size); - } + bdrv_reset_dirty_bitmap(job->copy_bitmap, start, end - start); + nbytes =3D MIN(end - start, job->len - start); =20 - ret =3D blk_co_pread(blk, start, nbytes, *bounce_buffer, read_flags); - if (ret < 0) { - trace_backup_do_cow_read_fail(job, start, ret); - if (error_is_read) { - *error_is_read =3D true; + + remaining_bytes =3D nbytes; + while (remaining_bytes) { + int chunk =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, remaining_bytes); + + ret =3D blk_co_pread(blk, start, chunk, bounce_buffer, read_flags); + if (ret < 0) { + trace_backup_do_cow_read_fail(job, start, ret); + if (error_is_read) { + *error_is_read =3D true; + } + goto fail; } - goto fail; - } =20 - ret =3D blk_co_pwrite(job->target, start, nbytes, *bounce_buffer, - job->write_flags); - if (ret < 0) { - trace_backup_do_cow_write_fail(job, start, ret); - if (error_is_read) { - *error_is_read =3D false; + ret =3D blk_co_pwrite(job->target, start, chunk, bounce_buffer, + job->write_flags); + if (ret < 0) { + trace_backup_do_cow_write_fail(job, start, ret); + if (error_is_read) { + *error_is_read =3D false; + } + goto fail; } - goto fail; + + start +=3D chunk; + remaining_bytes -=3D chunk; } =20 return nbytes; @@ -301,9 +313,14 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, } } if (!job->use_copy_range) { + if (!bounce_buffer) { + size_t len =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, + MAX(dirty_end - start, end - dirty_end)); + bounce_buffer =3D blk_try_blockalign(job->common.blk, len); + } ret =3D backup_cow_with_bounce_buffer(job, start, dirty_end, is_write_notifier, - error_is_read, &bounce_buf= fer); + error_is_read, bounce_buff= er); } if (ret < 0) { break; --=20 2.18.0