Ticket #2551: prefetch.2.patch

File prefetch.2.patch, 2.9 KB (added by jch, 11 years ago)
  • libtransmission/peer-msgs.c

    diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c
    index 087ea6b..a8fef31 100644
    a b updatePeerProgress( tr_peermsgs * msgs ) 
    12741274}
    12751275
    12761276static void
     1277prefetchPieces( tr_peermsgs *msgs )
     1278{
     1279    int i;
     1280    off_t next = -1;
     1281
     1282    /* Maintain at least 8 prefetched blocks per unchoked peer, but allow
     1283       up to 4 extra blocks if that would cause sequential writes. */
     1284    for(i = msgs->peerAskedFor.prefetched; i < msgs->peerAskedFor.len; i++) {
     1285        struct peer_request *req = &msgs->peerAskedFor.fifo[i];
     1286        if(i >= 8 && (i >= 12 || next < 0 || req->offset + req->length != next))
     1287            break;
     1288        tr_ioPrefetch( msgs->torrent,  req->index, req->offset, req->length );
     1289        msgs->peerAskedFor.prefetched++;
     1290        next = req->offset + req->length;
     1291    }
     1292}
     1293
     1294static void
    12771295peerMadeRequest( tr_peermsgs *               msgs,
    12781296                 const struct peer_request * req )
    12791297{
    peerMadeRequest( tr_peermsgs * msgs, 
    12931311    else
    12941312        allow = TRUE;
    12951313
    1296     if( allow )
     1314    if( allow ) {
    12971315        reqListAppend( &msgs->peerAskedFor, req );
    1298     else if( fext )
     1316        prefetchPieces( msgs );
     1317    } else if( fext )
    12991318        protocolSendReject( msgs, req );
    13001319}
    13011320
    fillOutputBuffer( tr_peermsgs * msgs, time_t now ) 
    18281847                bytesWritten = 0;
    18291848                msgs = NULL;
    18301849            }
     1850            prefetchPieces( msgs );
    18311851        }
    18321852        else if( fext ) /* peer needs a reject message */
    18331853        {
  • libtransmission/request-list.c

    diff --git a/libtransmission/request-list.c b/libtransmission/request-list.c
    index 8276b99..d2608be 100644
    a b compareRequests( const struct peer_request * a, 
    2828    return 0;
    2929}
    3030
    31 const struct request_list REQUEST_LIST_INIT = { 0, 0, NULL, NULL };
     31const struct request_list REQUEST_LIST_INIT = { 0, 0, NULL, NULL, 0 };
    3232
    3333static const int GROW = 8;
    3434
    reqListPop( struct request_list * list, 
    125125        reqListRemoveNthFromFifo( list, 0 );
    126126        reqListRemoveFromSorted( list, setme );
    127127        --list->len;
     128        if(list->prefetched > 0)
     129            --list->prefetched;
    128130        success = TRUE;
    129131    }
    130132
    reqListRemove( struct request_list * list, 
    155157        assert( i < list->len );
    156158        reqListRemoveNthFromFifo( list, i );
    157159        --list->len;
     160        if( i < list->prefetched )
     161            --list->prefetched;
    158162    }
    159163
    160164    return found;
  • libtransmission/request-list.h

    diff --git a/libtransmission/request-list.h b/libtransmission/request-list.h
    index 8f9854a..51fecac 100644
    a b struct request_list 
    3333    size_t                 max;
    3434    struct peer_request  * fifo;
    3535    struct peer_request  * sort;
     36    int prefetched;
    3637};
    3738
    3839extern const struct request_list REQUEST_LIST_INIT;