Received: by 2002:a0c:cd0f:0:0:0:0:0 with SMTP id b15csp2733411qvm; Mon, 20 Jan 2020 02:45:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwJTmk3gZdhCJn+7cNxHzQBS1Ctl2YxayAt+gT8RDB7Sw4XC0eLEftlg40QAQrXGVaGilks X-Received: by 2002:a37:6294:: with SMTP id w142mr45724821qkb.284.1579517110655; Mon, 20 Jan 2020 02:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579517110; cv=none; d=google.com; s=arc-20160816; b=ZVie87uHuKVHwA1RJKm1a7+zUHC6q5nxLNs2zYlQANM/GdNg6lOhVUpxrZtZgt2CLq vdxBqBQ2/x1IdDyRTafPKyvVehUEHMdkilVIogEDA3zNxKRR5oEMQRaGBUYAqKGnV5v7 kYUe5uPQ7WdD5iEJ2NU5ytcGZt4Pj3OBcUdqptYs0t3KYy5m0WAQiS7Wxrhts5cJMJvR Az3VEyukkG4zBxXVhdvsHu4yrLM+BiH+3f+HAuREplQzch0apcoObjymFiZs/b+Qwz2n P55rDJmb1jUlRulZNS64rkAbyxEbGwbtjm/lJDYmR1FzWjmN+F+qv4hBtItuJDy/j07p Ka+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Yr1WVaAouDj40R39IdfVYwIhtLx/Le0jqD+NYulh5As=; b=XVd23CFb0zLMVrr2xpLIuuP9Q248pay/QzG8u/6dFTEy2VhTX0dv1mLKHzfGU8PJzk MRAvFL/q/Vw0ay7zWOVaVh6xKZAXh0eKytyB07dHs+7slXfXV7SvikWskRJ1xGbkVCwZ yL6LBAaQ5hmzC3Z1c6C76ebv3OrR+FnEEfl5hBhIIqbL2IdB4ye1R1kGd4n0gUD7igp6 4+MJwy58uU/Y7qzx1bnBvx/njw/qQjKr6mgySFjf9WtoGR27UiDF6yGkChlopmRyA0jt OheK1hCrm6hrAwepUFqY/Ev3HWfn5AVrjHc2LyYF8TGygAgPXY9aTUqdBnIAnTV3Sbbn 3PlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=S6dA80JP; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bx14si20359250qvb.176.2020.01.20.02.45.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Jan 2020 02:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=S6dA80JP; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:33814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itUYP-0001bn-Ef for alex.bennee@linaro.org; Mon, 20 Jan 2020 05:45:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38004) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itUQI-0006uu-2M for qemu-arm@nongnu.org; Mon, 20 Jan 2020 05:36:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itUQD-0002t3-Vx for qemu-arm@nongnu.org; Mon, 20 Jan 2020 05:36:45 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40084 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itUQD-0002sh-Sc for qemu-arm@nongnu.org; Mon, 20 Jan 2020 05:36:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579516601; 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=Yr1WVaAouDj40R39IdfVYwIhtLx/Le0jqD+NYulh5As=; b=S6dA80JPHaRmIUWKt+z20laCQNKwLbP8MVHDLFnQPxBBxZl/EqLqumU4qHGPzRFto1PTjc hhtc09kHP12XWv7aO+QysjFMVLszupGMEpyFlQgele79iKBAbA/b02TfB2PuZC/VsHpn+y Uunu8zKr0hNE8DuXQV9aFsj90fCBTvA= 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-226-yL0risH0Mqivszhl5q07qw-1; Mon, 20 Jan 2020 05:36:38 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A2F9190D37F; Mon, 20 Jan 2020 10:36:36 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id C81711BC6D; Mon, 20 Jan 2020 10:36:31 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PULL 19/29] migration/postcopy: enable compress during postcopy Date: Mon, 20 Jan 2020 11:33:30 +0100 Message-Id: <20200120103340.25118-20-quintela@redhat.com> In-Reply-To: <20200120103340.25118-1-quintela@redhat.com> References: <20200120103340.25118-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: yL0risH0Mqivszhl5q07qw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: 205.139.110.120 X-BeenThere: qemu-arm@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 , "Michael S. Tsirkin" , Peter Maydell , Stefan Weil , Jason Wang , Juan Quintela , "Dr. David Alan Gilbert" , Marcel Apfelbaum , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Wei Yang , David Gibson , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Andrzej Zaborowski , Stefan Berger Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: 2zp3NZh+9vle 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 a7414170e5..5f20c3d15d 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