From ecba902ff108c4eb6349c2fbd9196766a8382cf2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 7 Aug 2011 07:27:38 +0000 Subject: [PATCH] fix cache eviction issue in seed_mode --- src/disk_io_thread.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 67ffcb9c2..cf809f2c1 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1037,15 +1037,20 @@ namespace libtorrent TORRENT_ASSERT(j.cache_min_time >= 0); mutex::scoped_lock l(m_piece_mutex); + + int piece_size = j.storage->info()->piece_size(j.piece); + int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; + + if (in_use() + blocks_in_piece >= m_settings.cache_size) + { + flush_cache_blocks(l, in_use() - m_settings.cache_size + blocks_in_piece); + } cache_piece_index_t::iterator p; bool hit; int ret = cache_piece(j, p, hit, ignore_cache_size, l); if (ret < 0) return ret; - int piece_size = j.storage->info()->piece_size(j.piece); - int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; - if (!m_settings.disable_hash_checks) { hasher ctx;