Received: from eggs.gnu.org ([2001:4830:134:3::10]:39581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPrer-0004nL-JF for qemu-devel@nongnu.org; Wed, 20 Jul 2016 09:35:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPreo-0005Ob-Vo for qemu-devel@nongnu.org; Wed, 20 Jul 2016 09:35:28 -0400 Date: Wed, 20 Jul 2016 15:35:17 +0200 From: Niels de Vos Message-ID: <20160720133517.GE23632@ndevos-x240.usersys.redhat.com> References: <1468901281-22858-1-git-send-email-eblake@redhat.com> <578E4708.5080308@redhat.com> <20160720033402.GA7641@ad.usersys.redhat.com> <578EF446.70202@redhat.com> <20160720043709.GA10539@ad.usersys.redhat.com> <913397c9-6edc-2561-3d2e-e32032f9db22@redhat.com> <20160720073836.GF10539@ad.usersys.redhat.com> <1796238868.8815050.1469006377577.JavaMail.zimbra@redhat.com> <20160720123025.GO2031@devil.localdomain> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="r7U+bLA8boMOj+mD" Content-Disposition: inline In-Reply-To: <20160720123025.GO2031@devil.localdomain> Subject: Re: [Qemu-devel] semantics of FIEMAP without FIEMAP_FLAG_SYNC (was Re: [PATCH v5 13/14] nbd: Implement NBD_CMD_WRITE_ZEROES on server) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Dave Chinner Cc: Paolo Bonzini , Fam Zheng , Eric Blake , Kevin Wolf , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , Lukas Czerner , P@draigBrady.com --r7U+bLA8boMOj+mD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 20, 2016 at 10:30:25PM +1000, Dave Chinner wrote: > On Wed, Jul 20, 2016 at 05:19:37AM -0400, Paolo Bonzini wrote: > > Adding ext4 and XFS guys (Lukas and Dave respectively). As a quick rec= ap, the > > issue here is the semantics of FIEMAP and SEEK_HOLE/SEEK_DATA, which we= use in > > "qemu-img map". This command prints metadata about a virtual disk imag= e---which > > in the case of a raw image amounts to detecting holes and unwritten ext= ents. > >=20 > > First, it seems like SEEK_HOLE and SEEK_DATA really should be "SEEK_NON= ZERO" and > > "SEEK_ZERO", on both ext4 and XFS. You can see that unwritten extent= s are > > reported by "qemu-img map" as holes: >=20 > Correctly so. seek hole/data knows nothing about the underlying > filesystem storage implementation. A "hole" is defined as a region > of zeros, and the filesystem is free call anything it kows for > certain contains zeros as a hole. >=20 > FYI, SEEK_HOLE/DATA were named after the the pre-existing Solaris > seek API that uses these definitions for hole and data.... >=20 > > $ dd if=3D/dev/urandom of=3Dtest.img bs=3D1M count=3D100 > > $ fallocate -z -o 10M -l 10M test.img > > $ du -h test.img > > $ qemu-img map --output=3Djson test.img > > [{ "start": 0, "length": 10485760, "depth": 0, "zero": false, "data= ": true, "offset": 0}, > > { "start": 10485760, "length": 10485760, "depth": 0, "zero": true, = "data": false, "offset": 10485760}, > > { "start": 20971520, "length": 83886080, "depth": 0, "zero": false,= "data": true, "offset": 20971520}] >=20 > >=20 > > On the second line, zero=3Dtrue data=3Dfalse identifies a hole. The ri= ght output > > would either have zero=3Dtrue data=3Dtrue (unwritten extent) or just > >=20 > > [{ "start": 0, "length": 104857600, "depth": 0, "zero": false, "dat= a": true, "offset": 0}, > > > > since the zero flag is advisory (it doesn't try to detect zeroes beyond= what the > > filesystem says). >=20 > Not from SEEK_HOLE/SEEK_DATA. All it conveys is "this is the start > of a range of zeros" and "this is the start of a range of data". And > for filesystems that don't specifically implement these seek > operations, zeros are considered data. i.e. SEEK_HOLE will take you > to the end of file, SEEK_DATA returns the current position.... >=20 > i.e. unwritten extents contain no data, so they are semantically > identical to holes for the purposes of seeking and hence SEEK_DATA > can skip over them. >=20 > > The reason why we disabled FIEMAP was a combination of a corruption and= performance > > issue. The data corruption bug was at https://bugs.launchpad.net/qemu/= +bug/1368815 > > and it was reported on Ubuntu Trusty (kernel 3.13 based on the release = notes at > > https://wiki.ubuntu.com/TrustyTahr/ReleaseNotes). We corrected that by= using > > FIEMAP_FLAG_SYNC, based on a similar patch to coreutils. This turned o= ut to be too > > slow, so we dropped FIEMAP altogether. >=20 > Yes, because FIEMAP output is only useful for diagnostic purposes as > it can be stale even before the syscall returns to userspace. i.e. > it can't be used in userspace for optimising file copies.... Oh... And I was surprised to learn that "cp" does use FIEMAP and not SEEK_HOLE/SEEK_DATA. You give a strong suggestion to fix that. http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/extent-scan.c#n87 > Finding regions of valid data in a file is what SEEK_HOLE/SEEK_DATA > is for, not FIEMAP. FIEMAP only reports the physical layout of the > file, now where the currently valid data in the file lies. >=20 > > However, today I found kernel commit 91dd8c114499 ("ext4: prevent race = while walking > > extent tree for fiemap", 2012-11-28) whose commit message says: > >=20 > > Moreover the extent currently in delayed allocation might be alloca= ted > > after we search the extent tree and before we search extent status = tree > > delayed buffers resulting in those delayed buffers being completely > > missed, even though completely written and allocated. > >=20 > > This seems pretty much like our data corruption bug; it would mean that > > using FIEMAP_FLAG_SYNC was only working around a bug and delayed alloca= tions > > _should_ be reported as usual by FIEMAP. >=20 > What do you think you can do with the delayed allocation regions in > the file? >=20 > Indeed, with specualtive delayed allocation, XFS can report delalloc > regions that have no actual resemblence to the layout of dirty data > in the file. SEEK_DATA will iterate the delalloc regions containing > data precisely, however. >=20 > > Except that the commit went in kernel 3.8 and as said above Trusty had = 3.13. > > So either there are other bugs, or my understanding of the commit is no= t correct. > > So the questions for Lukas and Dave are: > >=20 > > 1) is it expected that SEEK_HOLE skips unwritten extents? >=20 > There are multiple answers to this, all of which are correct depending > on current context and state: >=20 > 1. No - some filesystems will report clean unwritten extents as holes. >=20 > 2. Yes - some filesystems will report clean unwritten extents as > data. >=20 > 3. Maybe - if there is written data in memory over the unwritten > extent on disk (i.e. hasn't been flushed to disk, it will be > considered a data region with non-zero data. (FIEMAP will still > report is as unwritten) >=20 > > If not, would > > it be acceptable to introduce Linux-specific SEEK_ZERO/SEEK_NONZERO, wh= ich > > would be similar to what SEEK_HOLE/SEEK_DATA do now? >=20 > To solve what problem? You haven't explained what problem you are > trying to solve yet. I think this is about optimizing file copy. There is a difference between pre-allocated (but unwritten) and zero'd out extents. In the Gluster network protocol, we could use FALLOCATE for the first, and ZEROFILL for the second. Depending on what the underlaying filesystem and storage support, performance would differ. But, maybe this distinction is not important enough to optimize for? That is not something I can judge for the QEMU use-case. > > 2) for FIEMAP do we really need FIEMAP_FLAG_SYNC? And if not, for what > > filesystems and kernel releases is it really not needed? >=20 > I can't answer this question, either, because I don't know what > you want the fiemap information for. Great details, thanks for sharing! HTH, Niels --r7U+bLA8boMOj+mD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXj34VAAoJECXo5AApwsWzaCUQAKEPjw0sqP4y8Lk3c/SN/5Eu wyv6KwP7j4jSIBSxajFaW+/dYXHPMjlbmFOSaH19LW8PHY5lN9E5W2xpMMAKPlee qe1tliWHt3McdcBeHfXgHL+sRWPbpeia5sAD08sVxwZuEe8qCgtzQmXCkS9ol2Ch 9fDPhsNgoAQFNxzpaYRd1/wUre1cd2M1YOLVdFh3rrum1AO6XtCbuUFlkP5u4XXV iKyARt6XFdCN0/11O3hxnZEbo3MCPGkMwi9JJ1IDFHHiUmlwxi58xlIdGAGuM+MO 3eAWBpNKNgxWCDJ2hxaI2fKDEdBYX4s71f8YgAHB2GoilI+mv2x/7iHxyvoE/UN8 ybCAepC+yF1xmKPp/Y49a76Z2I9xWWqD0ODvZ+gB231781SoBmB281Ov1RC41BRq WXFdfO54rVxxQvKbHWtXZm0E2H+ypd6VI8ylyAyvo0XStaxeuHYnkWxRjXGpeKzn OhcpcKJDtaMfRn97m2Rq9m+pDzmCsd2NhKdrixKDalVlBCWGEGhUAygnBZZLdyVf TwZWVVj8jQBHnUreLqy9hK0+SJp9vwZ1qaQ6tiPA/UOhA/3/qMzJPEzSrDdzOHCj fHqobLrixYNRd8gZ8illf2YxlcUdqRH46LcgfSBNqUI0uwAHES50VrnohSoQZnat vdykrDpMqdxo/fNw7XUi =Cd6p -----END PGP SIGNATURE----- --r7U+bLA8boMOj+mD--