From nobody Tue Feb 10 23:13:21 2026 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 1522396736227589.0599641471172; Fri, 30 Mar 2018 00:58:56 -0700 (PDT) Received: from localhost ([::1]:41126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ow1-00008Q-9C for importer@patchew.org; Fri, 30 Mar 2018 03:58:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oop-0001xX-0J for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oom-0007eB-On for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:26 -0400 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]:34955) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oom-0007ds-Fv for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:24 -0400 Received: by mail-pf0-x232.google.com with SMTP id u86so4982794pfd.2 for ; Fri, 30 Mar 2018 00:51:24 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:22 -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=XsxfFpBYGEbNF2r+20A4GycRAcq4g/gPhN8+JOpd+Vo=; b=fbYlrjEIv9f6gh1vz7NZfRbJf/B/7krvCd5Q9k6RSgAN2MzIOd6SbNWaq84wkruztz LUGHbWhxxq8CQUXfpGnbsAhvxauxxhqjTm9RTfc1PzHOQ33MG1+zF80rOsV/05Gr+UT5 k126Pf2wboTfAwSTKtzwTKm2baZXtXHrZIIKh+OC7TYQjtRzJeZ4FswNemxW7+gmZs3/ xnAMA1g2NU9GWtNrZASdezQwGQYWpNGwxOzl3d54Fi+Ls9UX59Es5R4EIeV6ETRc5/Wt OimyWFzodlaHnQQtFaxNdphz+/FdeV1vHZl4e1NFGqKXgdzWx3VPiKNNpzBPBrRbPDfY GBCg== 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=XsxfFpBYGEbNF2r+20A4GycRAcq4g/gPhN8+JOpd+Vo=; b=Ch3jl70jmJSf2DKDUSv4nkfnDtfkSEcWeB0faBty50zfhaXBuhjao9hoNNYjCClDdU XiuBj6qzupOPQPu4Sic1oKbh9UM+4p8f0zOZUrpPqBYihj+q4nu1z5rEuACSkiNTtWQe 1uZyr+2D07Yc5tfYqyrEpxzb0YBm8qZpoWxQooPcnM+b2Bq6wosKvAn3sTPbQtsnomcM 4SlGiaEejVJFI4jOJ6aJIKGd9f/fNOR4OuPR6+c5MMUFUGP77LqLQOB+XjQREsX39pVc Z8Jm6z9m0QMYjFks/ZI4sK8vHRuIomfJlxx4gSClBj5coTl1S1uFZLX1d7lRpDJvspcN cwcw== X-Gm-Message-State: AElRT7GbvyVa5KxncgGoCFP/DMVVKFB7WDmL0olBERqOLRqg+6aTzcW9 kLjLZ2eXTWEBP7TiA4k1x8o= X-Google-Smtp-Source: AIpwx4/9nQfJjQPiGAdrNg1d+khfAPHGRGGHXSrjU2Jz3x1WIki/by36qQkIHJBjsfVn5yHkGSTWtw== X-Received: by 10.101.74.69 with SMTP id a5mr7982694pgu.32.1522396283467; Fri, 30 Mar 2018 00:51:23 -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: Fri, 30 Mar 2018 15:51:23 +0800 Message-Id: <20180330075128.26919-6-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::232 Subject: [Qemu-devel] [PATCH v3 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 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.14.3