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=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 5FDF0C282DD for ; Fri, 10 Jan 2020 17:49:41 +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 2D19E20678 for ; Fri, 10 Jan 2020 17:49:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bIgqLB3/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D19E20678 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]:50018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipyPj-00009Y-RL for qemu-devel@archiver.kernel.org; Fri, 10 Jan 2020 12:49:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51785) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipyCB-00070i-Lg for qemu-devel@nongnu.org; Fri, 10 Jan 2020 12:35:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipyCA-00076H-4N for qemu-devel@nongnu.org; Fri, 10 Jan 2020 12:35:39 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:58722 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipyC9-00074o-UG for qemu-devel@nongnu.org; Fri, 10 Jan 2020 12:35:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578677737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SSqpK7OYRTRdYmsOlX0kj3gAK31HzZmc08e82895ib0=; b=bIgqLB3/2s6DnlggCUPPPTAjIwAcTUGRGeZ3ARvSCO0x1MZJuTeQaNgpk3BcmyEt2S1eAb I4lNSqFnSJt4IPQO5uclc2OEI/n31zLGCIopyUDetTNtxQtDJ+BlmBSi3RF+zxHIrVJsb1 1RH5O28aCyhZvNmzkeyCQXorB2N8G2k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-125-wTIjINQJPFeIejiK3BSxzA-1; Fri, 10 Jan 2020 12:35:36 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D70E107ACC5; Fri, 10 Jan 2020 17:35:31 +0000 (UTC) Received: from secure.mitica (ovpn-116-240.ams2.redhat.com [10.36.116.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E12419C4F; Fri, 10 Jan 2020 17:35:24 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PULL 20/28] migration/postcopy: enable compress during postcopy Date: Fri, 10 Jan 2020 18:32:07 +0100 Message-Id: <20200110173215.3865-21-quintela@redhat.com> In-Reply-To: <20200110173215.3865-1-quintela@redhat.com> References: <20200110173215.3865-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: wTIjINQJPFeIejiK3BSxzA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Laurent Vivier , Corey Minyard , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Peter Maydell , Stefan Weil , Jason Wang , "Michael S. Tsirkin" , "Dr. David Alan Gilbert" , Wei Yang , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, David Gibson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Stefan Berger , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Wei Yang postcopy requires to place a whole host page, while migration thread migrate memory in target page size. This makes postcopy need to collect all target pages in one host page before placing via userfaultfd. To enable compress during postcopy, there are two problems to solve: 1. Random order for target page arrival 2. Target pages in one host page arrives without interrupt by target page from other host page The first one is handled by previous cleanup patch. This patch handles the second one by: 1. Flush compress thread for each host page 2. Wait for decompress thread for before placing host page Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 11 ----------- migration/ram.c | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e55edee606..990bff00c0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1005,17 +1005,6 @@ static bool migrate_caps_check(bool *cap_list, #endif =20 if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { - if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { - /* The decompression threads asynchronously write into RAM - * rather than use the atomic copies needed to avoid - * userfaulting. It should be possible to fix the decompressi= on - * threads for compatibility in future. - */ - error_setg(errp, "Postcopy is not currently compatible " - "with compression"); - return false; - } - /* This check is reasonably expensive, so only when it's being * set the first time, also it's only the destination that needs * special support. diff --git a/migration/ram.c b/migration/ram.c index b5546940f9..b9eb08f549 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3469,6 +3469,14 @@ static int ram_save_iterate(QEMUFile *f, void *opaqu= e) =20 rs->target_page_count +=3D pages; =20 + /* + * During postcopy, it is necessary to make sure one whole hos= t + * page is sent in one chunk. + */ + if (migrate_postcopy_ram()) { + flush_compressed_data(rs); + } + /* * we want to check in the 1st loop, just in case it was the 1= st * time and we had to sync the dirty bitmap. @@ -4061,6 +4069,7 @@ static int ram_load_postcopy(QEMUFile *f) void *place_source =3D NULL; RAMBlock *block =3D NULL; uint8_t ch; + int len; =20 addr =3D qemu_get_be64(f); =20 @@ -4078,7 +4087,8 @@ static int ram_load_postcopy(QEMUFile *f) =20 trace_ram_load_postcopy_loop((uint64_t)addr, flags); place_needed =3D false; - if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE)) { + if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | + RAM_SAVE_FLAG_COMPRESS_PAGE)) { block =3D ram_block_from_stream(f, flags); =20 host =3D host_from_ram_block_offset(block, addr); @@ -4161,6 +4171,17 @@ static int ram_load_postcopy(QEMUFile *f) TARGET_PAGE_SIZE); } break; + case RAM_SAVE_FLAG_COMPRESS_PAGE: + all_zero =3D false; + len =3D qemu_get_be32(f); + if (len < 0 || len > compressBound(TARGET_PAGE_SIZE)) { + error_report("Invalid compressed data length: %d", len); + ret =3D -EINVAL; + break; + } + decompress_data_with_multi_threads(f, page_buffer, len); + break; + case RAM_SAVE_FLAG_EOS: /* normal exit */ multifd_recv_sync_main(); @@ -4172,6 +4193,11 @@ static int ram_load_postcopy(QEMUFile *f) break; } =20 + /* Got the whole host page, wait for decompress before placing. */ + if (place_needed) { + ret |=3D wait_for_decompress_done(); + } + /* Detect for any possible file errors */ if (!ret && qemu_file_get_error(f)) { ret =3D qemu_file_get_error(f); --=20 2.24.1