From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 10 21:48:23 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 45B2ED5F; Sun, 10 Feb 2013 21:48:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 9753363D; Sun, 10 Feb 2013 21:48:22 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r1ALmIRI046444; Sun, 10 Feb 2013 23:48:18 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r1ALmIRI046444 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r1ALmIJ2046443; Sun, 10 Feb 2013 23:48:18 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 10 Feb 2013 23:48:18 +0200 From: Konstantin Belousov To: Ian Lepore Subject: Re: fcntl(2) F_READAHEAD set to zero doesn't work [patch] Message-ID: <20130210214818.GU2522@kib.kiev.ua> References: <1360367889.4545.58.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="yUaAwXDrp3vRFP8y" Content-Disposition: inline In-Reply-To: <1360367889.4545.58.camel@revolution.hippie.lan> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: "freebsd-hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Feb 2013 21:48:23 -0000 --yUaAwXDrp3vRFP8y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 08, 2013 at 04:58:09PM -0700, Ian Lepore wrote: > I discovered today that fcntl(fd, F_READAHEAD, 0) doesn't work as > advertised. It's supposed to disable readahead, but instead it restores > the default readahead behavior (if it had previously been changed), and > there is no way to disable readahead.[1] I think the attached patch > fixes it, but it's not immediately clear from the patch why; here's the > deal... >=20 > The amount of readahead is calculated by sequential_heuristic() in > vfs_vnops.c. If the FRDAHEAD flag is set on the file it uses the value > stored in the file's f_seqcount, otherwise it calculates a value (and > updates f_seqcount, which doesn't ever happen when FRDAHEAD is set). >=20 > So the patch causes the FRDAHEAD flag to be set even in the case of the > readahead amount being zero. Because it seems like a useful concept, it > still allows the readahead to be restored to default behavior, now by > passing a negative value. >=20 > Does this look right to those of you who understand this part of the > system better than I do? It looks correct. I do wonder if it better to keep the actual behaviour as is and set the readahead amount to default on the arg =3D=3D 0, disabling readahead for arg < 0. It is too exteme, most likely, please proceed. >=20 > -- Ian >=20 > [1] No way using F_READAHEAD; I know about POSIX_FADV_RANDOM. > Index: sys/kern/kern_descrip.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 > --- sys/kern/kern_descrip.c (revision 246337) > +++ sys/kern/kern_descrip.c (working copy) > @@ -776,7 +776,7 @@ > } > fhold(fp); > FILEDESC_SUNLOCK(fdp); > - if (arg !=3D 0) { > + if (arg >=3D 0) { > vp =3D fp->f_vnode; > error =3D vn_lock(vp, LK_SHARED); > if (error !=3D 0) { > Index: lib/libc/sys/fcntl.2 > =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 > --- lib/libc/sys/fcntl.2 (revision 246337) > +++ lib/libc/sys/fcntl.2 (working copy) > @@ -28,7 +28,7 @@ > .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 > .\" $FreeBSD$ > .\" > -.Dd July 27, 2012 > +.Dd February 8, 2013 > .Dt FCNTL 2 > .Os > .Sh NAME > @@ -171,7 +171,7 @@ > which is rounded up to the nearest block size. > A zero value in > .Fa arg > -turns off read ahead. > +turns off read ahead, a negative value restores the system default. > .It Dv F_RDAHEAD > Equivalent to Darwin counterpart which sets read ahead amount of 128KB > when the third argument, > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" --yUaAwXDrp3vRFP8y Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRGBWhAAoJEJDCuSvBvK1BXpYP/jcWsgG68n10KB2W8aL+SZrc 6Pi4DQSMBTuqUfZ2b1UD2TlB7LHikbeqM6e1LjCbwcDqx9yc1k2PaQnVRGiWxsQl 2x6juHIYraXGaPz8tyAuWorYn/LRc7tyFUph2I+QTIg6mlzzxA3k6BtEZTAWnKbD sDrtRCwG0jAwlSk3JIQ3l1guwBvyXCilNonRLwrlbP1HqTP10rZ/P4rYQTLpnViz dMPHmoLgE+/ezHJPVFadD5Lc/wpw7JuiHwMhFCt+F7wOD6BseJPCGV3HZKgaOmFt bVuF4t8wltOca21mvza1FRJlMxTYVX/aiup2FOnTCkwAGV+QsQLTU1IXlr3/qpJT J7A4xIiwJ+/zI8GYvWuOZLo2ucgMOK7OnloFoRc4GeVEd1xbctrERmKNxV+mufxj ag4p5gFWbO62vIFzj1qAdUe53eYgo3/pLYtHzvwzrGch52NRxmVyIE9QqQ6nNk/u G4NlVQav49LN1z+as7lCEEy46zcNWUSy2PGxEKtuKLl2x5m9PI1QI5NhySKsJxyi 1TxizHWWsiSBi3Q0aC/X0w4dsoTZuDG/t3++YDLwLUAk5sYJptOj2Sn+BVSkYD8w UxU/22OYtyqulHc4zWCY5bEFWo5UOxWe7JTNfaPrv+cvjJsirjfrnLDczBLzPrn3 zoCPvZPwoTiHdZvHexLC =8bc/ -----END PGP SIGNATURE----- --yUaAwXDrp3vRFP8y--