diff --git a/bindings/python/src/session_settings.cpp b/bindings/python/src/session_settings.cpp index 677b0ae24..ddb020bc2 100644 --- a/bindings/python/src/session_settings.cpp +++ b/bindings/python/src/session_settings.cpp @@ -106,6 +106,7 @@ void bind_session_settings() .def_readwrite("max_suggest_pieces", &session_settings::max_suggest_pieces) .def_readwrite("drop_skipped_requests", &session_settings::drop_skipped_requests) .def_readwrite("low_prio_disk", &session_settings::low_prio_disk) + .def_readwrite("volatile_read_cache", &session_settings::volatile_read_cache) ; enum_("proxy_type") diff --git a/docs/manual.rst b/docs/manual.rst index 8a0c60f7a..a49968479 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3721,6 +3721,7 @@ session_settings bool drop_skipped_requests; bool low_prio_disk; + bool volatile_read_cache; }; ``user_agent`` this is the client identification to the tracker. @@ -4191,6 +4192,12 @@ overall responsiveness of the system while downloading in the background. For high-performance server setups, this might not be desirable. +``volatile_read_cache``, if this is set to true, read cache blocks +that are hit by peer read requests are removed from the disk cache +to free up more space. This is useful if you don't expect the disk +cache to create any cache hits from other peers than the one who +triggered the cache line to be read into the cache in the first place. + pe_settings =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index ead0fe48e..547381b85 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -186,6 +186,7 @@ namespace libtorrent , max_suggest_pieces(10) , drop_skipped_requests(false) , low_prio_disk(true) + , volatile_read_cache(false) {} // this is the user agent that will be sent to the tracker @@ -683,6 +684,12 @@ namespace libtorrent // to foreground tasks, while bittorrent runs // in the background bool low_prio_disk; + + // if this is set to true, any block read from the + // disk cache will be dropped from the cache immediately + // following. This may be useful if the block is not + // expected to be hit again. It would save some memory + bool volatile_read_cache; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 236ef3b26..f9b100c13 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -711,6 +711,12 @@ namespace libtorrent { std::memcpy(buf.get() + offset, p.blocks[i].buf, block_size); offset += m_block_size; + if (m_settings.volatile_read_cache) + { + free_buffer(p.blocks[i].buf); + p.blocks[i].buf = 0; + --p.num_blocks; + } } buffer_size += block_size; TORRENT_ASSERT(p.num_blocks > 0); @@ -1227,11 +1233,17 @@ namespace libtorrent int to_copy = (std::min)(m_block_size - block_offset, size); std::memcpy(j.buffer + buffer_offset - , p.blocks[block].buf + block_offset - , to_copy); + , p.blocks[block].buf + block_offset + , to_copy); size -= to_copy; block_offset = 0; buffer_offset += to_copy; + if (m_settings.volatile_read_cache) + { + free_buffer(p.blocks[block].buf); + p.blocks[block].buf = 0; + --p.num_blocks; + } ++block; } return j.buffer_size; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 7f68da4e2..4a6c2d0c0 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1021,6 +1021,7 @@ namespace aux { || m_settings.use_read_cache != s.use_read_cache || m_settings.allow_reordered_disk_operations != s.allow_reordered_disk_operations || m_settings.file_pool_size != s.file_pool_size + || m_settings.volatile_read_cache != s.volatile_read_cache || m_settings.low_prio_disk != s.low_prio_disk) update_disk_io_thread = true;