add back close_file_interval feature but disable it by default

This commit is contained in:
arvidn
2019-08-28 09:38:57 +02:00
committed by Arvid Norberg
parent 3076188911
commit b8e13e08c5
5 changed files with 37 additions and 11 deletions

View File

@ -102,6 +102,8 @@ namespace aux {
std::vector<open_file_state> get_status(storage_index_t st) const;
void close_oldest();
private:
std::shared_ptr<file_mapping> remove_oldest(std::unique_lock<std::mutex>&);

View File

@ -44,7 +44,6 @@ using namespace lt;
// the disk I/O thread is not simulated with high enough fidelity for this to
// work
/*
TORRENT_TEST(close_file_interval)
{
bool ran_to_completion = false;
@ -86,7 +85,6 @@ TORRENT_TEST(close_file_interval)
});
TEST_CHECK(ran_to_completion);
}
*/
TORRENT_TEST(file_pool_size)
{

View File

@ -316,6 +316,10 @@ private:
settings_interface const& m_settings;
// we call close_oldest_file on the file_pool regularly. This is the next
// time we should call it
time_point m_next_close_oldest_file = min_time();
// LRU cache of open files
aux::file_view_pool m_file_pool;
@ -1409,6 +1413,21 @@ TORRENT_EXPORT std::unique_ptr<disk_interface> mmap_disk_io_constructor(
}
}
}
if (now > m_next_close_oldest_file)
{
seconds const interval(m_settings.get_int(settings_pack::close_file_interval));
if (interval <= seconds(0))
{
// check again in one minute, in case the setting changed
m_next_close_oldest_file = now + minutes(1);
}
else
{
m_next_close_oldest_file = now + interval;
m_file_pool.close_oldest();
}
}
}
execute_job(j);

View File

@ -113,7 +113,7 @@ namespace libtorrent { namespace aux {
{
// the file cache is at its maximum size, close
// the least recently used file
remove_oldest(l);
defer_destruction = remove_oldest(l);
}
l.unlock();
@ -234,6 +234,9 @@ namespace {
void file_view_pool::resize(int const size)
{
// these are destructed _after_ the mutex is released
std::vector<std::shared_ptr<file_mapping>> defer_destruction;
std::unique_lock<std::mutex> l(m_mutex);
TORRENT_ASSERT(size > 0);
@ -244,7 +247,17 @@ namespace {
// close the least recently used files
while (int(m_files.size()) > m_size)
remove_oldest(l);
defer_destruction.emplace_back(remove_oldest(l));
}
void file_view_pool::close_oldest()
{
// closing a file may be long running operation (mac os x)
// destruct it after the mutex is released
std::shared_ptr<file_mapping> deferred_destruction;
std::unique_lock<std::mutex> l(m_mutex);
deferred_destruction = remove_oldest(l);
}
}
}

View File

@ -104,12 +104,6 @@ namespace libtorrent {
#else
#define DEPRECATED_SET(name, default_value, fun) { "", nullptr, 0 }
#define DEPRECATED_SET_STR(name, default_value, fun) { "", nullptr, nullptr }
#endif
#ifdef TORRENT_WINDOWS
constexpr int CLOSE_FILE_INTERVAL = 120;
#else
constexpr int CLOSE_FILE_INTERVAL = 0;
#endif
namespace {
@ -347,7 +341,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0;
DEPRECATED_SET(cache_size_volatile, 256, nullptr),
SET(urlseed_max_request_bytes, 16 * 1024 * 1024, nullptr),
SET(web_seed_name_lookup_retry, 1800, nullptr),
SET(close_file_interval, CLOSE_FILE_INTERVAL, nullptr),
SET(close_file_interval, 0, nullptr),
SET(utp_cwnd_reduce_timer, 100, nullptr),
SET(max_web_seed_connections, 3, nullptr),
SET(resolver_cache_timeout, 1200, &session_impl::update_resolver_cache_timeout),