diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 370bd053e..622f93fb5 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -378,6 +378,10 @@ Session::Session(QObject *parent) sessionSettings.connection_speed = 20; // default is 10 sessionSettings.no_connect_privileged_ports = false; sessionSettings.seed_choking_algorithm = libt::session_settings::fastest_upload; + // Disk cache pool is rarely tested in libtorrent and doesn't free buffers + // Soon to be deprecated there + // More info: https://github.com/arvidn/libtorrent/issues/2251 + sessionSettings.use_disk_cache_pool = false; configure(sessionSettings); m_nativeSession->set_settings(sessionSettings); configureListeningInterface(); @@ -405,6 +409,10 @@ Session::Session(QObject *parent) pack.set_int(libt::settings_pack::connection_speed, 20); // default is 10 pack.set_bool(libt::settings_pack::no_connect_privileged_ports, false); pack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::fastest_upload); + // Disk cache pool is rarely tested in libtorrent and doesn't free buffers + // Soon to be deprecated there + // More info: https://github.com/arvidn/libtorrent/issues/2251 + pack.set_bool(libt::settings_pack::use_disk_cache_pool, false); configure(pack); m_nativeSession = new libt::session(pack, 0); @@ -1239,8 +1247,8 @@ void Session::configure(libtorrent::settings_pack &settingsPack) settingsPack.set_bool(libt::settings_pack::announce_to_all_trackers, announceToAll); settingsPack.set_bool(libt::settings_pack::announce_to_all_tiers, announceToAll); - const int cacheSize = diskCacheSize(); - settingsPack.set_int(libt::settings_pack::cache_size, (cacheSize > 0) ? cacheSize * 64 : -1); + const int cacheSize = (diskCacheSize() > -1) ? diskCacheSize() * 64 : -1; + settingsPack.set_int(libt::settings_pack::cache_size, cacheSize); settingsPack.set_int(libt::settings_pack::cache_expiry, diskCacheTTL()); qDebug() << "Using a disk cache size of" << cacheSize << "MiB"; @@ -1456,8 +1464,8 @@ void Session::configure(libtorrent::session_settings &sessionSettings) bool announceToAll = announceToAllTrackers(); sessionSettings.announce_to_all_trackers = announceToAll; sessionSettings.announce_to_all_tiers = announceToAll; - int cacheSize = diskCacheSize(); - sessionSettings.cache_size = (cacheSize > 0) ? cacheSize * 64 : -1; + const int cacheSize = (diskCacheSize() > -1) ? diskCacheSize() * 64 : -1; + sessionSettings.cache_size = cacheSize; sessionSettings.cache_expiry = diskCacheTTL(); qDebug() << "Using a disk cache size of" << cacheSize << "MiB"; libt::session_settings::io_buffer_mode_t mode = useOSCache() ? libt::session_settings::enable_os_cache @@ -2782,27 +2790,27 @@ void Session::setAnnounceToAllTrackers(bool val) } } -uint Session::diskCacheSize() const +int Session::diskCacheSize() const { - uint size = m_diskCacheSize; + int size = m_diskCacheSize; // These macros may not be available on compilers other than MSVC and GCC #if defined(__x86_64__) || defined(_M_X64) - size = qMin(size, 4096u); // 4GiB + size = qMin(size, 4096); // 4GiB #else // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes // allocate 1536MiB and leave 512MiB to the rest of program data in RAM - size = qMin(size, 1536u); + size = qMin(size, 1536); #endif return size; } -void Session::setDiskCacheSize(uint size) +void Session::setDiskCacheSize(int size) { #if defined(__x86_64__) || defined(_M_X64) - size = qMin(size, 4096u); // 4GiB + size = qMin(size, 4096); // 4GiB #else // allocate 1536MiB and leave 512MiB to the rest of program data in RAM - size = qMin(size, 1536u); + size = qMin(size, 1536); #endif if (size != m_diskCacheSize) { m_diskCacheSize = size; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 0b9cef8d5..de6ef5aeb 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -327,8 +327,8 @@ namespace BitTorrent void setIPFilterFile(QString path); bool announceToAllTrackers() const; void setAnnounceToAllTrackers(bool val); - uint diskCacheSize() const; - void setDiskCacheSize(uint size); + int diskCacheSize() const; + void setDiskCacheSize(int size); uint diskCacheTTL() const; void setDiskCacheTTL(uint ttl); bool useOSCache() const; @@ -572,7 +572,7 @@ namespace BitTorrent CachedSettingValue m_isTrackerFilteringEnabled; CachedSettingValue m_IPFilterFile; CachedSettingValue m_announceToAllTrackers; - CachedSettingValue m_diskCacheSize; + CachedSettingValue m_diskCacheSize; CachedSettingValue m_diskCacheTTL; CachedSettingValue m_useOSCache; CachedSettingValue m_isAnonymousModeEnabled; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 6d5926cd3..09bc9d062 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -194,7 +194,9 @@ void AdvancedSettings::saveAdvancedSettings() void AdvancedSettings::updateCacheSpinSuffix(int value) { - if (value <= 0) + if (value == 0) + spin_cache.setSuffix(tr(" (disabled)")); + else if (value < 0) spin_cache.setSuffix(tr(" (auto)")); else spin_cache.setSuffix(tr(" MiB")); @@ -255,7 +257,7 @@ void AdvancedSettings::loadAdvancedSettings() labelLibtorrentLink.setText(QString("%2").arg("http://www.libtorrent.org/reference.html").arg(tr("Open documentation"))); labelLibtorrentLink.setOpenExternalLinks(true); // Disk write cache - spin_cache.setMinimum(0); + spin_cache.setMinimum(-1); // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes. // These macros may not be available on compilers other than MSVC and GCC #if defined(__x86_64__) || defined(_M_X64)