Ticket #2551: prefetch-forgotten.patch

File prefetch-forgotten.patch, 2.4 KB (added by jch, 11 years ago)

You forgot to prefetch when receiving a request, Charles

  • libtransmission/peer-msgs.c

    diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c
    index b43397f..7233f63 100644
    a b updatePeerProgress( tr_peermsgs * msgs ) 
    11131113}
    11141114
    11151115static void
     1116prefetchPieces( tr_peermsgs *msgs )
     1117{
     1118    int i;
     1119    uint64_t next = 0;
     1120
     1121    /* Maintain at least 8 prefetched blocks per unchoked peer, but allow
     1122       up to 4 extra blocks if that would cause sequential writes. */
     1123    for( i=msgs->prefetchCount; i<msgs->peerAskedForCount; ++i )
     1124    {
     1125        const struct peer_request * req = msgs->peerAskedFor + i;
     1126        const uint64_t begin = tr_pieceOffset( msgs->torrent, req->index, req->offset, 0 );
     1127        const uint64_t end = begin + req->length;
     1128        const tr_bool isSequential = next == begin;
     1129
     1130        if( ( i >= 12 ) || ( !isSequential && ( i >= 8 ) ) )
     1131            break;
     1132
     1133        tr_ioPrefetch( msgs->torrent, req->index, req->offset, req->length );
     1134        ++msgs->prefetchCount;
     1135
     1136        next = end;
     1137    }
     1138}
     1139
     1140static void
    11161141peerMadeRequest( tr_peermsgs *               msgs,
    11171142                 const struct peer_request * req )
    11181143{
    peerMadeRequest( tr_peermsgs * msgs, 
    11341159    else
    11351160        allow = TRUE;
    11361161
    1137     if( allow )
     1162    if( allow ) {
    11381163        msgs->peerAskedFor[msgs->peerAskedForCount++] = *req;
    1139     else if( fext )
     1164        prefetchPieces( msgs );         
     1165    } else if( fext )
    11401166        protocolSendReject( msgs, req );
    11411167}
    11421168
    updateRequests( tr_peermsgs * msgs ) 
    16331659    }
    16341660}
    16351661
    1636 static void
    1637 prefetchPieces( tr_peermsgs *msgs )
    1638 {
    1639     int i;
    1640     uint64_t next = 0;
    1641 
    1642     /* Maintain at least 8 prefetched blocks per unchoked peer, but allow
    1643        up to 4 extra blocks if that would cause sequential writes. */
    1644     for( i=msgs->prefetchCount; i<msgs->peerAskedForCount; ++i )
    1645     {
    1646         const struct peer_request * req = msgs->peerAskedFor + i;
    1647         const uint64_t begin = tr_pieceOffset( msgs->torrent, req->index, req->offset, 0 );
    1648         const uint64_t end = begin + req->length;
    1649         const tr_bool isSequential = next == begin;
    1650 
    1651         if( ( i >= 12 ) || ( !isSequential && ( i >= 8 ) ) )
    1652             break;
    1653 
    1654         tr_ioPrefetch( msgs->torrent, req->index, req->offset, req->length );
    1655         ++msgs->prefetchCount;
    1656 
    1657         next = end;
    1658     }
    1659 }
    1660 
    16611662static size_t
    16621663fillOutputBuffer( tr_peermsgs * msgs, time_t now )
    16631664{