added option to lock disk cache in physical memory
This commit is contained in:
parent
7607286f50
commit
5c12db28d2
|
@ -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 max_sparse_regions;
|
||||
|
||||
bool lock_disk_cache;
|
||||
};
|
||||
|
||||
``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
|
||||
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
|
||||
===========
|
||||
|
||||
|
|
|
@ -181,10 +181,14 @@ namespace libtorrent
|
|||
|
||||
void release_memory();
|
||||
|
||||
protected:
|
||||
|
||||
// number of bytes per block. The BitTorrent
|
||||
// protocol defines the block size to 16 KiB.
|
||||
const int m_block_size;
|
||||
|
||||
session_settings m_settings;
|
||||
|
||||
private:
|
||||
|
||||
// this only protects the pool allocator
|
||||
|
@ -307,8 +311,6 @@ namespace libtorrent
|
|||
cache_status m_cache_stats;
|
||||
int m_num_cached_blocks;
|
||||
|
||||
session_settings m_settings;
|
||||
|
||||
#ifdef TORRENT_DISK_STATS
|
||||
std::ofstream m_log;
|
||||
#endif
|
||||
|
|
|
@ -155,6 +155,9 @@ namespace libtorrent
|
|||
, max_sparse_regions(30000)
|
||||
#else
|
||||
, max_sparse_regions(0)
|
||||
#endif
|
||||
#ifndef TORRENT_DISABLE_MLOCK
|
||||
, lock_disk_cache(true)
|
||||
#endif
|
||||
{}
|
||||
|
||||
|
@ -513,6 +516,13 @@ namespace libtorrent
|
|||
// don't use unless you have to, it screws with rarest-first
|
||||
// piece selection, and reduces swarm performance
|
||||
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
|
||||
|
|
|
@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/time.hpp"
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DISABLE_MLOCK
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
disk_buffer_pool::disk_buffer_pool(int block_size)
|
||||
|
@ -79,6 +83,17 @@ namespace libtorrent
|
|||
#else
|
||||
char* ret = (char*)m_pool.ordered_malloc();
|
||||
#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
|
||||
++m_allocations;
|
||||
++m_categories[category];
|
||||
|
@ -101,6 +116,16 @@ namespace libtorrent
|
|||
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
|
||||
m_buf_to_category.erase(buf);
|
||||
#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
|
||||
page_aligned_allocator::free(buf);
|
||||
#else
|
||||
|
@ -116,6 +141,16 @@ namespace libtorrent
|
|||
#else
|
||||
char* ret = (char*)m_pool.ordered_malloc(num_blocks);
|
||||
#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
|
||||
m_allocations += num_blocks;
|
||||
m_categories[category] += num_blocks;
|
||||
|
@ -139,6 +174,16 @@ namespace libtorrent
|
|||
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
|
||||
m_buf_to_category.erase(buf);
|
||||
#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
|
||||
page_aligned_allocator::free(buf);
|
||||
#else
|
||||
|
|
|
@ -589,6 +589,9 @@ namespace aux {
|
|||
bool update_disk_io_thread = false;
|
||||
if (m_settings.cache_size != s.cache_size
|
||||
|| 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)
|
||||
update_disk_io_thread = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue