Changeset 7643


Ignore:
Timestamp:
Jan 8, 2009, 7:20:24 PM (12 years ago)
Author:
charles
Message:

(trunk libT) make the default number of open files 32 rather than 16, and make it configurable via settings.json. (Reported by Lucius Windschuh via denis_)

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r7543 r7643  
    3434#include <string.h>
    3535#ifdef SYS_DARWIN
    36 #include <fcntl.h>
     36 #include <fcntl.h>
    3737#endif
    3838
     
    7272enum
    7373{
    74     TR_MAX_OPEN_FILES = 16, /* real files, not sockets */
    75 
    7674    NOFILE_BUFFER = 512, /* the process' number of open files is
    7775                            globalMaxPeers + NOFILE_BUFFER */
     
    9189{
    9290    int                   socketCount;
    93     int                   socketMax;
    94     tr_lock *             lock;
    95     struct tr_openfile    open[TR_MAX_OPEN_FILES];
     91    int                   socketLimit;
     92
     93    struct tr_openfile  * openFiles;
     94    int                   openFileLimit;
     95
     96    tr_lock             * lock;
    9697};
    9798
     
    105106
    106107#ifndef O_LARGEFILE
    107 #define O_LARGEFILE 0
     108 #define O_LARGEFILE 0
    108109#endif
    109110
     
    177178            uint64_t     desiredFileSize )
    178179{
    179     struct tr_openfile * file = &gFd->open[i];
     180    struct tr_openfile * file = &gFd->openFiles[i];
    180181    int                  flags;
    181182    char               * filename;
     
    237238TrCloseFile( int i )
    238239{
    239     struct tr_openfile * o = &gFd->open[i];
     240    struct tr_openfile * o = &gFd->openFiles[i];
    240241
    241242    assert( i >= 0 );
    242     assert( i < TR_MAX_OPEN_FILES );
     243    assert( i < gFd->openFileLimit );
    243244    assert( fileIsOpen( o ) );
    244245
     
    276277
    277278    /* Is it already open? */
    278     for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
    279     {
    280         o = &gFd->open[i];
     279    for( i = 0; i < gFd->openFileLimit; ++i )
     280    {
     281        o = &gFd->openFiles[i];
    281282
    282283        if( !fileIsOpen( o ) )
     
    316317
    317318        /* look for the file that's been open longest */
    318         for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
    319         {
    320             o = &gFd->open[i];
     319        for( i = 0; i < gFd->openFileLimit; ++i )
     320        {
     321            o = &gFd->openFiles[i];
    321322
    322323            if( !fileIsOpen( o ) )
     
    336337        if( winner >= 0 )
    337338        {
    338             if( fileIsOpen( &gFd->open[winner] ) )
     339            if( fileIsOpen( &gFd->openFiles[winner] ) )
    339340            {
    340341                dbgmsg( "closing file '%s', slot #%d",
    341                         gFd->open[winner].filename,
     342                        gFd->openFiles[winner].filename,
    342343                        winner );
    343344                TrCloseFile( winner );
     
    355356
    356357    assert( winner >= 0 );
    357     o = &gFd->open[winner];
     358    o = &gFd->openFiles[winner];
    358359    if( !fileIsOpen( o ) )
    359360    {
     
    386387    tr_lockLock( gFd->lock );
    387388
    388     for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
    389     {
    390         struct tr_openfile * o = &gFd->open[i];
     389    for( i = 0; i < gFd->openFileLimit; ++i )
     390    {
     391        struct tr_openfile * o = &gFd->openFiles[i];
    391392        if( o->fd != fd )
    392393            continue;
     
    410411    tr_lockLock( gFd->lock );
    411412
    412     for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
    413     {
    414         struct tr_openfile * o = &gFd->open[i];
     413    for( i = 0; i < gFd->openFileLimit; ++i )
     414    {
     415        struct tr_openfile * o = &gFd->openFiles[i];
    415416        if( !fileIsOpen( o ) || strcmp( filename, o->filename ) )
    416417            continue;
     
    427428            dbgmsg(
    428429                "flagging file '%s', slot #%d to be closed when checked in",
    429                 gFd->open[i].filename, i );
     430                gFd->openFiles[i].filename, i );
    430431            o->closeWhenDone = 1;
    431432        }
     
    444445getSocketMax( struct tr_fd_s * gFd )
    445446{
    446     return gFd->socketMax;
     447    return gFd->socketLimit;
    447448}
    448449
     
    546547
    547548void
    548 tr_fdInit( int globalPeerLimit )
     549tr_fdInit( size_t openFileLimit, size_t socketLimit )
    549550{
    550551    int i;
     
    552553    assert( gFd == NULL );
    553554    gFd = tr_new0( struct tr_fd_s, 1 );
     555    gFd->openFiles = tr_new0( struct tr_openfile, openFileLimit );
     556    gFd->openFileLimit = openFileLimit;
    554557    gFd->lock = tr_lockNew( );
    555558
     
    559562        getrlimit( RLIMIT_NOFILE, &rlim );
    560563        rlim.rlim_cur = MIN( rlim.rlim_max,
    561                             (rlim_t)( globalPeerLimit + NOFILE_BUFFER ) );
     564                            (rlim_t)( socketLimit + NOFILE_BUFFER ) );
    562565        setrlimit( RLIMIT_NOFILE, &rlim );
    563         gFd->socketMax = rlim.rlim_cur - NOFILE_BUFFER;
     566        gFd->socketLimit = rlim.rlim_cur - NOFILE_BUFFER;
    564567        tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", (int)rlim.rlim_cur );
    565568    }
    566569#else
    567     gFd->socketMax = globalPeerLimit;
    568 #endif
    569     tr_dbg( "%d usable file descriptors", globalPeerLimit );
    570 
    571     for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
    572         gFd->open[i].fd = -1;
     570    gFd->socketLimit = socketLimit;
     571#endif
     572    tr_dbg( "%zu usable file descriptors", socketLimit );
     573
     574    for( i = 0; i < gFd->openFileLimit; ++i )
     575        gFd->openFiles[i].fd = -1;
    573576}
    574577
     
    578581    int i = 0;
    579582
    580     for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
    581         if( fileIsOpen( &gFd->open[i] ) )
     583    for( i = 0; i < gFd->openFileLimit; ++i )
     584        if( fileIsOpen( &gFd->openFiles[i] ) )
    582585            TrCloseFile( i );
    583586
     
    592595{
    593596    assert( gFd != NULL && "tr_fdInit() must be called first!" );
    594     gFd->socketMax = n;
     597    gFd->socketLimit = n;
    595598}
    596599
     
    598601tr_fdGetPeerLimit( void )
    599602{
    600     return gFd ? gFd->socketMax : -1;
    601 }
    602 
     603    return gFd ? gFd->socketLimit : -1;
     604}
     605
  • trunk/libtransmission/fdlimit.h

    r7608 r7643  
    2929#include "net.h"
    3030
    31 /***********************************************************************
    32  * tr_fdInit
    33  ***********************************************************************
    34  * Detect the maximum number of open files and initializes things.
    35  **********************************************************************/
    36 void tr_fdInit( int globalPeerLimit );
     31void tr_fdInit( size_t openFileLimit,
     32                size_t globalPeerLimit );
    3733
    3834/**
  • trunk/libtransmission/session.c

    r7618 r7643  
    228228    tr_bencDictAddInt( d, TR_PREFS_KEY_LAZY_BITFIELD,            TRUE );
    229229    tr_bencDictAddInt( d, TR_PREFS_KEY_MSGLEVEL,                 TR_MSG_INF );
     230    tr_bencDictAddInt( d, TR_PREFS_KEY_OPEN_FILE_LIMIT,          atoi( TR_DEFAULT_OPEN_FILE_LIMIT_STR ) );
    230231    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL,        atoi( TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ) );
    231232    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT,       atoi( TR_DEFAULT_PEER_LIMIT_TORRENT_STR ) );
     
    271272    tr_bencDictAddInt( d, TR_PREFS_KEY_LAZY_BITFIELD,            s->useLazyBitfield );
    272273    tr_bencDictAddInt( d, TR_PREFS_KEY_MSGLEVEL,                 tr_getMessageLevel( ) );
     274    tr_bencDictAddInt( d, TR_PREFS_KEY_OPEN_FILE_LIMIT,          s->openFileLimit );
    273275    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL,        tr_sessionGetPeerLimit( s ) );
    274276    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT,       s->peerLimitPerTorrent );
     
    459461    /* Initialize rate and file descripts controls */
    460462
    461     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i );
    462     assert( found );
    463     tr_fdInit( i );
     463    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_OPEN_FILE_LIMIT, &i );
     464    assert( found );
     465    session->openFileLimit = i;
     466    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &j );
     467    assert( found );
     468    tr_fdInit( session->openFileLimit, j );
    464469
    465470    /**
  • trunk/libtransmission/session.h

    r7468 r7643  
    7575
    7676    uint16_t                     peerLimitPerTorrent;
     77    uint16_t                     openFileLimit;
    7778
    7879    tr_port                      peerPort;
  • trunk/libtransmission/transmission.h

    r7580 r7643  
    115115tr_encryption_mode;
    116116
     117#define TR_DEFAULT_OPEN_FILE_LIMIT_STR "32"
    117118#define TR_DEFAULT_RPC_WHITELIST "127.0.0.1"
    118119#define TR_DEFAULT_RPC_PORT_STR "9091"
     
    129130#define TR_PREFS_KEY_LAZY_BITFIELD              "lazy-bitfield-enabled"
    130131#define TR_PREFS_KEY_MSGLEVEL                   "message-level"
     132#define TR_PREFS_KEY_OPEN_FILE_LIMIT            "open-file-limit"
    131133#define TR_PREFS_KEY_PEER_LIMIT_GLOBAL          "peer-limit-global"
    132134#define TR_PREFS_KEY_PEER_LIMIT_TORRENT         "peer-limit-per-torrent"
Note: See TracChangeset for help on using the changeset viewer.