From nobody Mon Feb 9 19:08:09 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491486246705800.984168066297; Thu, 6 Apr 2017 06:44:06 -0700 (PDT) Received: from localhost ([::1]:45920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cw7hl-0002S2-Fk for importer@patchew.org; Thu, 06 Apr 2017 09:44:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cw7BI-0006ZL-LM for qemu-devel@nongnu.org; Thu, 06 Apr 2017 09:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cw7BH-0000AB-DV for qemu-devel@nongnu.org; Thu, 06 Apr 2017 09:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54600) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cw7BH-00009v-4l for qemu-devel@nongnu.org; Thu, 06 Apr 2017 09:10:31 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 398C366CB9 for ; Thu, 6 Apr 2017 13:10:30 +0000 (UTC) Received: from secure.mitica (ovpn-117-221.ams2.redhat.com [10.36.117.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4892FA2E87; Thu, 6 Apr 2017 13:10:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 398C366CB9 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 398C366CB9 From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 6 Apr 2017 15:09:06 +0200 Message-Id: <20170406130913.2232-48-quintela@redhat.com> In-Reply-To: <20170406130913.2232-1-quintela@redhat.com> References: <20170406130913.2232-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 06 Apr 2017 13:10:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 47/54] ram: reorganize last_sent_block 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: dgilbert@redhat.com 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" We were setting it far away of when we changed it. Now everything is done inside save_page_header. Once there, reorganize code to pass RAMState. We also set CONTINUE flag in a single place. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- migration/ram.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 9ed91e5..1ef142f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -451,18 +451,22 @@ void migrate_compress_threads_create(void) * @offset: offset inside the block for the page * in the lower bits, it contains flags */ -static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t of= fset) +static size_t save_page_header(RAMState *rs, RAMBlock *block, ram_addr_t o= ffset) { size_t size, len; =20 - qemu_put_be64(f, offset); + if (block =3D=3D rs->last_sent_block) { + offset |=3D RAM_SAVE_FLAG_CONTINUE; + } + qemu_put_be64(rs->f, offset); size =3D 8; =20 if (!(offset & RAM_SAVE_FLAG_CONTINUE)) { len =3D strlen(block->idstr); - qemu_put_byte(f, len); - qemu_put_buffer(f, (uint8_t *)block->idstr, len); + qemu_put_byte(rs->f, len); + qemu_put_buffer(rs->f, (uint8_t *)block->idstr, len); size +=3D 1 + len; + rs->last_sent_block =3D block; } return size; } @@ -582,7 +586,7 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **cur= rent_data, } =20 /* Send XBZRLE based compressed page */ - bytes_xbzrle =3D save_page_header(rs->f, block, + bytes_xbzrle =3D save_page_header(rs, block, offset | RAM_SAVE_FLAG_XBZRLE); qemu_put_byte(rs->f, ENCODING_FLAG_XBZRLE); qemu_put_be16(rs->f, encoded_len); @@ -767,7 +771,7 @@ static int save_zero_page(RAMState *rs, RAMBlock *block= , ram_addr_t offset, if (is_zero_range(p, TARGET_PAGE_SIZE)) { rs->zero_pages++; rs->bytes_transferred +=3D - save_page_header(rs->f, block, offset | RAM_SAVE_FLAG_COMPRESS= ); + save_page_header(rs, block, offset | RAM_SAVE_FLAG_COMPRESS); qemu_put_byte(rs->f, 0); rs->bytes_transferred +=3D 1; pages =3D 1; @@ -824,9 +828,6 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) =20 current_addr =3D block->offset + offset; =20 - if (block =3D=3D rs->last_sent_block) { - offset |=3D RAM_SAVE_FLAG_CONTINUE; - } if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { if (bytes_xmit > 0) { @@ -858,8 +859,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - rs->bytes_transferred +=3D save_page_header(rs->f, block, - offset | RAM_SAVE_FLAG_PAGE= ); + rs->bytes_transferred +=3D save_page_header(rs, block, + offset | RAM_SAVE_FLAG_P= AGE); if (send_async) { qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, migrate_release_ram() & @@ -880,10 +881,11 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss, bool last_stage) static int do_compress_ram_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) { + RAMState *rs =3D &ram_state; int bytes_sent, blen; uint8_t *p =3D block->host + (offset & TARGET_PAGE_MASK); =20 - bytes_sent =3D save_page_header(f, block, offset | + bytes_sent =3D save_page_header(rs, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); blen =3D qemu_put_compression_data(f, p, TARGET_PAGE_SIZE, migrate_compress_level()); @@ -1014,7 +1016,7 @@ static int ram_save_compressed_page(RAMState *rs, Pag= eSearchStatus *pss, pages =3D save_zero_page(rs, block, offset, p); if (pages =3D=3D -1) { /* Make sure the first page is sent out before other pages= */ - bytes_xmit =3D save_page_header(rs->f, block, offset | + bytes_xmit =3D save_page_header(rs, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); blen =3D qemu_put_compression_data(rs->f, p, TARGET_PAGE_S= IZE, migrate_compress_level()); @@ -1031,7 +1033,6 @@ static int ram_save_compressed_page(RAMState *rs, Pag= eSearchStatus *pss, ram_release_pages(block->idstr, pss->offset, pages); } } else { - offset |=3D RAM_SAVE_FLAG_CONTINUE; pages =3D save_zero_page(rs, block, offset, p); if (pages =3D=3D -1) { pages =3D compress_page_with_multi_thread(rs, block, offse= t); @@ -1336,13 +1337,6 @@ static int ram_save_target_page(RAMState *rs, PageSe= archStatus *pss, if (unsentmap) { clear_bit(dirty_ram_abs >> TARGET_PAGE_BITS, unsentmap); } - /* Only update last_sent_block if a block was actually sent; xbzrle - * might have decided the page was identical so didn't bother writ= ing - * to the stream. - */ - if (res > 0) { - rs->last_sent_block =3D pss->block; - } } =20 return res; --=20 2.9.3