From nobody Fri Nov 1 03:33:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1653994753; cv=none; d=zohomail.com; s=zohoarc; b=BX0DZNRkNDbeKT9vC2U/TrluRO2zWDYiX1m88chDNujLg6Hwr5s5hqpiFkVBVtztXhPOVsJf9zPslvlNEpIDss7CFKrJPeHXb0OjkAKWKZGjlISDtnwrZoDoq37IZu53zdmrUKXVSNS7+Y/C+AZZP+5ov/fK1afXeXoEHifWg0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653994753; 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=CyG/QV+4nMiaGsMNPoSSCmF//51XCpJ1FC4gsqGv66A=; b=f/dqTW20djHL34AJVzPaHu4OcJ/JOPHj5x9uY4nA/8jGX4gxsZ/JFe9IBBQJWSim7/7RnOjn4oM3OYXSlX8hlGLsxqWOGDivUduD0DrixlDaUCuJMccMHmLvBQXu5CwSfOxoOiBMPdx3DheDHLrBrxAZjnaPjQpuEAwfUXLg1Tg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653994753590953.6580066280899; Tue, 31 May 2022 03:59:13 -0700 (PDT) Received: from localhost ([::1]:40694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvzai-0007Qb-Cx for importer@patchew.org; Tue, 31 May 2022 06:59:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvzLu-0003l0-BN for qemu-devel@nongnu.org; Tue, 31 May 2022 06:43:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvzLs-0004gw-KH for qemu-devel@nongnu.org; Tue, 31 May 2022 06:43:54 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-XeKT1NbFP76_VZ-XRyxzQQ-1; Tue, 31 May 2022 06:43:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DDB93C11733; Tue, 31 May 2022 10:43:48 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8DCB1131A; Tue, 31 May 2022 10:43:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653993832; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CyG/QV+4nMiaGsMNPoSSCmF//51XCpJ1FC4gsqGv66A=; b=D62OiC1Jau//leNEEB1XX5Tl4ruLsyaF4ZplL3/qMPz5tkuC1q2JykhebwNyH/NhyQcmU7 Wy5OGpdWXefLZmcpjTN51j0zqOzTh+1TP91XER4AsBvhDhUyqHxXYfrbElzzQ25AfISNum Ylo2r1DHWoVERloPA5eE6dGOyoQM0oE= X-MC-Unique: XeKT1NbFP76_VZ-XRyxzQQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Dr. David Alan Gilbert" , Juan Quintela , Eduardo Habkost , Peter Xu , Leonardo Bras Subject: [PATCH v7 12/13] multifd: Zero pages transmission Date: Tue, 31 May 2022 12:43:17 +0200 Message-Id: <20220531104318.7494-13-quintela@redhat.com> In-Reply-To: <20220531104318.7494-1-quintela@redhat.com> References: <20220531104318.7494-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1653994755886100002 Content-Type: text/plain; charset="utf-8" This implements the zero page dection and handling. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- Add comment for offset (dave) Use local variables for offset/block to have shorter lines --- migration/multifd.h | 5 +++++ migration/multifd.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index c36d7ff876..209e3a9756 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -52,6 +52,11 @@ typedef struct { uint32_t unused32[1]; /* Reserved for future use */ uint64_t unused64[3]; /* Reserved for future use */ char ramblock[256]; + /* + * This array contains the pointers to: + * - normal pages (initial normal_pages entries) + * - zero pages (following zero_pages entries) + */ uint64_t offset[]; } __attribute__((packed)) MultiFDPacket_t; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 0f7c27c08e..fcdd241c5c 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/rcu.h" #include "exec/target_page.h" #include "sysemu/sysemu.h" @@ -275,6 +276,12 @@ static void multifd_send_fill_packet(MultiFDSendParams= *p) =20 packet->offset[i] =3D cpu_to_be64(temp); } + for (i =3D 0; i < p->zero_num; i++) { + /* there are architectures where ram_addr_t is 32 bit */ + uint64_t temp =3D p->zero[i]; + + packet->offset[p->normal_num + i] =3D cpu_to_be64(temp); + } } =20 static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -358,6 +365,18 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) p->normal[i] =3D offset; } =20 + for (i =3D 0; i < p->zero_num; i++) { + uint64_t offset =3D be64_to_cpu(packet->offset[p->normal_num + i]); + + if (offset > (block->used_length - p->page_size)) { + error_setg(errp, "multifd: offset too long %" PRIu64 + " (max " RAM_ADDR_FMT ")", + offset, block->used_length); + return -1; + } + p->zero[i] =3D offset; + } + return 0; } =20 @@ -646,6 +665,8 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; + /* qemu older than 7.0 don't understand zero page on multifd channel */ + bool use_zero_page =3D migrate_use_multifd_zero_page(); int ret =3D 0; bool use_zero_copy_send =3D migrate_use_zero_copy_send(); =20 @@ -668,6 +689,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); =20 if (p->pending_job) { + RAMBlock *rb =3D p->pages->block; uint64_t packet_num =3D p->packet_num; p->flags =3D 0; if (p->sync_needed) { @@ -686,8 +708,16 @@ static void *multifd_send_thread(void *opaque) } =20 for (int i =3D 0; i < p->pages->num; i++) { - p->normal[p->normal_num] =3D p->pages->offset[i]; - p->normal_num++; + uint64_t offset =3D p->pages->offset[i]; + if (use_zero_page && + buffer_is_zero(rb->host + offset, p->page_size)) { + p->zero[p->zero_num] =3D offset; + p->zero_num++; + ram_release_page(rb->idstr, offset); + } else { + p->normal[p->normal_num] =3D offset; + p->normal_num++; + } } =20 if (p->normal_num) { @@ -1152,6 +1182,13 @@ static void *multifd_recv_thread(void *opaque) } } =20 + for (int i =3D 0; i < p->zero_num; i++) { + void *page =3D p->host + p->zero[i]; + if (!buffer_is_zero(page, p->page_size)) { + memset(page, 0, p->page_size); + } + } + if (sync_needed) { qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); --=20 2.35.3