Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Feb 2013 23:48:18 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Ian Lepore <ian@FreeBSD.org>
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@FreeBSD.org>
Subject:   Re: fcntl(2) F_READAHEAD set to zero doesn't work [patch]
Message-ID:  <20130210214818.GU2522@kib.kiev.ua>
In-Reply-To: <1360367889.4545.58.camel@revolution.hippie.lan>
References:  <1360367889.4545.58.camel@revolution.hippie.lan>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130210214818.GU2522>