From f7129f2f30bca26ae048cd189b5169c19e55e7f9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Aug 2009 20:55:22 +0000 Subject: [PATCH] (trunk libT) #2335: when verifying local data, pause a few msec between pieces to give the system some breathing room and other processes a shot at the disk IO --- libtransmission/verify.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libtransmission/verify.c b/libtransmission/verify.c index 496850733..abdb67d81 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -46,6 +46,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) tr_bool changed = 0; tr_bool hadPiece = 0; uint32_t piecePos = 0; + uint32_t pieceBytesRead = 0; tr_file_index_t fileIndex = 0; tr_piece_index_t pieceIndex = 0; const int64_t buflen = tor->info.pieceSize; @@ -89,6 +90,8 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) /* read a bit */ if( (fd>=0) && tr_lseek( fd, filePos, SEEK_SET ) != -1 ) { const int64_t numRead = read( fd, buffer, bytesThisPass ); + if( numRead > 0 ) + pieceBytesRead += numRead; if( numRead == bytesThisPass ) SHA1_Update( &sha, buffer, numRead ); } @@ -120,9 +123,17 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) tr_torrentSetPieceChecked( tor, pieceIndex, TRUE ); tor->anyDate = time( NULL ); + /* going full-throttle on a verify can choke other processes' + * disk IO, so wait a fwe msec between pieces. + * The msec is arbitrary, and the "if" clause is to make sure we + * don't slow down verification of files that don't exist */ + if( pieceBytesRead == tr_torPieceCountBytes( tor, pieceIndex ) ) + tr_wait( 50 ); + SHA1_Init( &sha ); ++pieceIndex; piecePos = 0; + pieceBytesRead = 0; } /* if we're finishing a file... */