Changeset 10276


Ignore:
Timestamp:
Feb 23, 2010, 7:20:57 AM (12 years ago)
Author:
charles
Message:

(trunk libT) use jch's suggestion of having a per-session page-aligned memory buffer for general reuse. (http://trac.transmissionbt.com/ticket/2551#comment:5)

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r10273 r10276  
    296296    uint32_t offset = 0;
    297297    tr_bool  success = TRUE;
    298     uint8_t  buffer[MAX_STACK_ARRAY_SIZE];
    299     const size_t buflen = MAX_STACK_ARRAY_SIZE;
     298    uint8_t * buffer = tr_sessionGetBuffer( tor->session );
     299    const size_t buflen = SESSION_BUFFER_SIZE;
    300300    SHA_CTX  sha;
    301301
     
    323323        SHA1_Final( setme, &sha );
    324324
     325    tr_sessionReleaseBuffer( tor->session );
    325326    return success;
    326327}
  • trunk/libtransmission/peer-io.c

    r9973 r10276  
    3333#include "net.h"
    3434#include "peer-io.h"
    35 #include "platform.h" /* MAX_STACK_ARRAY_SIZE */
    3635#include "trevent.h" /* tr_runInEventThread() */
    3736#include "utils.h"
     
    811810        {
    812811            /* FIXME(libevent2): use evbuffer_reserve_space() and evbuffer_commit_space() instead of tmp */
    813             uint8_t tmp[MAX_STACK_ARRAY_SIZE];
     812            void * tmp = tr_sessionGetBuffer( io->session );
     813            const size_t tmplen = SESSION_BUFFER_SIZE;
    814814            const uint8_t * walk = bytes;
    815815            evbuffer_expand( io->outbuf, byteCount );
    816816            while( byteCount > 0 )
    817817            {
    818                 const size_t thisPass = MIN( byteCount, sizeof( tmp ) );
     818                const size_t thisPass = MIN( byteCount, tmplen );
    819819                tr_cryptoEncrypt( io->crypto, thisPass, walk, tmp );
    820820                evbuffer_add( io->outbuf, tmp, thisPass );
     
    822822                byteCount -= thisPass;
    823823            }
     824            tr_sessionReleaseBuffer( io->session );
    824825            break;
    825826        }
     
    882883                size_t            byteCount )
    883884{
    884     uint8_t tmp[MAX_STACK_ARRAY_SIZE];
     885    void * buf = tr_sessionGetBuffer( io->session );
     886    const size_t buflen = SESSION_BUFFER_SIZE;
    885887
    886888    while( byteCount > 0 )
    887889    {
    888         const size_t thisPass = MIN( byteCount, sizeof( tmp ) );
    889         tr_peerIoReadBytes( io, inbuf, tmp, thisPass );
     890        const size_t thisPass = MIN( byteCount, buflen );
     891        tr_peerIoReadBytes( io, inbuf, buf, thisPass );
    890892        byteCount -= thisPass;
    891893    }
     894
     895    tr_sessionReleaseBuffer( io->session );
    892896}
    893897
  • trunk/libtransmission/peer-msgs.c

    r10201 r10276  
    3232#include "peer-mgr.h"
    3333#include "peer-msgs.h"
    34 #include "platform.h" /* MAX_STACK_ARRAY_SIZE */
    3534#include "session.h"
    3635#include "stats.h"
     
    13411340        size_t n = MIN( nLeft, inlen );
    13421341        size_t i = n;
     1342        void * buf = tr_sessionGetBuffer( getSession( msgs ) );
     1343        const size_t buflen = SESSION_BUFFER_SIZE;
    13431344
    13441345        while( i > 0 )
    13451346        {
    1346             uint8_t buf[MAX_STACK_ARRAY_SIZE];
    1347             const size_t thisPass = MIN( i, sizeof( buf ) );
     1347            const size_t thisPass = MIN( i, buflen );
    13481348            tr_peerIoReadBytes( msgs->peer->io, inbuf, buf, thisPass );
    13491349            evbuffer_add( msgs->incoming.block, buf, thisPass );
    13501350            i -= thisPass;
    13511351        }
     1352
     1353        tr_sessionReleaseBuffer( getSession( msgs ) );
     1354        buf = NULL;
    13521355
    13531356        fireClientGotData( msgs, n, TRUE );
  • trunk/libtransmission/platform.h

    r9965 r10276  
    3232 #define MAX_PATH_LENGTH  2048
    3333#endif
    34 
    35 #define MAX_STACK_ARRAY_SIZE 7168
    3634
    3735/**
  • trunk/libtransmission/session.c

    r10229 r10276  
    500500    session->tag = tr_strdup( tag );
    501501    session->magicNumber = SESSION_MAGIC_NUMBER;
     502    session->buffer = tr_valloc( SESSION_BUFFER_SIZE );
    502503    tr_bencInitList( &session->removedTorrents, 0 );
    503504
     
    892893***/
    893894
     895void*
     896tr_sessionGetBuffer( tr_session * session )
     897{
     898    assert( tr_isSession( session ) );
     899    assert( !session->bufferInUse );
     900    assert( tr_amInEventThread( session ) );
     901
     902    session->bufferInUse = TRUE;
     903    return session->buffer;
     904}
     905
     906void
     907tr_sessionReleaseBuffer( tr_session * session )
     908{
     909    assert( tr_isSession( session ) );
     910    assert( session->bufferInUse );
     911    assert( tr_amInEventThread( session ) );
     912
     913    session->bufferInUse = FALSE;
     914}
     915
    894916void
    895917tr_sessionLock( tr_session * session )
     
    15741596        tr_free( session->metainfoLookup );
    15751597    }
     1598    tr_free( session->buffer );
    15761599    tr_free( session->tag );
    15771600    tr_free( session->configDir );
  • trunk/libtransmission/session.h

    r10093 r10276  
    186186    struct tr_bindinfo         * public_ipv4;
    187187    struct tr_bindinfo         * public_ipv6;
     188
     189    /* a page-aligned buffer for use by the libtransmission thread.
     190     * @see SESSION_BUFFER_SIZE */
     191    void * buffer;
     192
     193    tr_bool bufferInUse;
    188194};
    189195
     
    212218enum
    213219{
    214     SESSION_MAGIC_NUMBER = 3845
     220    SESSION_MAGIC_NUMBER = 3845,
     221
     222    /* @see tr_session.buffer */
     223    SESSION_BUFFER_SIZE = (16*1024)
    215224};
     225
     226void* tr_sessionGetBuffer( tr_session * session );
     227
     228void tr_sessionReleaseBuffer( tr_session * session );
    216229
    217230static inline tr_bool tr_isSession( const tr_session * session )
Note: See TracChangeset for help on using the changeset viewer.