mirror of
https://github.com/transmission/transmission
synced 2025-02-03 21:12:05 +00:00
(trunk libT) need feedback from Mac users on this change. On Linux, it gets rid of the inactive-memory-grows-during-torrent-verification behavior that's often reported as a bug.
This commit is contained in:
parent
4bccf4985f
commit
d99438bd1c
3 changed files with 27 additions and 6 deletions
|
@ -202,7 +202,7 @@ preallocateFileFull( const char * filename, uint64_t length )
|
|||
}
|
||||
|
||||
FILE*
|
||||
tr_open_file_for_reading( const char * filename, tr_bool sequential )
|
||||
tr_open_file_for_scanning( const char * filename )
|
||||
{
|
||||
int fd;
|
||||
int flags;
|
||||
|
@ -228,12 +228,29 @@ tr_open_file_for_reading( const char * filename, tr_bool sequential )
|
|||
return NULL;
|
||||
|
||||
#ifdef HAVE_POSIX_FADVISE
|
||||
posix_fadvise( fd, 0, 0, sequential ? POSIX_FADV_SEQUENTIAL : POSIX_FADV_RANDOM );
|
||||
posix_fadvise( fd, 0, 0, POSIX_FADV_SEQUENTIAL );
|
||||
#endif
|
||||
|
||||
return fdopen( fd, "r" );
|
||||
}
|
||||
|
||||
static void
|
||||
flush_before_closing( int fd )
|
||||
{
|
||||
#if defined(HAVE_POSIX_FADVISE)
|
||||
posix_fadvise( fd, 0, 0, POSIX_FADV_DONTNEED );
|
||||
#elif defined(SYS_DARWIN)
|
||||
fcntl( fd, F_NOCACHE, 1 );
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
tr_close_file( FILE * fp )
|
||||
{
|
||||
flush_before_closing( fileno( fp ) );
|
||||
fclose( fp );
|
||||
}
|
||||
|
||||
/**
|
||||
* returns 0 on success, or an errno value on failure.
|
||||
* errno values include ENOENT if the parent folder doesn't exist,
|
||||
|
@ -327,6 +344,7 @@ TrCloseFile( int i )
|
|||
assert( i < gFd->openFileLimit );
|
||||
assert( fileIsOpen( o ) );
|
||||
|
||||
flush_before_closing( o->fd );
|
||||
close( o->fd );
|
||||
o->fd = -1;
|
||||
o->isCheckedOut = 0;
|
||||
|
|
|
@ -32,7 +32,10 @@
|
|||
void tr_fdInit( size_t openFileLimit,
|
||||
size_t globalPeerLimit );
|
||||
|
||||
FILE* tr_open_file_for_reading( const char * filename, tr_bool sequential );
|
||||
FILE* tr_open_file_for_scanning( const char * filename );
|
||||
|
||||
void tr_close_file( FILE * fp );
|
||||
|
||||
|
||||
/**
|
||||
* Returns an fd to the specified filename.
|
||||
|
|
|
@ -75,7 +75,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
|
|||
if( !filePos && !fp )
|
||||
{
|
||||
char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
|
||||
fp = tr_open_file_for_reading( filename, TRUE );
|
||||
fp = tr_open_file_for_scanning( filename );
|
||||
/* fprintf( stderr, "opening file #%d (%s) -- %p\n", fileIndex, filename, fp ); */
|
||||
tr_free( filename );
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
|
|||
if( leftInFile == 0 )
|
||||
{
|
||||
/* fprintf( stderr, "closing file\n" ); */
|
||||
if( fp != NULL ) { fclose( fp ); fp = NULL; }
|
||||
if( fp != NULL ) { tr_close_file( fp ); fp = NULL; }
|
||||
++fileIndex;
|
||||
filePos = 0;
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
|
|||
|
||||
/* cleanup */
|
||||
if( fp != NULL )
|
||||
fclose( fp );
|
||||
tr_close_file( fp );
|
||||
tr_free( buffer );
|
||||
|
||||
#ifdef STOPWATCH
|
||||
|
|
Loading…
Reference in a new issue