added volatile read cache option

This commit is contained in:
Arvid Norberg 2010-01-30 03:50:17 +00:00
parent a4ff3cdf87
commit ccf8b0278a
5 changed files with 30 additions and 2 deletions

View File

@ -106,6 +106,7 @@ void bind_session_settings()
.def_readwrite("max_suggest_pieces", &session_settings::max_suggest_pieces) .def_readwrite("max_suggest_pieces", &session_settings::max_suggest_pieces)
.def_readwrite("drop_skipped_requests", &session_settings::drop_skipped_requests) .def_readwrite("drop_skipped_requests", &session_settings::drop_skipped_requests)
.def_readwrite("low_prio_disk", &session_settings::low_prio_disk) .def_readwrite("low_prio_disk", &session_settings::low_prio_disk)
.def_readwrite("volatile_read_cache", &session_settings::volatile_read_cache)
; ;
enum_<proxy_settings::proxy_type>("proxy_type") enum_<proxy_settings::proxy_type>("proxy_type")

View File

@ -3721,6 +3721,7 @@ session_settings
bool drop_skipped_requests; bool drop_skipped_requests;
bool low_prio_disk; bool low_prio_disk;
bool volatile_read_cache;
}; };
``user_agent`` this is the client identification to the tracker. ``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 background. For high-performance server setups, this might not
be desirable. 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 pe_settings
=========== ===========

View File

@ -186,6 +186,7 @@ namespace libtorrent
, max_suggest_pieces(10) , max_suggest_pieces(10)
, drop_skipped_requests(false) , drop_skipped_requests(false)
, low_prio_disk(true) , low_prio_disk(true)
, volatile_read_cache(false)
{} {}
// this is the user agent that will be sent to the tracker // this is the user agent that will be sent to the tracker
@ -683,6 +684,12 @@ namespace libtorrent
// to foreground tasks, while bittorrent runs // to foreground tasks, while bittorrent runs
// in the background // in the background
bool low_prio_disk; 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 #ifndef TORRENT_DISABLE_DHT

View File

@ -711,6 +711,12 @@ namespace libtorrent
{ {
std::memcpy(buf.get() + offset, p.blocks[i].buf, block_size); std::memcpy(buf.get() + offset, p.blocks[i].buf, block_size);
offset += m_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; buffer_size += block_size;
TORRENT_ASSERT(p.num_blocks > 0); TORRENT_ASSERT(p.num_blocks > 0);
@ -1227,11 +1233,17 @@ namespace libtorrent
int to_copy = (std::min)(m_block_size int to_copy = (std::min)(m_block_size
- block_offset, size); - block_offset, size);
std::memcpy(j.buffer + buffer_offset std::memcpy(j.buffer + buffer_offset
, p.blocks[block].buf + block_offset , p.blocks[block].buf + block_offset
, to_copy); , to_copy);
size -= to_copy; size -= to_copy;
block_offset = 0; block_offset = 0;
buffer_offset += to_copy; 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; ++block;
} }
return j.buffer_size; return j.buffer_size;

View File

@ -1021,6 +1021,7 @@ namespace aux {
|| m_settings.use_read_cache != s.use_read_cache || m_settings.use_read_cache != s.use_read_cache
|| m_settings.allow_reordered_disk_operations != s.allow_reordered_disk_operations || m_settings.allow_reordered_disk_operations != s.allow_reordered_disk_operations
|| m_settings.file_pool_size != s.file_pool_size || 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) || m_settings.low_prio_disk != s.low_prio_disk)
update_disk_io_thread = true; update_disk_io_thread = true;