count send and receive buffers against the cache size limit
This commit is contained in:
parent
84dda7b617
commit
033fd5bd22
|
@ -3554,8 +3554,11 @@ where they are only allowed to download whole pieces. If the whole piece a peer
|
||||||
in parole mode fails the hash check, it is banned. If a peer participates in a
|
in parole mode fails the hash check, it is banned. If a peer participates in a
|
||||||
piece that passes the hash check, it is taken out of parole mode.
|
piece that passes the hash check, it is taken out of parole mode.
|
||||||
|
|
||||||
``cache_size`` is the disk write cache. It is specified in units of 16 KiB blocks.
|
``cache_size`` is the disk write and read cache. It is specified in units of
|
||||||
It defaults to 512 (= 8 MB).
|
16 KiB blocks. It defaults to 1024 (= 16 MB). Buffers that are part of a peer's
|
||||||
|
send or receive buffer also count against this limit. Send and receive buffers
|
||||||
|
will never be denied to be allocated, but they will cause the actual cached blocks
|
||||||
|
to be flushed or evicted.
|
||||||
|
|
||||||
``cache_expiry`` is the number of seconds from the last cached write to a piece
|
``cache_expiry`` is the number of seconds from the last cached write to a piece
|
||||||
in the write cache, to when it's forcefully flushed to disk. Default is 60 second.
|
in the write cache, to when it's forcefully flushed to disk. Default is 60 second.
|
||||||
|
|
|
@ -181,12 +181,17 @@ namespace libtorrent
|
||||||
|
|
||||||
void release_memory();
|
void release_memory();
|
||||||
|
|
||||||
|
int in_use() const { return m_in_use; }
|
||||||
|
|
||||||
protected:
|
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;
|
||||||
|
|
||||||
|
// number of disk buffers currently allocated
|
||||||
|
int m_in_use;
|
||||||
|
|
||||||
session_settings m_settings;
|
session_settings m_settings;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -123,7 +123,7 @@ namespace libtorrent
|
||||||
, auto_upload_slots(true)
|
, auto_upload_slots(true)
|
||||||
, auto_upload_slots_rate_based(false)
|
, auto_upload_slots_rate_based(false)
|
||||||
, use_parole_mode(true)
|
, use_parole_mode(true)
|
||||||
, cache_size(512)
|
, cache_size(1024)
|
||||||
, cache_expiry(60)
|
, cache_expiry(60)
|
||||||
, use_read_cache(true)
|
, use_read_cache(true)
|
||||||
, disk_io_write_mode(0)
|
, disk_io_write_mode(0)
|
||||||
|
|
|
@ -51,6 +51,7 @@ 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)
|
||||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
, m_pool(block_size)
|
, m_pool(block_size)
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,6 +84,7 @@ namespace libtorrent
|
||||||
#else
|
#else
|
||||||
char* ret = (char*)m_pool.ordered_malloc();
|
char* ret = (char*)m_pool.ordered_malloc();
|
||||||
#endif
|
#endif
|
||||||
|
++m_in_use;
|
||||||
#if TORRENT_USE_MLOCK
|
#if TORRENT_USE_MLOCK
|
||||||
if (m_settings.lock_disk_cache)
|
if (m_settings.lock_disk_cache)
|
||||||
{
|
{
|
||||||
|
@ -131,6 +133,7 @@ namespace libtorrent
|
||||||
#else
|
#else
|
||||||
m_pool.ordered_free(buf);
|
m_pool.ordered_free(buf);
|
||||||
#endif
|
#endif
|
||||||
|
--m_in_use;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* disk_buffer_pool::allocate_buffers(int num_blocks, char const* category)
|
char* disk_buffer_pool::allocate_buffers(int num_blocks, char const* category)
|
||||||
|
@ -141,6 +144,7 @@ namespace libtorrent
|
||||||
#else
|
#else
|
||||||
char* ret = (char*)m_pool.ordered_malloc(num_blocks);
|
char* ret = (char*)m_pool.ordered_malloc(num_blocks);
|
||||||
#endif
|
#endif
|
||||||
|
m_in_use += num_blocks;
|
||||||
#if TORRENT_USE_MLOCK
|
#if TORRENT_USE_MLOCK
|
||||||
if (m_settings.lock_disk_cache)
|
if (m_settings.lock_disk_cache)
|
||||||
{
|
{
|
||||||
|
@ -189,6 +193,7 @@ namespace libtorrent
|
||||||
#else
|
#else
|
||||||
m_pool.ordered_free(buf, num_blocks);
|
m_pool.ordered_free(buf, num_blocks);
|
||||||
#endif
|
#endif
|
||||||
|
m_in_use -= num_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void disk_buffer_pool::release_memory()
|
void disk_buffer_pool::release_memory()
|
||||||
|
@ -567,7 +572,7 @@ namespace libtorrent
|
||||||
|
|
||||||
int end_block = start_block;
|
int end_block = start_block;
|
||||||
for (int i = start_block; i < blocks_in_piece
|
for (int i = start_block; i < blocks_in_piece
|
||||||
&& (m_cache_stats.cache_size < m_settings.cache_size
|
&& (in_use() < m_settings.cache_size
|
||||||
|| (options && ignore_cache_size)); ++i)
|
|| (options && ignore_cache_size)); ++i)
|
||||||
{
|
{
|
||||||
// this is a block that is already allocated
|
// this is a block that is already allocated
|
||||||
|
@ -652,14 +657,14 @@ namespace libtorrent
|
||||||
, cache_t::iterator ignore
|
, cache_t::iterator ignore
|
||||||
, mutex_t::scoped_lock& l)
|
, mutex_t::scoped_lock& l)
|
||||||
{
|
{
|
||||||
if (m_settings.cache_size - m_cache_stats.cache_size < num_blocks)
|
if (m_settings.cache_size - in_use() < num_blocks)
|
||||||
{
|
{
|
||||||
// there's not enough room in the cache, clear a piece
|
// there's not enough room in the cache, clear a piece
|
||||||
// from the read cache
|
// from the read cache
|
||||||
if (!clear_oldest_read_piece(ignore, l)) return false;
|
if (!clear_oldest_read_piece(ignore, l)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_settings.cache_size - m_cache_stats.cache_size >= num_blocks;
|
return m_settings.cache_size - in_use() >= num_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns -1 on read error, -2 on out of memory error or the number of bytes read
|
// returns -1 on read error, -2 on out of memory error or the number of bytes read
|
||||||
|
@ -829,7 +834,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// if read cache is disabled or we exceeded the
|
// if read cache is disabled or we exceeded the
|
||||||
// limit, remove this piece from the cache
|
// limit, remove this piece from the cache
|
||||||
if (m_cache_stats.cache_size >= m_settings.cache_size
|
if (in_use() >= m_settings.cache_size
|
||||||
|| !m_settings.use_read_cache)
|
|| !m_settings.use_read_cache)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(!m_read_pieces.empty());
|
TORRENT_ASSERT(!m_read_pieces.empty());
|
||||||
|
@ -1279,7 +1284,7 @@ namespace libtorrent
|
||||||
// in the cache, we should not
|
// in the cache, we should not
|
||||||
// free it at the end
|
// free it at the end
|
||||||
holder.release();
|
holder.release();
|
||||||
if (m_cache_stats.cache_size >= m_settings.cache_size)
|
if (in_use() >= m_settings.cache_size)
|
||||||
flush_oldest_piece(l);
|
flush_oldest_piece(l);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue