Browse Source

Options to better memory control by libtorrent. Closes #7029.

adaptive-webui-19844
sledgehammer999 7 years ago
parent
commit
b649d61e8b
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2
  1. 30
      src/base/bittorrent/session.cpp
  2. 6
      src/base/bittorrent/session.h
  3. 6
      src/gui/advancedsettings.cpp

30
src/base/bittorrent/session.cpp

@ -378,6 +378,10 @@ Session::Session(QObject *parent)
sessionSettings.connection_speed = 20; // default is 10 sessionSettings.connection_speed = 20; // default is 10
sessionSettings.no_connect_privileged_ports = false; sessionSettings.no_connect_privileged_ports = false;
sessionSettings.seed_choking_algorithm = libt::session_settings::fastest_upload; 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); configure(sessionSettings);
m_nativeSession->set_settings(sessionSettings); m_nativeSession->set_settings(sessionSettings);
configureListeningInterface(); configureListeningInterface();
@ -405,6 +409,10 @@ Session::Session(QObject *parent)
pack.set_int(libt::settings_pack::connection_speed, 20); // default is 10 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_bool(libt::settings_pack::no_connect_privileged_ports, false);
pack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::fastest_upload); 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); configure(pack);
m_nativeSession = new libt::session(pack, 0); 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_trackers, announceToAll);
settingsPack.set_bool(libt::settings_pack::announce_to_all_tiers, announceToAll); settingsPack.set_bool(libt::settings_pack::announce_to_all_tiers, announceToAll);
const int cacheSize = diskCacheSize(); const int cacheSize = (diskCacheSize() > -1) ? diskCacheSize() * 64 : -1;
settingsPack.set_int(libt::settings_pack::cache_size, (cacheSize > 0) ? cacheSize * 64 : -1); settingsPack.set_int(libt::settings_pack::cache_size, cacheSize);
settingsPack.set_int(libt::settings_pack::cache_expiry, diskCacheTTL()); settingsPack.set_int(libt::settings_pack::cache_expiry, diskCacheTTL());
qDebug() << "Using a disk cache size of" << cacheSize << "MiB"; qDebug() << "Using a disk cache size of" << cacheSize << "MiB";
@ -1456,8 +1464,8 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
bool announceToAll = announceToAllTrackers(); bool announceToAll = announceToAllTrackers();
sessionSettings.announce_to_all_trackers = announceToAll; sessionSettings.announce_to_all_trackers = announceToAll;
sessionSettings.announce_to_all_tiers = announceToAll; sessionSettings.announce_to_all_tiers = announceToAll;
int cacheSize = diskCacheSize(); const int cacheSize = (diskCacheSize() > -1) ? diskCacheSize() * 64 : -1;
sessionSettings.cache_size = (cacheSize > 0) ? cacheSize * 64 : -1; sessionSettings.cache_size = cacheSize;
sessionSettings.cache_expiry = diskCacheTTL(); sessionSettings.cache_expiry = diskCacheTTL();
qDebug() << "Using a disk cache size of" << cacheSize << "MiB"; qDebug() << "Using a disk cache size of" << cacheSize << "MiB";
libt::session_settings::io_buffer_mode_t mode = useOSCache() ? libt::session_settings::enable_os_cache 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 // These macros may not be available on compilers other than MSVC and GCC
#if defined(__x86_64__) || defined(_M_X64) #if defined(__x86_64__) || defined(_M_X64)
size = qMin(size, 4096u); // 4GiB size = qMin(size, 4096); // 4GiB
#else #else
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes // 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 // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
size = qMin(size, 1536u); size = qMin(size, 1536);
#endif #endif
return size; return size;
} }
void Session::setDiskCacheSize(uint size) void Session::setDiskCacheSize(int size)
{ {
#if defined(__x86_64__) || defined(_M_X64) #if defined(__x86_64__) || defined(_M_X64)
size = qMin(size, 4096u); // 4GiB size = qMin(size, 4096); // 4GiB
#else #else
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
size = qMin(size, 1536u); size = qMin(size, 1536);
#endif #endif
if (size != m_diskCacheSize) { if (size != m_diskCacheSize) {
m_diskCacheSize = size; m_diskCacheSize = size;

6
src/base/bittorrent/session.h

@ -327,8 +327,8 @@ namespace BitTorrent
void setIPFilterFile(QString path); void setIPFilterFile(QString path);
bool announceToAllTrackers() const; bool announceToAllTrackers() const;
void setAnnounceToAllTrackers(bool val); void setAnnounceToAllTrackers(bool val);
uint diskCacheSize() const; int diskCacheSize() const;
void setDiskCacheSize(uint size); void setDiskCacheSize(int size);
uint diskCacheTTL() const; uint diskCacheTTL() const;
void setDiskCacheTTL(uint ttl); void setDiskCacheTTL(uint ttl);
bool useOSCache() const; bool useOSCache() const;
@ -572,7 +572,7 @@ namespace BitTorrent
CachedSettingValue<bool> m_isTrackerFilteringEnabled; CachedSettingValue<bool> m_isTrackerFilteringEnabled;
CachedSettingValue<QString> m_IPFilterFile; CachedSettingValue<QString> m_IPFilterFile;
CachedSettingValue<bool> m_announceToAllTrackers; CachedSettingValue<bool> m_announceToAllTrackers;
CachedSettingValue<uint> m_diskCacheSize; CachedSettingValue<int> m_diskCacheSize;
CachedSettingValue<uint> m_diskCacheTTL; CachedSettingValue<uint> m_diskCacheTTL;
CachedSettingValue<bool> m_useOSCache; CachedSettingValue<bool> m_useOSCache;
CachedSettingValue<bool> m_isAnonymousModeEnabled; CachedSettingValue<bool> m_isAnonymousModeEnabled;

6
src/gui/advancedsettings.cpp

@ -194,7 +194,9 @@ void AdvancedSettings::saveAdvancedSettings()
void AdvancedSettings::updateCacheSpinSuffix(int value) 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)")); spin_cache.setSuffix(tr(" (auto)"));
else else
spin_cache.setSuffix(tr(" MiB")); spin_cache.setSuffix(tr(" MiB"));
@ -255,7 +257,7 @@ void AdvancedSettings::loadAdvancedSettings()
labelLibtorrentLink.setText(QString("<a href=\"%1\">%2</a>").arg("http://www.libtorrent.org/reference.html").arg(tr("Open documentation"))); labelLibtorrentLink.setText(QString("<a href=\"%1\">%2</a>").arg("http://www.libtorrent.org/reference.html").arg(tr("Open documentation")));
labelLibtorrentLink.setOpenExternalLinks(true); labelLibtorrentLink.setOpenExternalLinks(true);
// Disk write cache // 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. // 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 // These macros may not be available on compilers other than MSVC and GCC
#if defined(__x86_64__) || defined(_M_X64) #if defined(__x86_64__) || defined(_M_X64)

Loading…
Cancel
Save