From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTvGR-0007fF-1B for qemu-devel@nongnu.org; Sat, 29 Mar 2014 11:33:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTvGM-0004C5-3f for qemu-devel@nongnu.org; Sat, 29 Mar 2014 11:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTvGL-0004Bu-SU for qemu-devel@nongnu.org; Sat, 29 Mar 2014 11:33:38 -0400 Message-ID: <5336E7C8.1060100@redhat.com> Date: Sat, 29 Mar 2014 09:33:28 -0600 From: Eric Blake MIME-Version: 1.0 References: <1396079541-7112-1-git-send-email-arei.gonglei@huawei.com> <5336D059.2080106@redhat.com> <118C69AB-F17E-41B6-AFEF-5C1C02E345C9@icloud.com> <5336D7FE.5050904@redhat.com> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6V6WLUQ0JxaaFJrfD7xvXSmRUjKf3kXm1" Subject: Re: [Qemu-devel] [PATCH] xbzrle: don't check the value in the vm ram repeatedly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?6ZmI5qKB?= Cc: ChenLiang , weidong.huang@huawei.com, quintela@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com, owasserm@redhat.com, arei.gonglei@huawei.com, mrhines@us.ibm.com, pbonzini@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --6V6WLUQ0JxaaFJrfD7xvXSmRUjKf3kXm1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/29/2014 09:00 AM, =E9=99=88=E6=A2=81 wrote: >>> You really need to do the "go over the rest" loop on an 8-byte tempor= ary >>> variable. Ever since your patch made new_buf be a volatile buffer, >>> rather than a static copy, you MUST visit each byte of new_buf exactl= y once. >>> >> hmm, thanks. get it. Maybe we can do it like this > sorry, it should like this >=20 > /* word at a time for speed */ > if (!res) { > while (i < slen && > (*(long *)(old_buf + i)) =3D=3D (*(long *)(new_buf += i))) { > i +=3D sizeof(long); > zrun_len +=3D sizeof(long); > } >=20 > /* go over the rest */ > //while (i < slen && old_buf[i] =3D=3D new_buf[i]) { > // zrun_len++; > // i++; > //} > } No, that's not right either. Once you have made a decision based on something you have read, you must proceed with that decision. In the case, you broke out of the while loop because you found a difference. Now you must report the location of that difference, as of the time where you read it and without re-reading from new_buf. The ONLY viable solution is to read the contents of new_buf into a temporary, then do all subsequent actions on that temporary. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --6V6WLUQ0JxaaFJrfD7xvXSmRUjKf3kXm1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJTNufIAAoJEKeha0olJ0NqNkwH/id65z6N4NMkd3CeerviuE96 4td513V+pOqZVou46ROJggu7Ih4Tig1sTXYGC1yqh82Z3wka024+tED5rFiU22Vx Ddza8AxQO3V1p3g2lckYJnu37Pf1sRTPiKiEHuj0qGHmfqVcCrXgHJiI17Hl0FBM ERsmgIASyUtNMmwgPXVX1iaptHZ9BA9e7GpIyvzEd7SRb6dD56jCobb9VPsS/vuS kAixg7HSMwLT+kht6i3EnHNwjN/XOF9w06RHYCYH+9Ooe/y8LiEmyK8OMc1WSSxU CVvmJYg9c1ujmHJ/OSZTExb2zHiH+yAZ45JqWGMxJN1BghcKPJV/Bwp7T0MZiOc= =bT8Z -----END PGP SIGNATURE----- --6V6WLUQ0JxaaFJrfD7xvXSmRUjKf3kXm1--