remove support for using a pool allocator for disk buffers (#2257)

This commit is contained in:
Steven Siloti 2017-08-19 02:04:39 -07:00 committed by Arvid Norberg
parent 070066e892
commit 2365611507
10 changed files with 9 additions and 120 deletions

View File

@ -18,6 +18,7 @@
* added support for retrieval of DHT live nodes
* complete UNC path support
* add packets pool allocator
* remove disk buffer pool allocator
* fix last_upload and last_download overflow after 9 hours in past
* python binding add more add_torrent_params fields and an invalid key check
* introduce introduce distinct types for peer_class_t, piece_index_t and

View File

@ -35,15 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
#include "libtorrent/allocator.hpp" // for page_aligned_allocator
#include <boost/pool/pool.hpp>
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#if TORRENT_USE_INVARIANT_CHECKS
#include <set>
#endif
@ -87,8 +78,6 @@ namespace libtorrent {
int block_size() const { return m_block_size; }
void release_memory();
int in_use() const
{
std::unique_lock<std::mutex> l(m_pool_mutex);
@ -144,28 +133,6 @@ namespace libtorrent {
int m_cache_buffer_chunk_size;
#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;
// this is the actual user setting
bool m_want_pool_allocator;
// memory pool for read and write operations
// and disk cache
boost::pool<page_aligned_allocator> m_pool;
#endif
// this is specifically exempt from release_asserts
// since it's a quite costly check. Only for debug
// builds.

View File

@ -642,11 +642,15 @@ namespace libtorrent {
// failure is preferred, set this to false.
listen_system_port_fallback,
#ifndef TORRENT_NO_DEPRECATE
// ``use_disk_cache_pool`` enables using a pool allocator for disk
// cache blocks. 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.
use_disk_cache_pool,
#else
deprecated24,
#endif
// when this is true, and incoming encrypted connections are enabled,
// &supportcrypt=1 is included in http tracker announces

View File

@ -293,7 +293,6 @@ namespace libtorrent {
//
// int block_size() const { return m_block_size; }
//
// void release_memory();
// };
virtual void delete_files(remove_flags_t options, storage_error& ec) = 0;

View File

@ -692,9 +692,6 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, std::uint1
cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j)
{
#if !defined TORRENT_DISABLE_POOL_ALLOCATOR
TORRENT_ASSERT(is_disk_buffer(boost::get<disk_buffer_holder>(j->argument).get()));
#endif
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
@ -1616,14 +1613,6 @@ void block_cache::check_invariant() const
{
if (p.blocks[k].buf)
{
#if !defined TORRENT_DISABLE_POOL_ALLOCATOR && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
TORRENT_PIECE_ASSERT(is_disk_buffer(p.blocks[k].buf), &p);
// make sure we don't have the same buffer
// in the cache twice
TORRENT_PIECE_ASSERT(buffers.count(p.blocks[k].buf) == 0, &p);
buffers.insert(p.blocks[k].buf);
#endif
++num_blocks;
if (p.blocks[k].dirty)
{

View File

@ -77,11 +77,6 @@ namespace libtorrent {
, m_exceeded_max_size(false)
, m_ios(ios)
, m_cache_buffer_chunk_size(0)
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
, m_using_pool_allocator(false)
, m_want_pool_allocator(false)
, m_pool(block_size, 32)
#endif
{
#if TORRENT_USE_ASSERTS
m_magic = 0x1337;
@ -145,13 +140,9 @@ namespace libtorrent {
return m_buffers_in_use.count(buffer) == 1;
#elif defined TORRENT_DEBUG_BUFFERS
return page_aligned_allocator::in_use(buffer);
#elif defined TORRENT_DISABLE_POOL_ALLOCATOR
return true;
#else
if (m_using_pool_allocator)
return m_pool.is_from(buffer);
else
return true;
TORRENT_UNUSED(buffer);
return true;
#endif
}
@ -237,28 +228,8 @@ namespace libtorrent {
TORRENT_ASSERT(l.owns_lock());
TORRENT_UNUSED(l);
char* ret;
#if defined TORRENT_DISABLE_POOL_ALLOCATOR
char* ret = page_aligned_allocator::malloc(m_block_size);
ret = page_aligned_allocator::malloc(m_block_size);
#else
if (m_using_pool_allocator)
{
int const effective_block_size
= m_in_use >= m_max_use
? 20 // use small increments once we've exceeded the cache size
: m_cache_buffer_chunk_size
? m_cache_buffer_chunk_size
: std::max(m_max_use / 10, 1);
m_pool.set_next_size(effective_block_size);
ret = static_cast<char*>(m_pool.malloc());
}
else
{
ret = page_aligned_allocator::malloc(m_block_size);
}
#endif
if (ret == nullptr)
{
m_exceeded_max_size = true;
@ -324,14 +295,6 @@ namespace libtorrent {
// 0 cache_buffer_chunk_size means 'automatic' (i.e.
// proportional to the total disk cache size)
m_cache_buffer_chunk_size = sett.get_int(settings_pack::cache_buffer_chunk_size);
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
// if the chunk size is set to 1, there's no point in creating a pool
m_want_pool_allocator = sett.get_bool(settings_pack::use_disk_cache_pool)
&& (m_cache_buffer_chunk_size != 1);
// if there are no allocated blocks, it's OK to switch allocator
if (m_in_use == 0)
m_using_pool_allocator = m_want_pool_allocator;
#endif
int const cache_size = sett.get_int(settings_pack::cache_size);
if (cache_size < 0)
@ -419,37 +382,9 @@ namespace libtorrent {
TORRENT_ASSERT(l.owns_lock());
TORRENT_UNUSED(l);
#if defined TORRENT_DISABLE_POOL_ALLOCATOR
page_aligned_allocator::free(buf);
#else
if (m_using_pool_allocator)
m_pool.free(buf);
else
page_aligned_allocator::free(buf);
#endif // TORRENT_DISABLE_POOL_ALLOCATOR
--m_in_use;
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
// should we switch which allocator to use?
if (m_in_use == 0 && m_want_pool_allocator != m_using_pool_allocator)
{
m_pool.release_memory();
m_using_pool_allocator = m_want_pool_allocator;
}
#endif
}
void disk_buffer_pool::release_memory()
{
TORRENT_ASSERT(m_magic == 0x1337);
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
std::unique_lock<std::mutex> l(m_pool_mutex);
if (m_using_pool_allocator)
m_pool.release_memory();
#endif
}
}

View File

@ -2569,8 +2569,6 @@ namespace libtorrent {
, completed_jobs, l);
l.unlock();
m_disk_cache.release_memory();
j->storage->release_files(j->error);
return j->error ? status_t::fatal_disk_error : status_t::no_error;
}

View File

@ -240,8 +240,6 @@ namespace libtorrent {
// of a resumed file
set.set_int(settings_pack::checking_mem_usage, 320);
// the disk cache performs better with the pool allocator
set.set_bool(settings_pack::use_disk_cache_pool, true);
return set;
}

View File

@ -3547,8 +3547,6 @@ namespace {
}
}
}
// m_peer_pool.release_memory();
}
namespace {

View File

@ -189,7 +189,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0;
SET(support_merkle_torrents, true, nullptr),
SET(report_redundant_bytes, true, nullptr),
SET(listen_system_port_fallback, true, nullptr),
SET(use_disk_cache_pool, true, nullptr),
DEPRECATED_SET(use_disk_cache_pool, false, nullptr),
SET(announce_crypto_support, true, nullptr),
SET(enable_upnp, true, &session_impl::update_upnp),
SET(enable_natpmp, true, &session_impl::update_natpmp),