set MAP_NOCACHE if we can

Set the MAP_NOCACHE flags in mmap() if we can. On OS X this stops the
mad super-aggressive disc caching and produces a huge improveemnt in
performance.
This commit is contained in:
John Cupitt 2011-02-02 21:56:40 +00:00
parent aca238dfca
commit 729b680841
3 changed files with 16 additions and 2 deletions

View File

@ -28,6 +28,8 @@
- move im_stretch3() to deprecated
- move im_clamp() to deprecated
- gtk-doc for video ... all operators done! amazing argh
- set MAP_NOCACHE on OS X, otherwise performance dives off a cliff with
files larger than memory
30/11/10 started 7.24.0
- bump for new stable

5
TODO
View File

@ -1,7 +1,8 @@
- does OS X have any mmap flags which could stop their crazy caching?
- use g_mmap() or whatever it's called ... or perhaps they don't have all
these options
- use g_mmap() or whatever it's called
- use |_O_TEMPORARY to open()'s mode on Windows for tmpfiles to increase the

View File

@ -163,12 +163,23 @@ im__mmap( int fd, int writeable, size_t length, gint64 offset )
#else /*!OS_WIN32*/
{
int prot;
int flags;
if( writeable )
prot = PROT_WRITE;
else
prot = PROT_READ;
flags = MAP_SHARED;
/* OS X caches mmapped files very aggressively if this flags is not
* set. Scanning a large file without this flag will cause every other
* process to get swapped out and kill performance.
*/
#ifdef MAP_NOCACHE
flags |= MAP_NOCACHE;
#endif /*MAP_NOCACHE*/
/* Casting gint64 to off_t should be safe, even on *nixes without
* LARGEFILE.
*/