added option to lock disk cache in physical memory

This commit is contained in:
Arvid Norberg 2009-02-06 09:46:13 +00:00
parent 7607286f50
commit 5c12db28d2
5 changed files with 68 additions and 2 deletions

View File

@ -3253,6 +3253,8 @@ that will be sent to the tracker. The user-agent is a good way to identify your
int seeding_piece_quota; int seeding_piece_quota;
int max_sparse_regions; int max_sparse_regions;
bool lock_disk_cache;
}; };
``user_agent`` this is the client identification to the tracker. ``user_agent`` this is the client identification to the tracker.
@ -3584,6 +3586,10 @@ that will maintain or decrease the number of sparse regions are
prioritized. To disable this functionality, set this to 0. It defaults prioritized. To disable this functionality, set this to 0. It defaults
to 0 on all platforms except windows. to 0 on all platforms except windows.
``lock_disk_cache`` if lock disk cache is set to true the disk cache
that's in use, will be locked in physical memory, preventing it from
being swapped out.
pe_settings pe_settings
=========== ===========

View File

@ -181,10 +181,14 @@ namespace libtorrent
void release_memory(); void release_memory();
protected:
// number of bytes per block. The BitTorrent // number of bytes per block. The BitTorrent
// protocol defines the block size to 16 KiB. // protocol defines the block size to 16 KiB.
const int m_block_size; const int m_block_size;
session_settings m_settings;
private: private:
// this only protects the pool allocator // this only protects the pool allocator
@ -307,8 +311,6 @@ namespace libtorrent
cache_status m_cache_stats; cache_status m_cache_stats;
int m_num_cached_blocks; int m_num_cached_blocks;
session_settings m_settings;
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
std::ofstream m_log; std::ofstream m_log;
#endif #endif

View File

@ -155,6 +155,9 @@ namespace libtorrent
, max_sparse_regions(30000) , max_sparse_regions(30000)
#else #else
, max_sparse_regions(0) , max_sparse_regions(0)
#endif
#ifndef TORRENT_DISABLE_MLOCK
, lock_disk_cache(true)
#endif #endif
{} {}
@ -513,6 +516,13 @@ namespace libtorrent
// don't use unless you have to, it screws with rarest-first // don't use unless you have to, it screws with rarest-first
// piece selection, and reduces swarm performance // piece selection, and reduces swarm performance
int max_sparse_regions; int max_sparse_regions;
#ifndef TORRENT_DISABLE_MLOCK
// if this is set to true, the memory allocated for the
// disk cache will be locked in physical RAM, never to
// be swapped out
bool lock_disk_cache;
#endif
}; };
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT

View File

@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp" #include "libtorrent/time.hpp"
#endif #endif
#ifndef TORRENT_DISABLE_MLOCK
#include <sys/mman.h>
#endif
namespace libtorrent namespace libtorrent
{ {
disk_buffer_pool::disk_buffer_pool(int block_size) disk_buffer_pool::disk_buffer_pool(int block_size)
@ -79,6 +83,17 @@ namespace libtorrent
#else #else
char* ret = (char*)m_pool.ordered_malloc(); char* ret = (char*)m_pool.ordered_malloc();
#endif #endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualLock(ret, m_block_size);
#else
mlock(ret, m_block_size);
#endif
}
#endif
#ifdef TORRENT_STATS #ifdef TORRENT_STATS
++m_allocations; ++m_allocations;
++m_categories[category]; ++m_categories[category];
@ -101,6 +116,16 @@ namespace libtorrent
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n"; m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
m_buf_to_category.erase(buf); m_buf_to_category.erase(buf);
#endif #endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualUnlock(buf, m_block_size);
#else
munlock(buf, m_block_size);
#endif
}
#endif
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR #ifdef TORRENT_DISABLE_POOL_ALLOCATOR
page_aligned_allocator::free(buf); page_aligned_allocator::free(buf);
#else #else
@ -116,6 +141,16 @@ namespace libtorrent
#else #else
char* ret = (char*)m_pool.ordered_malloc(num_blocks); char* ret = (char*)m_pool.ordered_malloc(num_blocks);
#endif #endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualLock(ret, m_block_size * num_blocks);
#else
mlock(ret, m_block_size * num_blocks);
#endif
}
#endif
#ifdef TORRENT_STATS #ifdef TORRENT_STATS
m_allocations += num_blocks; m_allocations += num_blocks;
m_categories[category] += num_blocks; m_categories[category] += num_blocks;
@ -139,6 +174,16 @@ namespace libtorrent
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n"; m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
m_buf_to_category.erase(buf); m_buf_to_category.erase(buf);
#endif #endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualUnlock(buf, m_block_size * num_blocks);
#else
munlock(buf, m_block_size * num_blocks);
#endif
}
#endif
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR #ifdef TORRENT_DISABLE_POOL_ALLOCATOR
page_aligned_allocator::free(buf); page_aligned_allocator::free(buf);
#else #else

View File

@ -589,6 +589,9 @@ namespace aux {
bool update_disk_io_thread = false; bool update_disk_io_thread = false;
if (m_settings.cache_size != s.cache_size if (m_settings.cache_size != s.cache_size
|| m_settings.cache_expiry != s.cache_expiry || m_settings.cache_expiry != s.cache_expiry
#ifndef TORRENT_DISABLE_MLOCK
|| m_settings.lock_disk_cache != s.lock_disk_cache
#endif
|| m_settings.use_read_cache != s.use_read_cache) || m_settings.use_read_cache != s.use_read_cache)
update_disk_io_thread = true; update_disk_io_thread = true;