From nobody Tue Oct 28 01:58:00 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; dkim=fail; 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=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522228710657472.2901208137714; Wed, 28 Mar 2018 02:18:30 -0700 (PDT) Received: from localhost ([::1]:38186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f17Ds-0006kR-RI for importer@patchew.org; Wed, 28 Mar 2018 05:18:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f176P-0000w5-Vo for qemu-devel@nongnu.org; Wed, 28 Mar 2018 05:10:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f176O-00053R-Cz for qemu-devel@nongnu.org; Wed, 28 Mar 2018 05:10:41 -0400 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]:41949) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f176O-00051e-55 for qemu-devel@nongnu.org; Wed, 28 Mar 2018 05:10:40 -0400 Received: by mail-pg0-x232.google.com with SMTP id t10so707091pgv.8 for ; Wed, 28 Mar 2018 02:10:40 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id q9sm5590648pgs.89.2018.03.28.02.10.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Mar 2018 02:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sFu4QSTOV4tjzMqswvpkzJdod0DV1g8C2XOfU7z++68=; b=dQuQX8zT08hHGELQImGx2uWAh8IYSRVvM6hEZliQCCUmwZSoVAMiyV9H4lUaNOkJCr GZ6r5DmDlgMd9koZHWGEHQzVWp2Labze6vvNUrp3cQteg6iv3Ml9VpWzrAOCLc2gioJb qTwFrahq37SpLFk7RBKl5hfP0weEXm0asaTd07AD7QXXh9Wm1CrSntfIYIKmwtN72yP9 eDVL1+cbO/rf0p0pnbgSjJyizvY8HfN5+I3xJ4INOkYb4PbaDq0IZrOSFvhO+fxhptPI f1PIaZyoodM7oIyunhOUVDSPuEugShuerp+s2NYthLlkRPelq2bE9qRWtu/4iXL+G+fr i2kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sFu4QSTOV4tjzMqswvpkzJdod0DV1g8C2XOfU7z++68=; b=AY6fHLMkfLilV64DukD3LC4m/dqQYmjm79kny7xMPk510pwyceGVVa4jVtTYOf6KO9 0JjqOY6lZDQbZksg9w59Y//Oq6alrLw0dbdl3nyqw0MSet2YIAfcrUAs2f5KJD9PgbYj j6yAgK5dFVZWiwSgHPWBaoTLNT1+I5YnrmWWn2mU199CuRLb0jkMCpxcx7BrCM2yY6WS VYLKkRlRkN3q5+osR0rndC3ZXMPvygtpJoeoj8/cNrd8M21vpYyExPjUgKehU5eHyoq8 8h5JcTdROIjwzfejF1tC0sxuqNgWnyxNATa2RFTJ8OZxl1XfvPgC7y+cU+qSOFgX0ar8 tPXA== X-Gm-Message-State: AElRT7FC7dDS88wGt7CYXCyjQA/4V5BeHxFRdW7ENT2NXKlSrZzjc974 UjMCCuqPT9qXR8z1aBrAWrg= X-Google-Smtp-Source: AIpwx49Pk/4GJXEyFFlz3aBmb4Lgws7Pc8xRwopRMQD1NfU2R8ByYaP49JPBW53w04oPfuPU136Z0g== X-Received: by 10.99.123.71 with SMTP id k7mr2052468pgn.134.1522228239279; Wed, 28 Mar 2018 02:10:39 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Tue, 27 Mar 2018 17:10:38 +0800 Message-Id: <20180327091043.30220-6-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180327091043.30220-1-xiaoguangrong@tencent.com> References: <20180327091043.30220-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::232 Subject: [Qemu-devel] [PATCH v2 05/10] 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: , Cc: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 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 --- migration/ram.c | 174 +++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 89 insertions(+), 85 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e85191c1cb..fc1fde7bb7 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -976,6 +976,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 * @@ -992,56 +1030,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 @@ -1176,63 +1194,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.14.3