Received: from eggs.gnu.org ([2001:4830:134:3::10]:51234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c77qU-0001QQ-FI for qemu-devel@nongnu.org; Wed, 16 Nov 2016 16:34:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c77qT-0003Or-70 for qemu-devel@nongnu.org; Wed, 16 Nov 2016 16:34:18 -0500 References: <20161116144826.3841abf44a3d2a5e0f718268@gmail.com> From: Eric Blake Message-ID: Date: Wed, 16 Nov 2016 15:34:10 -0600 MIME-Version: 1.0 In-Reply-To: <20161116144826.3841abf44a3d2a5e0f718268@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xqBLtgJm8QP3wweKNMTWCMrmo1ooSxmnp" Subject: Re: [Qemu-devel] [Qemu-block] Once again with feeling: work-around for slow SEEK_HOLE on Linux tmpfs. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christopher Oliver , qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --xqBLtgJm8QP3wweKNMTWCMrmo1ooSxmnp From: Eric Blake To: Christopher Oliver , qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Message-ID: Subject: Re: [Qemu-block] Once again with feeling: work-around for slow SEEK_HOLE on Linux tmpfs. References: <20161116144826.3841abf44a3d2a5e0f718268@gmail.com> In-Reply-To: <20161116144826.3841abf44a3d2a5e0f718268@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/16/2016 01:48 PM, Christopher Oliver wrote: >=20 >=20 Attaching the patch (rather than including it inline) requires reviewers to save the attachment off to a file in order to even see what you wrote. To save others some time, I'm pasting the text and replying inlin= e: > The following patch is a work-around for slow SEEK_HOLE on some filesys= tems. The subject line is too long and doesn't match the usual pattern of "category: short synopsis". > Specifically, SEEK_HOLE on a dense file on Linux tmpfs is linear time i= n > the length. This slows qemu-img to a crawl as it runs SEEK_DATA/SEEK_H= OLE > pairs over the length of the image it's reading stepping by small delta= s. >=20 > The key observation is that if the descriptor is read-only, and there a= re > no writers anywhere else (that's undefined behavior anyhow, right?), th= en a > hole seek in the interval from the previous start to the previously fou= nd > hole will find the same hole. >=20 > Signed-off-by: Christopher Oliver The S-o-b is incorrect; it is missing an email address. Without that, the patch cannot be accepted. You'll want to try again, but this time, I suggest getting 'qemu send-email' working to the point that you can send yourself an inline patch (not an attachment), before sending v2 to the list; you may also want to check out other patch submission guidelines here: http://wiki.qemu.org/Contribute/SubmitAPatch >=20 > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 28b47d9..b45defe 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -136,6 +136,8 @@ typedef struct BDRVRawState { > int type; > int open_flags; > size_t buf_align; > + off_t last_hole; > + off_t hole_follows; > =20 > #ifdef CONFIG_XFS > bool is_xfs:1; > @@ -470,6 +472,7 @@ static int raw_open_common(BlockDriverState *bs, QD= ict *options, > =20 > s->has_discard =3D true; > s->has_write_zeroes =3D true; > + s->last_hole =3D -1; > bs->supported_zero_flags =3D BDRV_REQ_MAY_UNMAP; > if ((bs->open_flags & BDRV_O_NOCACHE) !=3D 0) { > s->needs_alignment =3D true; > @@ -1710,7 +1713,24 @@ static int find_allocation(BlockDriverState *bs,= off_t start, > * H4. offs < 0, errno !=3D ENXIO: we learned nothing > * Pretend we know nothing at all, i.e. "forget" about D1. > */ > - offs =3D lseek(s->fd, start, SEEK_HOLE); > + /* Addendum: Since HOLE seeks are expensive on some filesystems Can anything be done to Linux tmpfs to make HOLE seeks less expensive? > + * (e.g. tmpfs) and holes don't change when an image is read only,= > + * cache the range from a start to a hold and return that value s/hold/hole/ > + * for requests in that interval. Outside of that interval, seek > + * and cache the new range. > + */ > + if ((s->open_flags & (O_RDWR|O_RDONLY)) =3D=3D O_RDONLY) { > + if (start <=3D s->last_hole && start >=3D s->hole_follows) { > + offs =3D lseek(s->fd, s->last_hole, SEEK_SET); > + } else { > + offs =3D lseek(s->fd, start, SEEK_HOLE); > + s->last_hole =3D offs; > + s->hole_follows =3D start; > + } > + } else { > + offs =3D lseek(s->fd, start, SEEK_HOLE); > + } > + > if (offs < 0) { > return -errno; /* D1 and (H3 or H4) */ > } --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --xqBLtgJm8QP3wweKNMTWCMrmo1ooSxmnp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYLNDSAAoJEKeha0olJ0Nq/GsH/3D6Of1QUxSr8hofL7HJHQwx ObQ90unwI+Q9BIjKzhCvclxQzne+QWB+nnGnjlPO4WVyn5d1LhqaYOoeKJn9rmDu q2Sn7vWBdpZFiiw4vo6JuT5nS82ixsJYnHRZlIp+2cGMr1GkqWYJlAZ34QJIkePq xZFBWu8JTVwmKFbZtIwAY9DGm+1OwxU0/UGc8WnYdWvvFjSAO9myvA3zSnJ5kM4i Iy/QO0X7zNVE5KIlYi93UliMVWs2HRoZItlr6U8lihDSlaUeQd/WCS9eaffgm6wt SAPad99t5zo26cLQ4hh4NxVwMgJx70BjDv7/lKSuAlm0C6pgVCNspstxixgmbXs= =o3Zj -----END PGP SIGNATURE----- --xqBLtgJm8QP3wweKNMTWCMrmo1ooSxmnp--