make disk cache pool allocator configurable
This commit is contained in:
parent
74b7d676bc
commit
372dd935f1
|
@ -1,3 +1,4 @@
|
||||||
|
* make disk cache pool allocator configurable
|
||||||
* fix library ABI to not depend on logging being enabled
|
* fix library ABI to not depend on logging being enabled
|
||||||
* use hex encoding instead of base32 in create_magnet_uri
|
* use hex encoding instead of base32 in create_magnet_uri
|
||||||
* include name, save_path and torrent_file in torrent_status, for improved performance
|
* include name, save_path and torrent_file in torrent_status, for improved performance
|
||||||
|
|
|
@ -4654,6 +4654,12 @@ session_settings
|
||||||
|
|
||||||
bool ban_web_seeds;
|
bool ban_web_seeds;
|
||||||
int max_http_recv_buffer_size;
|
int max_http_recv_buffer_size;
|
||||||
|
|
||||||
|
bool support_share_mode;
|
||||||
|
bool support_merkle_torrents;
|
||||||
|
bool report_redundant_bytes;
|
||||||
|
std::string handshake_client_version;
|
||||||
|
bool use_disk_cache_pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
``version`` is automatically set to the libtorrent version you're using
|
``version`` is automatically set to the libtorrent version you're using
|
||||||
|
@ -5556,6 +5562,23 @@ RAM buffers when downloading stuff over HTTP. Specifically when specifying a
|
||||||
URL to a .torrent file when adding a torrent or when announcing to an HTTP
|
URL to a .torrent file when adding a torrent or when announcing to an HTTP
|
||||||
tracker. The default is 2 MiB.
|
tracker. The default is 2 MiB.
|
||||||
|
|
||||||
|
``support_share_mode`` enables or disables the share mode extension. This is
|
||||||
|
enabled by default.
|
||||||
|
|
||||||
|
``support_merkle_torrents`` enables or disables the merkle tree torrent support.
|
||||||
|
This is enabled by default.
|
||||||
|
|
||||||
|
``report_redundant_bytes`` enables or disables reporting redundant bytes to the tracker.
|
||||||
|
This is enabled by default.
|
||||||
|
|
||||||
|
``handshake_client_version`` is the client name advertized in the peer handshake. If
|
||||||
|
set to an empty string, the user_agent string is used.
|
||||||
|
|
||||||
|
``use_disk_cache_pool`` enables using a pool allocator for disk cache blocks. This is
|
||||||
|
disabled by default. Enabling it makes the cache perform better at high throughput.
|
||||||
|
It also makes the cache less likely and slower at returning memory back to the system
|
||||||
|
once allocated.
|
||||||
|
|
||||||
pe_settings
|
pe_settings
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/session_settings.hpp"
|
#include "libtorrent/session_settings.hpp"
|
||||||
#include "libtorrent/allocator.hpp"
|
#include "libtorrent/allocator.hpp"
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
#include <boost/pool/pool.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef TORRENT_DISK_STATS
|
#ifdef TORRENT_DISK_STATS
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#endif
|
#endif
|
||||||
|
@ -97,6 +101,25 @@ namespace libtorrent
|
||||||
|
|
||||||
mutable mutex m_pool_mutex;
|
mutable mutex m_pool_mutex;
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
// if this is true, all buffers are allocated
|
||||||
|
// from m_pool. If this is false, all buffers
|
||||||
|
// are allocated using page_aligned_allocator.
|
||||||
|
// if the settings change to prefer the other
|
||||||
|
// allocator, this bool will not switch over
|
||||||
|
// to match the settings until all buffers have
|
||||||
|
// been freed. That way, we never have a mixture
|
||||||
|
// of buffers allocated from different sources.
|
||||||
|
// in essence, this make the setting only take
|
||||||
|
// effect after a restart (which seems fine).
|
||||||
|
// or once the client goes idle for a while.
|
||||||
|
bool m_using_pool_allocator;
|
||||||
|
|
||||||
|
// memory pool for read and write operations
|
||||||
|
// and disk cache
|
||||||
|
boost::pool<page_aligned_allocator> m_pool;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
||||||
int m_allocations;
|
int m_allocations;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -965,6 +965,14 @@ namespace libtorrent
|
||||||
// in the peer protocol handshake. If this is empty
|
// in the peer protocol handshake. If this is empty
|
||||||
// the user_agent is used
|
// the user_agent is used
|
||||||
std::string handshake_client_version;
|
std::string handshake_client_version;
|
||||||
|
|
||||||
|
// if this is true, the disk cache uses a pool allocator
|
||||||
|
// for disk cache blocks. Enabling this improves
|
||||||
|
// performance of the disk cache with the side effect
|
||||||
|
// that the disk cache is less likely and slower at
|
||||||
|
// returning memory to the kernel when cache pressure
|
||||||
|
// is low.
|
||||||
|
bool use_disk_cache_pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
|
|
@ -127,7 +127,7 @@ namespace libtorrent
|
||||||
private:
|
private:
|
||||||
// the type of the addr union
|
// the type of the addr union
|
||||||
unsigned is_v6_addr:1;
|
unsigned is_v6_addr:1;
|
||||||
unsigned unused:1;
|
// unsigned unused:1;
|
||||||
public:
|
public:
|
||||||
// the state this block is in (see block_state_t)
|
// the state this block is in (see block_state_t)
|
||||||
unsigned state:2;
|
unsigned state:2;
|
||||||
|
|
|
@ -47,6 +47,10 @@ namespace libtorrent
|
||||||
disk_buffer_pool::disk_buffer_pool(int block_size)
|
disk_buffer_pool::disk_buffer_pool(int block_size)
|
||||||
: m_block_size(block_size)
|
: m_block_size(block_size)
|
||||||
, m_in_use(0)
|
, m_in_use(0)
|
||||||
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
, m_using_pool_allocator(false)
|
||||||
|
, m_pool(block_size, m_settings.cache_buffer_chunk_size)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
||||||
m_allocations = 0;
|
m_allocations = 0;
|
||||||
|
@ -80,7 +84,14 @@ namespace libtorrent
|
||||||
if (m_buf_to_category.find(buffer)
|
if (m_buf_to_category.find(buffer)
|
||||||
== m_buf_to_category.end()) return false;
|
== m_buf_to_category.end()) return false;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
if (m_using_pool_allocator)
|
||||||
|
return m_pool.is_from(buffer);
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_buffer_pool::is_disk_buffer(char* buffer) const
|
bool disk_buffer_pool::is_disk_buffer(char* buffer) const
|
||||||
|
@ -94,7 +105,20 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
mutex::scoped_lock l(m_pool_mutex);
|
mutex::scoped_lock l(m_pool_mutex);
|
||||||
TORRENT_ASSERT(m_magic == 0x1337);
|
TORRENT_ASSERT(m_magic == 0x1337);
|
||||||
char* ret = page_aligned_allocator::malloc(m_block_size);
|
char* ret;
|
||||||
|
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
ret = page_aligned_allocator::malloc(m_block_size);
|
||||||
|
#else
|
||||||
|
if (m_using_pool_allocator)
|
||||||
|
{
|
||||||
|
ret = (char*)m_pool.malloc();
|
||||||
|
m_pool.set_next_size(m_settings.cache_buffer_chunk_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = page_aligned_allocator::malloc(m_block_size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
++m_in_use;
|
++m_in_use;
|
||||||
#if TORRENT_USE_MLOCK
|
#if TORRENT_USE_MLOCK
|
||||||
if (m_settings.lock_disk_cache)
|
if (m_settings.lock_disk_cache)
|
||||||
|
@ -185,13 +209,34 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
page_aligned_allocator::free(buf);
|
page_aligned_allocator::free(buf);
|
||||||
|
#else
|
||||||
|
if (m_using_pool_allocator)
|
||||||
|
m_pool.free(buf);
|
||||||
|
else
|
||||||
|
page_aligned_allocator::free(buf);
|
||||||
|
#endif
|
||||||
--m_in_use;
|
--m_in_use;
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
// should we switch which allocator to use?
|
||||||
|
if (m_in_use == 0 && m_settings.use_disk_cache_pool != m_using_pool_allocator)
|
||||||
|
{
|
||||||
|
m_pool.release_memory();
|
||||||
|
m_using_pool_allocator = m_settings.use_disk_cache_pool;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void disk_buffer_pool::release_memory()
|
void disk_buffer_pool::release_memory()
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_magic == 0x1337);
|
TORRENT_ASSERT(m_magic == 0x1337);
|
||||||
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
mutex::scoped_lock l(m_pool_mutex);
|
||||||
|
if (m_using_pool_allocator)
|
||||||
|
m_pool.release_memory();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,6 +304,9 @@ namespace libtorrent
|
||||||
// max 'bottled' http receive buffer/url torrent size
|
// max 'bottled' http receive buffer/url torrent size
|
||||||
set.max_http_recv_buffer_size = 6 * 1024 * 1024;
|
set.max_http_recv_buffer_size = 6 * 1024 * 1024;
|
||||||
|
|
||||||
|
// the disk cache performs better with the pool allocator
|
||||||
|
set.use_disk_cache_pool = true;
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,6 +1315,7 @@ namespace libtorrent
|
||||||
, support_share_mode(true)
|
, support_share_mode(true)
|
||||||
, support_merkle_torrents(false)
|
, support_merkle_torrents(false)
|
||||||
, report_redundant_bytes(true)
|
, report_redundant_bytes(true)
|
||||||
|
, use_disk_cache_pool(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
session_settings::~session_settings() {}
|
session_settings::~session_settings() {}
|
||||||
|
|
Loading…
Reference in New Issue