From ae8488fb91905fec0291d3edbec6ec1bbdb1a6c9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 23 May 2009 19:27:27 +0000 Subject: [PATCH] improved read cache memory efficiency --- ChangeLog | 1 + docs/manual.rst | 6 ++++++ include/libtorrent/session_settings.hpp | 5 +++++ src/disk_io_thread.cpp | 3 +++ src/session_impl.cpp | 1 + 5 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index 79bb48a0b..536988313 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * improved read cache memory efficiency * added another cache flush algorithm to write the largest contiguous blocks instead of the least recently used * introduced a mechanism to be lighter on the disk when checking torrents diff --git a/docs/manual.rst b/docs/manual.rst index 84561b90d..af5e26ecb 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3448,6 +3448,8 @@ session_settings { lru, largest_contiguous }; disk_cache_algo_t disk_cache_algorithm; + + int read_cache_line_size; }; ``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 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 =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 15c797be3..8e43e2fa8 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -168,6 +168,7 @@ namespace libtorrent , optimize_hashing_for_speed(true) , file_checks_delay_per_block(0) , disk_cache_algorithm(lru) + , read_cache_line_size(16) {} // this is the user agent that will be sent to the tracker @@ -576,6 +577,10 @@ namespace libtorrent { lru, largest_contiguous }; 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 diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 6faf84386..89e0b06c6 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -720,6 +720,7 @@ namespace libtorrent int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; int end_block = start_block; + int num_read = 0; for (int i = start_block; i < blocks_in_piece && (in_use() < m_settings.cache_size || (options & ignore_cache_size)); ++i) @@ -736,6 +737,8 @@ namespace libtorrent ++m_cache_stats.cache_size; ++m_cache_stats.read_cache_size; ++end_block; + ++num_read; + if (num_read >= m_settings.read_cache_line_size) break; } if (end_block == start_block) return -2; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index bb5ba0271..8a37702b0 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -641,6 +641,7 @@ namespace aux { || 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.disk_cache_algorithm != s.disk_cache_algorithm + || m_settings.read_cache_line_size != s.read_cache_line_size #ifndef TORRENT_DISABLE_MLOCK || m_settings.lock_disk_cache != s.lock_disk_cache #endif