Changeset 8291


Ignore:
Timestamp:
Apr 26, 2009, 12:51:51 AM (12 years ago)
Author:
charles
Message:

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

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r8198 r8291  
    203203
    204204FILE*
    205 tr_open_file_for_reading( const char * filename, tr_bool sequential )
     205tr_open_file_for_scanning( const char * filename )
    206206{
    207207    int fd;
     
    229229
    230230#ifdef HAVE_POSIX_FADVISE
    231     posix_fadvise( fd, 0, 0, sequential ? POSIX_FADV_SEQUENTIAL : POSIX_FADV_RANDOM );
     231    posix_fadvise( fd, 0, 0, POSIX_FADV_SEQUENTIAL );
    232232#endif
    233233
    234234    return fdopen( fd, "r" );
     235}
     236
     237static void
     238flush_before_closing( int fd )
     239{
     240#if defined(HAVE_POSIX_FADVISE)
     241    posix_fadvise( fd, 0, 0, POSIX_FADV_DONTNEED );
     242#elif defined(SYS_DARWIN)
     243    fcntl( fd, F_NOCACHE, 1 );
     244#endif
     245}
     246
     247void
     248tr_close_file( FILE * fp )
     249{
     250    flush_before_closing( fileno( fp ) );
     251    fclose( fp );
    235252}
    236253
     
    328345    assert( fileIsOpen( o ) );
    329346
     347    flush_before_closing( o->fd );
    330348    close( o->fd );
    331349    o->fd = -1;
  • trunk/libtransmission/fdlimit.h

    r8175 r8291  
    3333                size_t globalPeerLimit );
    3434
    35 FILE* tr_open_file_for_reading( const char * filename, tr_bool sequential );
     35FILE* tr_open_file_for_scanning( const char * filename );
     36
     37void tr_close_file( FILE * fp );
     38
    3639
    3740/**
  • trunk/libtransmission/verify.c

    r8244 r8291  
    7676        {
    7777            char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
    78             fp = tr_open_file_for_reading( filename, TRUE );
     78            fp = tr_open_file_for_scanning( filename );
    7979            /* fprintf( stderr, "opening file #%d (%s) -- %p\n", fileIndex, filename, fp ); */
    8080            tr_free( filename );
     
    130130        {
    131131            /* fprintf( stderr, "closing file\n" ); */
    132             if( fp != NULL ) { fclose( fp ); fp = NULL; }
     132            if( fp != NULL ) { tr_close_file( fp ); fp = NULL; }
    133133            ++fileIndex;
    134134            filePos = 0;
     
    138138    /* cleanup */
    139139    if( fp != NULL )
    140         fclose( fp );
     140        tr_close_file( fp );
    141141    tr_free( buffer );
    142142
Note: See TracChangeset for help on using the changeset viewer.