From nobody Wed Oct 29 17:29:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524687425846467.10535535629265; Wed, 25 Apr 2018 13:17:05 -0700 (PDT) Received: from localhost ([::1]:38848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBQqV-0005c1-BR for importer@patchew.org; Wed, 25 Apr 2018 16:16:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBQdo-0003f9-11 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 16:03:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBQdk-00034M-Rr for qemu-devel@nongnu.org; Wed, 25 Apr 2018 16:03:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35576 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBQdk-00034E-Le for qemu-devel@nongnu.org; Wed, 25 Apr 2018 16:03:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40095EFDE1; Wed, 25 Apr 2018 20:03:44 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FBDA215CDCE; Wed, 25 Apr 2018 20:03:43 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, peterx@redhat.com, a.perevalov@samsung.com, xiaoguangrong@tencent.com Date: Wed, 25 Apr 2018 21:03:21 +0100 Message-Id: <20180425200326.72337-12-dgilbert@redhat.com> In-Reply-To: <20180425200326.72337-1-dgilbert@redhat.com> References: <20180425200326.72337-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 25 Apr 2018 20:03:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 25 Apr 2018 20:03:44 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dgilbert@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 11/16] migration: introduce control_save_page() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Abstract the common function control_save_page() to cleanup the code, no logic is changed Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong Message-Id: <20180330075128.26919-6-xiaoguangrong@tencent.com> Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 174 +++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 85 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 72cb8dfb66..79c7958993 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -974,6 +974,44 @@ static void ram_release_pages(const char *rbname, uint= 64_t offset, int pages) ram_discard_range(rbname, offset, pages << TARGET_PAGE_BITS); } =20 +/* + * @pages: the number of pages written by the control path, + * < 0 - error + * > 0 - number of pages written + * + * Return true if the pages has been saved, otherwise false is returned. + */ +static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t of= fset, + int *pages) +{ + uint64_t bytes_xmit =3D 0; + int ret; + + *pages =3D -1; + ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAG= E_SIZE, + &bytes_xmit); + if (ret =3D=3D RAM_SAVE_CONTROL_NOT_SUPP) { + return false; + } + + if (bytes_xmit) { + ram_counters.transferred +=3D bytes_xmit; + *pages =3D 1; + } + + if (ret =3D=3D RAM_SAVE_CONTROL_DELAYED) { + return true; + } + + if (bytes_xmit > 0) { + ram_counters.normal++; + } else if (bytes_xmit =3D=3D 0) { + ram_counters.duplicate++; + } + + return true; +} + /** * ram_save_page: send the given page to the stream * @@ -990,56 +1028,36 @@ static void ram_release_pages(const char *rbname, ui= nt64_t offset, int pages) static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_st= age) { int pages =3D -1; - uint64_t bytes_xmit; - ram_addr_t current_addr; uint8_t *p; - int ret; bool send_async =3D true; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; + ram_addr_t current_addr =3D block->offset + offset; =20 p =3D block->host + offset; trace_ram_save_page(block->idstr, (uint64_t)offset, p); =20 - /* In doubt sent page as normal */ - bytes_xmit =3D 0; - ret =3D ram_control_save_page(rs->f, block->offset, - offset, TARGET_PAGE_SIZE, &bytes_xmit); - if (bytes_xmit) { - ram_counters.transferred +=3D bytes_xmit; - pages =3D 1; + if (control_save_page(rs, block, offset, &pages)) { + return pages; } =20 XBZRLE_cache_lock(); - - current_addr =3D block->offset + offset; - - if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { - if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { - if (bytes_xmit > 0) { - ram_counters.normal++; - } else if (bytes_xmit =3D=3D 0) { - ram_counters.duplicate++; - } - } - } else { - pages =3D save_zero_page(rs, block, offset); - if (pages > 0) { - /* Must let xbzrle know, otherwise a previous (now 0'd) cached - * page would be stale + pages =3D save_zero_page(rs, block, offset); + if (pages > 0) { + /* Must let xbzrle know, otherwise a previous (now 0'd) cached + * page would be stale + */ + xbzrle_cache_zero_page(rs, current_addr); + ram_release_pages(block->idstr, offset, pages); + } else if (!rs->ram_bulk_stage && + !migration_in_postcopy() && migrate_use_xbzrle()) { + pages =3D save_xbzrle_page(rs, &p, current_addr, block, + offset, last_stage); + if (!last_stage) { + /* Can't send this cached data async, since the cache page + * might get updated before it gets to the wire */ - xbzrle_cache_zero_page(rs, current_addr); - ram_release_pages(block->idstr, offset, pages); - } else if (!rs->ram_bulk_stage && - !migration_in_postcopy() && migrate_use_xbzrle()) { - pages =3D save_xbzrle_page(rs, &p, current_addr, block, - offset, last_stage); - if (!last_stage) { - /* Can't send this cached data async, since the cache page - * might get updated before it gets to the wire - */ - send_async =3D false; - } + send_async =3D false; } } =20 @@ -1174,63 +1192,49 @@ static int ram_save_compressed_page(RAMState *rs, P= ageSearchStatus *pss, bool last_stage) { int pages =3D -1; - uint64_t bytes_xmit =3D 0; uint8_t *p; - int ret; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; =20 p =3D block->host + offset; =20 - ret =3D ram_control_save_page(rs->f, block->offset, - offset, TARGET_PAGE_SIZE, &bytes_xmit); - if (bytes_xmit) { - ram_counters.transferred +=3D bytes_xmit; - pages =3D 1; + if (control_save_page(rs, block, offset, &pages)) { + return pages; } - if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { - if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { - if (bytes_xmit > 0) { - ram_counters.normal++; - } else if (bytes_xmit =3D=3D 0) { - ram_counters.duplicate++; - } + + /* When starting the process of a new block, the first page of + * the block should be sent out before other pages in the same + * block, and all the pages in last block should have been sent + * out, keeping this order is important, because the 'cont' flag + * is used to avoid resending the block name. + */ + if (block !=3D rs->last_sent_block) { + flush_compressed_data(rs); + pages =3D save_zero_page(rs, block, offset); + if (pages > 0) { + ram_release_pages(block->idstr, offset, pages); + } else { + /* + * Make sure the first page is sent out before other pages. + * + * we post it as normal page as compression will take much + * CPU resource. + */ + ram_counters.transferred +=3D save_page_header(rs, rs->f, bloc= k, + offset | RAM_SAVE_FLAG_PAGE); + qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, + migrate_release_ram() & + migration_in_postcopy()); + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + ram_counters.normal++; + pages =3D 1; } } else { - /* When starting the process of a new block, the first page of - * the block should be sent out before other pages in the same - * block, and all the pages in last block should have been sent - * out, keeping this order is important, because the 'cont' flag - * is used to avoid resending the block name. - */ - if (block !=3D rs->last_sent_block) { - flush_compressed_data(rs); - pages =3D save_zero_page(rs, block, offset); - if (pages > 0) { - ram_release_pages(block->idstr, offset, pages); - } else { - /* - * Make sure the first page is sent out before other pages. - * - * we post it as normal page as compression will take much - * CPU resource. - */ - ram_counters.transferred +=3D save_page_header(rs, rs->f, = block, - offset | RAM_SAVE_FLAG_PAG= E); - qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, - migrate_release_ram() & - migration_in_postcopy()); - ram_counters.transferred +=3D TARGET_PAGE_SIZE; - ram_counters.normal++; - pages =3D 1; - } + pages =3D save_zero_page(rs, block, offset); + if (pages =3D=3D -1) { + pages =3D compress_page_with_multi_thread(rs, block, offset); } else { - pages =3D save_zero_page(rs, block, offset); - if (pages =3D=3D -1) { - pages =3D compress_page_with_multi_thread(rs, block, offse= t); - } else { - ram_release_pages(block->idstr, offset, pages); - } + ram_release_pages(block->idstr, offset, pages); } } =20 --=20 2.17.0