From 00125c972600955205ae24c7a58053ec94b649db Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 25 Jan 2009 23:33:10 +0000 Subject: [PATCH] (trunk libT) add mac, linux, and win32 support for os-level hints that local data will be read in random order, to disable readahead buffering. --- configure.ac | 12 ++++++++++++ libtransmission/fdlimit.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/configure.ac b/configure.ac index 45b443f94..a07ca0b4f 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,18 @@ AC_PATH_ZLIB AC_SYS_LARGEFILE + +dnl ---------------------------------------------------------------------------- +dnl +dnl posix_fadvise + +dnl can posix_fadvise be used +AC_CHECK_DECLS(posix_fadvise, [], [], [ +#define _XOPEN_SOURCE 600 +#include ]) +AC_CHECK_FUNCS([posix_fadvise]) + + dnl ---------------------------------------------------------------------------- dnl dnl va_copy diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index b21eb7737..746ac6864 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -231,6 +231,9 @@ TrOpenFile( int i, /* open the file */ flags = doWrite ? ( O_RDWR | O_CREAT ) : O_RDONLY; +#ifdef O_RANDOM + flags |= O_RANDOM +#endif #ifdef O_LARGEFILE flags |= O_LARGEFILE; #endif @@ -249,6 +252,13 @@ TrOpenFile( int i, if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_SPARSE ) ) preallocateFileSparse( file->fd, desiredFileSize ); +#if defined( SYS_DARWIN ) + fcntl( file->fd, F_NOCACHE, 1 ); + fcntl( file->fd, F_RDAHEAD, 0 ); +#elif defined( HAVE_POSIX_FADVISE ) + posix_fadvise( file->fd, 0, 0, POSIX_FADV_RANDOM ); +#endif + tr_free( filename ); return 0; }