From owner-freebsd-current@FreeBSD.ORG Thu Jan 19 16:39:53 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CA8C51065672 for ; Thu, 19 Jan 2012 16:39:53 +0000 (UTC) (envelope-from tijl@coosemans.org) Received: from mailrelay010.isp.belgacom.be (mailrelay010.isp.belgacom.be [195.238.6.177]) by mx1.freebsd.org (Postfix) with ESMTP id 50CB98FC18 for ; Thu, 19 Jan 2012 16:39:52 +0000 (UTC) X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EABZGGE9bsZjf/2dsb2JhbABErF9/gQaCT4E9iDWZJaAGiTgBATMBBQgFBBEFAQYBAQYBBRAIBwMCBwEBAgEBBQMBAQEBAoJ9C32DHASePokk Received: from 223.152-177-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.177.152.223]) by relay.skynet.be with ESMTP; 19 Jan 2012 17:39:51 +0100 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.14.5/8.14.5) with ESMTP id q0JGdoaO004041 for ; Thu, 19 Jan 2012 17:39:50 +0100 (CET) (envelope-from tijl@coosemans.org) From: Tijl Coosemans To: freebsd-current@freebsd.org Date: Thu, 19 Jan 2012 17:39:42 +0100 User-Agent: KMail/1.13.7 (FreeBSD/10.0-CURRENT; KDE/4.7.3; i386; ; ) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart13824245.QcW69M6GYp"; protocol="application/pgp-signature"; micalg=pgp-sha256 Content-Transfer-Encoding: 7bit Message-Id: <201201191739.48327.tijl@coosemans.org> Subject: posix_fadvise noreuse disables file caching X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Jan 2012 16:39:53 -0000 --nextPart13824245.QcW69M6GYp Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, I recently noticed that multimedia/vlc generates a lot of disk IO when playing media files. For instance, when playing a 320kbps mp3 gstat reports about 1250kBps (=10000kbps). That's quite a lot of overhead. It turns out that vlc sets POSIX_FADV_NOREUSE on the entire file and reads in chunks of 1028 bytes. FreeBSD implements NOREUSE as if O_DIRECT was specified during open(2), i.e. it disables all caching. That means every 1028 byte read turns into a 32KiB read (new default block size in 9.0) which explains the above numbers. I've copied the relevant vlc code below (modules/access/file.c:Open()). It's interesting to see that on OSX it sets F_NOCACHE which disables caching too, but combined with F_RDAHEAD there's still read-ahead caching. I don't think POSIX intended for NOREUSE to mean O_DIRECT. It should still cache data (and even do read-ahead if F_RDAHEAD is specified), and once data is fetched from the cache, it can be marked WONTNEED. Is it possible to implement it this way, or if not to just ignore the NOREUSE hint for now? /* Demuxers will need the beginning of the file for probing. */ posix_fadvise (fd, 0, 4096, POSIX_FADV_WILLNEED); /* In most cases, we only read the file once. */ posix_fadvise (fd, 0, 0, POSIX_FADV_NOREUSE); #if defined(HAVE_FCNTL) /* We'd rather use any available memory for reading ahead * than for caching what we've already seen/heard */ # if defined(F_RDAHEAD) fcntl (fd, F_RDAHEAD, 1); # endif # if defined(F_NOCACHE) fcntl (fd, F_NOCACHE, 1); # endif #endif --nextPart13824245.QcW69M6GYp Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iF4EABEIAAYFAk8YR1QACgkQfoCS2CCgtislqgD+IRA+y6FZeLHaBfz4SP7PTel6 x4WuUYPfepIJW62j6GMA/jA0MTRpJ4UUDlaTd2RmkHcdHDVKkcDd4CWB2F0PeukH =LEb6 -----END PGP SIGNATURE----- --nextPart13824245.QcW69M6GYp--