Changeset 10798


Ignore:
Timestamp:
Jun 19, 2010, 2:25:11 PM (12 years ago)
Author:
charles
Message:

(trunk) #1521 "memory cache to reduce disk IO" -- commit block-cache-rc1.diff to trunk for the nightlies.

Location:
trunk
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r10783 r10798  
    208208    { 'd', "downlimit",              "Set the max download speed in KiB/s for the current torrent(s) or globally", "d", 1, "<speed>" },
    209209    { 'D', "no-downlimit",           "Disable max download speed for the current torrent(s) or globally", "D", 0, NULL },
     210    { 'e', "cache",                  "Set the maximum size of the session's memory cache (in MiB)", "e", 1, "<size>" },
    210211    { 910, "encryption-required",    "Encrypt all peer connections", "er", 0, NULL },
    211212    { 911, "encryption-preferred",   "Prefer encrypted peer connections", "ep", 0, NULL },
     
    323324        case 'c': /* incomplete-dir */
    324325        case 'C': /* no-incomplete-dir */
     326        case 'e': /* cache */
    325327        case 'm': /* portmap */
    326328        case 'M': /* "no-portmap */
     
    13301332    if( ( tr_bencDictFindDict( top, "arguments", &args ) ) )
    13311333    {
     1334        double d;
    13321335        const char * str;
    13331336        int64_t      i;
    13341337        tr_bool      boolVal;
     1338        char buf[64];
    13351339
    13361340        printf( "VERSION\n" );
     
    13601364        if( tr_bencDictFindStr( args,  TR_PREFS_KEY_ENCRYPTION, &str ) )
    13611365            printf( "  Encryption: %s\n", str );
     1366        if( tr_bencDictFindReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d ) )
     1367            printf( "  Maximum memory cache size: %s\n", strlsize( buf, d*MiB, sizeof( buf ) ) );
    13621368        printf( "\n" );
    13631369
     
    18171823                case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE );
    18181824                          break;
     1825                case 'e': tr_bencDictAddReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, atof(optarg) );
     1826                          break;
    18191827                case 910: tr_bencDictAddStr( args, TR_PREFS_KEY_ENCRYPTION, "required" );
    18201828                          break;
  • trunk/daemon/transmission-remote.1

    r10729 r10798  
    2222.Op Fl c Ar path | Fl C
    2323.Op Fl d Ar number | Fl D
     24.Op Fl e Ar size
    2425.Op Fl er | ep | et
    2526.Op Fl f
     
    125126Disable download speed limits.
    126127If current torrent(s) are selected this operates on them.  Otherwise, it changes the global setting.
     128.It Fl e Fl -cache Ar size
     129Set the session's maximum memory cache size in MiB.  This cache is used to reduce disk IO.
    127130.It Fl er Fl -encryption-required
    128131Encrypt all peer connections.
  • trunk/doc/rpc-spec.txt

    r10638 r10798  
    400400   "blocklist-enabled"           | boolean    true means enabled
    401401   "blocklist-size"              | number     number of rules in the blocklist
     402   "cache-size-MiB"              | number     size (in MiB) of the disk cache
    402403   "config-dir"                  | string     location of transmission's configuration directory
    403404   "download-dir"                | string     default path to download torrents
     
    598599         | 2.00    | yes       | session-get    | new arg "start-added-torrents"
    599600         | 2.00    | yes       | session-get    | new arg "trash-original-torrent-files"
     601         | 2.00    | yes       | session-get    | new arg "cache-size-MiB"
    600602         | 2.00    | yes       | torrent-get    | new arg "isFinished"
  • trunk/gtk/my-valgrind.sh

    r10332 r10798  
    33export G_DEBUG=gc-friendly
    44export GLIBCXX_FORCE_NEW=1
    5 valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=yes ./transmission -p 2>&1 | tee runlog
     5valgrind --tool=cachegrind ./transmission -p -g /tmp/transmission-test/what 2>&1 | tee runlog
     6#valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=yes ./transmission -p -g /tmp/transmission-test/what 2>&1 | tee runlog
  • trunk/libtransmission/Makefile.am

    r10754 r10798  
    2222    bitfield.c \
    2323    blocklist.c \
     24    cache.c \
    2425    clients.c \
    2526    completion.c \
     
    7273    bitset.h \
    7374    blocklist.h \
     75    cache.h \
    7476    clients.h \
    7577    ConvertUTF.h \
  • trunk/libtransmission/inout.c

    r10552 r10798  
    2727
    2828#include "transmission.h"
     29#include "cache.h"
    2930#include "crypto.h"
    3031#include "fdlimit.h"
    3132#include "inout.h"
     33#include "peer-common.h" /* MAX_BLOCK_SIZE */
    3234#include "platform.h"
    3335#include "stats.h"
     
    8486    int             err = 0;
    8587    const tr_bool doWrite = ioMode >= TR_IO_WRITE;
     88
     89if( doWrite )
     90    fprintf( stderr, "in file %s at offset %zu, writing %zu bytes; file length is %zu\n", file->name, (size_t)fileOffset, buflen, (size_t)file->length );
    8691
    8792    assert( fileIndex < info->fileCount );
     
    224229    if( pieceIndex >= tor->info.pieceCount )
    225230        return EINVAL;
    226     if( pieceOffset + buflen > tr_torPieceCountBytes( tor, pieceIndex ) )
    227         return EINVAL;
     231    //if( pieceOffset + buflen > tr_torPieceCountBytes( tor, pieceIndex ) )
     232    //    return EINVAL;
    228233
    229234    tr_ioFindFileLocation( tor, pieceIndex, pieceOffset,
     
    238243        buf += bytesThisPass;
    239244        buflen -= bytesThisPass;
     245//fprintf( stderr, "++fileIndex to %d\n", (int)fileIndex );
    240246        ++fileIndex;
    241247        fileOffset = 0;
     
    296302    uint32_t offset = 0;
    297303    tr_bool  success = TRUE;
    298     uint8_t * buffer = tr_sessionGetBuffer( tor->session );
    299     const size_t buflen = SESSION_BUFFER_SIZE;
     304    const size_t buflen = MAX_BLOCK_SIZE;
     305    uint8_t * buffer = tr_new( uint8_t, buflen );
    300306    SHA_CTX  sha;
    301307
     
    314320    {
    315321        const int len = MIN( bytesLeft, buflen );
    316         success = !tr_ioRead( tor, pieceIndex, offset, len, buffer );
     322        success = !tr_cacheReadBlock( tor->session->cache, tor, pieceIndex, offset, len, buffer );
    317323        if( !success )
    318324            break;
     
    325331        SHA1_Final( setme, &sha );
    326332
    327     tr_sessionReleaseBuffer( tor->session );
     333    tr_free( buffer );
    328334    return success;
    329335}
  • trunk/libtransmission/peer-mgr.c

    r10752 r10798  
    2222#include "bencode.h"
    2323#include "blocklist.h"
     24#include "cache.h"
    2425#include "clients.h"
    2526#include "completion.h"
     
    14991500                        for( fileIndex=0; fileIndex<tor->info.fileCount; ++fileIndex ) {
    15001501                            const tr_file * file = &tor->info.files[fileIndex];
    1501                             if( ( file->firstPiece <= p ) && ( p <= file->lastPiece ) )
    1502                                 if( tr_cpFileIsComplete( &tor->completion, fileIndex ) )
     1502                            if( ( file->firstPiece <= p ) && ( p <= file->lastPiece ) ) {
     1503                                if( tr_cpFileIsComplete( &tor->completion, fileIndex ) ) {
     1504fprintf( stderr, "flushing complete file %d (%s)\n", fileIndex, tor->info.files[fileIndex].name );
     1505                                    tr_cacheFlushFile( tor->session->cache, tor, fileIndex );
    15031506                                    tr_torrentFileCompleted( tor, fileIndex );
     1507                                }
     1508                            }
    15041509                        }
    15051510
  • trunk/libtransmission/peer-msgs.c

    r10737 r10798  
    2323#include "transmission.h"
    2424#include "bencode.h"
     25#include "cache.h"
    2526#include "completion.h"
    2627#include "crypto.h"
    27 #include "inout.h"
    2828#ifdef WIN32
    2929#include "net.h" /* for ECONN */
     
    12121212    {
    12131213        const struct peer_request * req = msgs->peerAskedFor + i;
    1214         tr_ioPrefetch( msgs->torrent, req->index, req->offset, req->length );
     1214        tr_cachePrefetchBlock( getSession(msgs)->cache, msgs->torrent, req->index, req->offset, req->length );
    12151215        ++msgs->prefetchCount;
    12161216    }
     
    16021602    **/
    16031603
    1604     if(( err = tr_ioWrite( tor, req->index, req->offset, req->length, data )))
     1604    if(( err = tr_cacheWriteBlock( getSession(msgs)->cache, tor, req->index, req->offset, req->length, data )))
    16051605        return err;
    16061606
     
    19141914            tr_peerIoWriteUint32( io, out, req.offset );
    19151915
    1916             err = tr_ioRead( msgs->torrent, req.index, req.offset, req.length, EVBUFFER_DATA(out)+EVBUFFER_LENGTH(out) );
     1916            err = tr_cacheReadBlock( getSession(msgs)->cache, msgs->torrent, req.index, req.offset, req.length, EVBUFFER_DATA(out)+EVBUFFER_LENGTH(out) );
    19171917            if( err )
    19181918            {
  • trunk/libtransmission/ptrarray.c

    r10349 r10798  
    103103}
    104104
    105 static void
     105void
    106106tr_ptrArrayErase( tr_ptrArray * t,
    107107                  int           begin,
     
    124124**/
    125125
    126 static int
     126int
    127127tr_ptrArrayLowerBound( const tr_ptrArray *                t,
    128128                       const void *                       ptr,
     
    185185    const int ret = tr_ptrArrayInsert( t, ptr, pos );
    186186
    187     assertSortedAndUnique( t, compare );
     187    //assertSortedAndUnique( t, compare );
    188188    return ret;
    189189}
  • trunk/libtransmission/ptrarray.h

    r10030 r10798  
    6666}
    6767
     68void tr_ptrArrayErase( tr_ptrArray * t, int begin, int end );
     69
     70
    6871
    6972/** @brief Peek at the array pointer and its size, for easy iteration */
     
    101104}
    102105
     106int tr_ptrArrayLowerBound( const tr_ptrArray * array,
     107                           const void * key,
     108                           int compare( const void * arrayItem, const void * key ),
     109                           tr_bool * exact_match );
     110
    103111/** @brief Insert a pointer into the array at the position determined by the sort function
    104112    @return the index of the stored pointer */
  • trunk/libtransmission/rpcimpl.c

    r10638 r10798  
    11851185    assert( idle_data == NULL );
    11861186
     1187    if( tr_bencDictFindReal( args_in, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d ) )
     1188        tr_sessionSetCacheLimit( session, d );
    11871189    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_UP, &i ) )
    11881190        tr_sessionSetAltSpeed( session, TR_UP, i );
     
    13241326    tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime(s) );
    13251327    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
     1328    tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, tr_sessionGetCacheLimit( s ) );
    13261329    tr_bencDictAddInt ( d, "blocklist-size", tr_blocklistGetRuleCount( s ) );
    13271330    tr_bencDictAddStr ( d, "config-dir", tr_sessionGetConfigDir( s ) );
  • trunk/libtransmission/session.c

    r10751 r10798  
    2929#include "bencode.h"
    3030#include "blocklist.h"
     31#include "cache.h"
    3132#include "crypto.h"
    3233#include "fdlimit.h"
     
    5253enum
    5354{
    54     SAVE_INTERVAL_SECS = 120
     55    SAVE_INTERVAL_SECS = 120,
     56
     57    DEFAULT_CACHE_SIZE_MiB = 2 /* 2 MiB */
    5558};
    5659
     
    243246    assert( tr_bencIsDict( d ) );
    244247
    245     tr_bencDictReserve( d, 35 );
     248    tr_bencDictReserve( d, 60 );
    246249    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED,        FALSE );
     250    tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB,       DEFAULT_CACHE_SIZE_MiB );
    247251    tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED,              TRUE );
    248252    tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED,              FALSE );
     
    308312    assert( tr_bencIsDict( d ) );
    309313
    310     tr_bencDictReserve( d, 30 );
     314    tr_bencDictReserve( d, 60 );
    311315    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED,        tr_blocklistIsEnabled( s ) );
     316    tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB,       tr_cacheGetLimit( s->cache ) );
    312317    tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED,              s->isDHTEnabled );
    313318    tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED,              s->isLPDEnabled );
     
    507512    session->bandwidth = tr_bandwidthNew( session, NULL );
    508513    session->lock = tr_lockNew( );
     514    session->cache = tr_cacheNew( DEFAULT_CACHE_SIZE_MiB );
    509515    session->tag = tr_strdup( tag );
    510516    session->magicNumber = SESSION_MAGIC_NUMBER;
     
    672678
    673679    /* misc features */
     680    if( tr_bencDictFindReal( settings, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d ) )
     681        tr_sessionSetCacheLimit( session, d );
    674682    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal ) )
    675683        tr_sessionSetLazyBitfieldEnabled( session, boolVal );
     
    16061614    tr_free( torrents );
    16071615
     1616    tr_cacheFree( session->cache );
     1617    session->cache = NULL;
    16081618    tr_announcerClose( session );
    16091619    tr_statsClose( session );
     
    18331843{
    18341844    return tr_sessionIsLPDEnabled( session );
     1845}
     1846
     1847/***
     1848****
     1849***/
     1850
     1851void
     1852tr_sessionSetCacheLimit( tr_session * session, double maxMiB )
     1853{
     1854    assert( tr_isSession( session ) );
     1855
     1856    tr_cacheSetLimit( session->cache, maxMiB );
     1857}
     1858
     1859double
     1860tr_sessionGetCacheLimit( const tr_session * session )
     1861{
     1862    assert( tr_isSession( session ) );
     1863
     1864    return tr_cacheGetLimit( session->cache );
    18351865}
    18361866
  • trunk/libtransmission/session.h

    r10638 r10798  
    4141struct tr_bandwidth;
    4242struct tr_bindsockets;
     43struct tr_cache;
    4344struct tr_fdInfo;
    4445
     
    150151    struct tr_shared *           shared;
    151152
     153    struct tr_cache *            cache;
     154
    152155    struct tr_lock *             lock;
    153156
  • trunk/libtransmission/torrent.c

    r10774 r10798  
    3030#include "bandwidth.h"
    3131#include "bencode.h"
     32#include "cache.h"
    3233#include "completion.h"
    3334#include "crypto.h" /* for tr_sha1 */
     
    15171518    tr_peerMgrStopTorrent( tor );
    15181519    tr_announcerTorrentStopped( tor );
     1520    tr_cacheFlushTorrent( tor->session->cache, tor );
    15191521
    15201522    tr_fdTorrentClose( tor->session, tor->uniqueId );
  • trunk/libtransmission/transmission.h

    r10697 r10798  
    164164#define TR_PREFS_KEY_BIND_ADDRESS_IPV6             "bind-address-ipv6"
    165165#define TR_PREFS_KEY_BLOCKLIST_ENABLED             "blocklist-enabled"
     166#define TR_PREFS_KEY_MAX_CACHE_SIZE_MiB            "cache-size-MiB"
    166167#define TR_PREFS_KEY_DHT_ENABLED                   "dht-enabled"
    167168#define TR_PREFS_KEY_LPD_ENABLED                   "lpd-enabled"
     
    587588 * In public torrents, PEX is enabled by default.
    588589 */
    589 void tr_sessionSetPexEnabled( tr_session  * session, tr_bool isEnabled );
    590 
    591 tr_bool            tr_sessionIsPexEnabled( const tr_session * session );
    592 
    593 tr_bool            tr_sessionIsDHTEnabled( const tr_session * session );
    594 
    595 void               tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
    596 
    597 tr_bool            tr_sessionIsLPDEnabled( const tr_session * session );
    598 
    599 void               tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled );
    600 
    601 void               tr_sessionSetLazyBitfieldEnabled( tr_session * session,
    602                                                      tr_bool       enabled );
    603 
    604 tr_bool            tr_sessionIsLazyBitfieldEnabled( const tr_session * session );
     590void     tr_sessionSetPexEnabled( tr_session  * session, tr_bool isEnabled );
     591tr_bool  tr_sessionIsPexEnabled( const tr_session * session );
     592
     593tr_bool  tr_sessionIsDHTEnabled( const tr_session * session );
     594void     tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
     595
     596tr_bool  tr_sessionIsLPDEnabled( const tr_session * session );
     597void     tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled );
     598
     599void     tr_sessionSetCacheLimit( tr_session * session, double MiB );
     600double   tr_sessionGetCacheLimit( const tr_session * session );
     601
     602void     tr_sessionSetLazyBitfieldEnabled( tr_session * session, tr_bool enabled );
     603tr_bool  tr_sessionIsLazyBitfieldEnabled( const tr_session * session );
    605604
    606605tr_encryption_mode tr_sessionGetEncryption( tr_session * session );
    607 
    608 void               tr_sessionSetEncryption( tr_session          * session,
     606void               tr_sessionSetEncryption( tr_session * session,
    609607                                            tr_encryption_mode    mode );
    610608
Note: See TracChangeset for help on using the changeset viewer.