improved read cache memory efficiency

This commit is contained in:
Arvid Norberg 2009-05-23 19:27:27 +00:00
parent e322b318ae
commit ae8488fb91
5 changed files with 16 additions and 0 deletions

View File

@ -1,3 +1,4 @@
* improved read cache memory efficiency
* added another cache flush algorithm to write the largest * added another cache flush algorithm to write the largest
contiguous blocks instead of the least recently used contiguous blocks instead of the least recently used
* introduced a mechanism to be lighter on the disk when checking torrents * introduced a mechanism to be lighter on the disk when checking torrents

View File

@ -3448,6 +3448,8 @@ session_settings
{ lru, largest_contiguous }; { lru, largest_contiguous };
disk_cache_algo_t disk_cache_algorithm; disk_cache_algo_t disk_cache_algorithm;
int read_cache_line_size;
}; };
``user_agent`` this is the client identification to the tracker. ``user_agent`` this is the client identification to the tracker.
@ -3839,6 +3841,10 @@ value. ``session_settings::largest_contiguous`` will flush the largest
sequences of contiguous blocks from the write cache, regarless of the sequences of contiguous blocks from the write cache, regarless of the
piece's last use time. piece's last use time.
``read_cache_line_size`` is the number of blocks to read into the read
cache when a read cache miss occurs. Setting this to 0 is essentially
the same thing as disabling read cache. The number of blocks read
into the read cache is always capped by the piece boundry.
pe_settings pe_settings
=========== ===========

View File

@ -168,6 +168,7 @@ namespace libtorrent
, optimize_hashing_for_speed(true) , optimize_hashing_for_speed(true)
, file_checks_delay_per_block(0) , file_checks_delay_per_block(0)
, disk_cache_algorithm(lru) , disk_cache_algorithm(lru)
, read_cache_line_size(16)
{} {}
// this is the user agent that will be sent to the tracker // this is the user agent that will be sent to the tracker
@ -576,6 +577,10 @@ namespace libtorrent
{ lru, largest_contiguous }; { lru, largest_contiguous };
disk_cache_algo_t disk_cache_algorithm; disk_cache_algo_t disk_cache_algorithm;
// the number of blocks that will be read ahead
// when reading a block into the read cache
int read_cache_line_size;
}; };
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT

View File

@ -720,6 +720,7 @@ namespace libtorrent
int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size;
int end_block = start_block; int end_block = start_block;
int num_read = 0;
for (int i = start_block; i < blocks_in_piece for (int i = start_block; i < blocks_in_piece
&& (in_use() < m_settings.cache_size && (in_use() < m_settings.cache_size
|| (options & ignore_cache_size)); ++i) || (options & ignore_cache_size)); ++i)
@ -736,6 +737,8 @@ namespace libtorrent
++m_cache_stats.cache_size; ++m_cache_stats.cache_size;
++m_cache_stats.read_cache_size; ++m_cache_stats.read_cache_size;
++end_block; ++end_block;
++num_read;
if (num_read >= m_settings.read_cache_line_size) break;
} }
if (end_block == start_block) return -2; if (end_block == start_block) return -2;

View File

@ -641,6 +641,7 @@ namespace aux {
|| m_settings.optimize_hashing_for_speed != s.optimize_hashing_for_speed || m_settings.optimize_hashing_for_speed != s.optimize_hashing_for_speed
|| m_settings.file_checks_delay_per_block != s.file_checks_delay_per_block || m_settings.file_checks_delay_per_block != s.file_checks_delay_per_block
|| m_settings.disk_cache_algorithm != s.disk_cache_algorithm || m_settings.disk_cache_algorithm != s.disk_cache_algorithm
|| m_settings.read_cache_line_size != s.read_cache_line_size
#ifndef TORRENT_DISABLE_MLOCK #ifndef TORRENT_DISABLE_MLOCK
|| m_settings.lock_disk_cache != s.lock_disk_cache || m_settings.lock_disk_cache != s.lock_disk_cache
#endif #endif