Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KSY0I-0005Kd-Hy for qemu-devel@nongnu.org; Mon, 11 Aug 2008 10:04:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KSY0F-0005It-6z for qemu-devel@nongnu.org; Mon, 11 Aug 2008 10:04:10 -0400 Received: from [199.232.76.173] (port=35745 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KSY0E-0005Iq-U2 for qemu-devel@nongnu.org; Mon, 11 Aug 2008 10:04:06 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:55282) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KSY0E-0006p8-7h for qemu-devel@nongnu.org; Mon, 11 Aug 2008 10:04:06 -0400 Subject: Re: [Qemu-devel] [patch 5/5][v2] Try to aggregate free clusters and freed clusters From: Laurent Vivier In-Reply-To: <48A03AE7.7050908@suse.de> References: <20080729141352.573798859@bull.net> <20080729141447.763322831@bull.net> <48A03AE7.7050908@suse.de> Content-Type: text/plain; charset=utf-8 Date: Mon, 11 Aug 2008 16:04:01 +0200 Message-Id: <1218463441.3871.29.camel@frecb07144> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf Le lundi 11 ao=C3=BBt 2008 =C3=A0 15:13 +0200, Kevin Wolf a =C3=A9crit : > Hi Laurent, >=20 > Laurent Vivier schrieb: > > In free_used_clusters(), try to aggregate free clusters and freed clu= sters. > >=20 > > Signed-off-by: Laurent Vivier > > --- > > block-qcow2.c | 61 ++++++++++++++++++++++++++++++++++-------------= ----------- > > 1 file changed, 36 insertions(+), 25 deletions(-) >=20 > I know that this patch will be rewritten as well, but I'll comment on i= t > nevertheless. Maybe the comments apply to your new version, too. >=20 >=20 > > Index: qemu/block-qcow2.c > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > --- qemu.orig/block-qcow2.c 2008-07-29 15:22:28.000000000 +0200 > > +++ qemu/block-qcow2.c 2008-07-29 15:22:30.000000000 +0200 > > @@ -714,22 +703,44 @@ static uint64_t free_used_clusters(Block > > return 0; > > } > > =20 > > - if (nb_clusters) { > > - int i =3D 1; > > - uint64_t current; > > - while (i < *nb_clusters) { > > - current =3D be64_to_cpu((*l2_table)[(*l2_index) + i]); > > - if (cluster_offset + (i << s->cluster_bits) !=3D current= ) > > - break; > > - i++; > > - } > > - *nb_clusters =3D i; > > - free_clusters(bs, cluster_offset, i << s->cluster_bits); > > + if (!nb_clusters) { > > + if (cluster_offset) > > + free_clusters(bs, cluster_offset, s->cluster_size); > > return 0; > > } > > =20 > > - free_clusters(bs, cluster_offset, s->cluster_size); > > + i =3D 0; > > + do_loop =3D 1; > > + while (i < *nb_clusters && do_loop) { > > + i++; > > + if (!cluster_offset) { > > + while (i < *nb_clusters) { > > + cluster_offset =3D (*l2_table)[(*l2_index) + i]; > > + if (cluster_offset) > > + break; > > + i++; > > + } > > + if ((cluster_offset & QCOW_OFLAG_COPIED) || > > + (cluster_offset & QCOW_OFLAG_COMPRESSED)) > > + do_loop =3D 0; > > + } else { > > + j =3D 1; > > + current =3D 0; > > + while (i < *nb_clusters) { > > + current =3D be64_to_cpu((*l2_table)[(*l2_index) + i]= ); > > + if (cluster_offset + (j << s->cluster_bits) !=3D cur= rent) > > + break; > > + i++; > > + j++; > > + } > > + free_clusters(bs, cluster_offset, j << s->cluster_bits); > > + cluster_offset =3D current; > > + if (current) > > + do_loop =3D 0; >=20 > The else block changes its behaviour with this patch: I think you shoul= d > take QCOW_OFLAG_COPIED into consideration. In this implementation, whe= n > a cluster with QCOW_OFLAG_COPIED is found, the inner loop aborts, but > the outer one will just call the else block once again. So you're also > accumulating clusters with QCOW_OFLAG_COPIED set. No, before the first loop QCOW_OFLAG_COPIED is not set. if cluster_offset is 0 and flag appears, we set do_loop to 0 and exit from the main loop. if cluster_offset is !=3D 0 we go into the else until current becomes 0 o= r a flag is set and then if current is not 0 (i.e. a flag or a non contiguous cluster) we set do_loop to 0 and exit from the loop. > BTW, why do you use that do_loop variable instead of a break statement? Yes Laurent --=20 ----------------- Laurent.Vivier@bull.net ------------------ "La perfection est atteinte non quand il ne reste rien =C3=A0 ajouter mais quand il ne reste rien =C3=A0 enlever." Saint Exup=C3=A9ry