From cc0a0b56eddb7b39740f424b6f3ae9213f942404 Mon Sep 17 00:00:00 2001 From: summer <79678786+summerqB@users.noreply.github.com> Date: Thu, 30 Jun 2022 09:23:48 +0600 Subject: [PATCH] Make working set limit available only on libtorrent 2.0.x builds You can already control the cache size in libtorrent 1.2.x so it doesn't make sense to implement this limit for all use cases. Also there are some downsides to using working set size to limit memory usage such as unresponsive GUI when limit gets hit. PR #17275. --- src/app/application.cpp | 6 ++++++ src/app/application.h | 2 ++ src/gui/advancedsettings.cpp | 6 ++++++ src/gui/advancedsettings.h | 4 ++-- src/webui/www/private/views/preferences.html | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 8300ceaa7..cde4ada94 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -216,7 +216,9 @@ void Application::setMemoryWorkingSetLimit(const int size) return; m_storeMemoryWorkingSetLimit = size; +#ifdef QBT_USES_LIBTORRENT2 applyMemoryWorkingSetLimit(); +#endif } bool Application::isFileLoggerEnabled() const @@ -595,7 +597,9 @@ void Application::processParams(const QStringList ¶ms) int Application::exec(const QStringList ¶ms) { +#ifdef QBT_USES_LIBTORRENT2 applyMemoryWorkingSetLimit(); +#endif Net::ProxyConfigurationManager::initInstance(); Net::DownloadManager::initInstance(); @@ -766,6 +770,7 @@ void Application::shutdownCleanup(QSessionManager &manager) } #endif +#ifdef QBT_USES_LIBTORRENT2 void Application::applyMemoryWorkingSetLimit() { const size_t MiB = 1024 * 1024; @@ -803,6 +808,7 @@ void Application::applyMemoryWorkingSetLimit() } #endif } +#endif void Application::cleanup() { diff --git a/src/app/application.h b/src/app/application.h index c918145f8..740445c67 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -136,7 +136,9 @@ private: void processParams(const QStringList ¶ms); void runExternalProgram(const BitTorrent::Torrent *torrent) const; void sendNotificationEmail(const BitTorrent::Torrent *torrent); +#ifdef QBT_USES_LIBTORRENT2 void applyMemoryWorkingSetLimit(); +#endif #ifndef DISABLE_GUI #ifdef Q_OS_MACOS diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 3d4b8d40d..64cfd1009 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -62,7 +62,9 @@ namespace // qBittorrent section QBITTORRENT_HEADER, RESUME_DATA_STORAGE, +#ifdef QBT_USES_LIBTORRENT2 MEMORY_WORKING_SET_LIMIT, +#endif #if defined(Q_OS_WIN) OS_MEMORY_PRIORITY, #endif @@ -178,8 +180,10 @@ void AdvancedSettings::saveAdvancedSettings() const BitTorrent::Session *const session = BitTorrent::Session::instance(); session->setResumeDataStorageType(m_comboBoxResumeDataStorage.currentData().value()); +#ifdef QBT_USES_LIBTORRENT2 // Physical memory (RAM) usage limit app()->setMemoryWorkingSetLimit(m_spinBoxMemoryWorkingSetLimit.value()); +#endif #if defined(Q_OS_WIN) session->setOSMemoryPriority(m_comboBoxOSMemoryPriority.currentData().value()); #endif @@ -407,6 +411,7 @@ void AdvancedSettings::loadAdvancedSettings() m_comboBoxResumeDataStorage.setCurrentIndex(m_comboBoxResumeDataStorage.findData(QVariant::fromValue(session->resumeDataStorageType()))); addRow(RESUME_DATA_STORAGE, tr("Resume data storage type (requires restart)"), &m_comboBoxResumeDataStorage); +#ifdef QBT_USES_LIBTORRENT2 // Physical memory (RAM) usage limit m_spinBoxMemoryWorkingSetLimit.setMinimum(1); m_spinBoxMemoryWorkingSetLimit.setMaximum(std::numeric_limits::max()); @@ -415,6 +420,7 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxMemoryWorkingSetLimit.setValue(app()->memoryWorkingSetLimit()); addRow(MEMORY_WORKING_SET_LIMIT, (tr("Physical memory (RAM) usage limit") + u' ' + makeLink(u"https://wikipedia.org/wiki/Working_set", u"(?)")) , &m_spinBoxMemoryWorkingSetLimit); +#endif #if defined(Q_OS_WIN) m_comboBoxOSMemoryPriority.addItem(tr("Normal"), QVariant::fromValue(BitTorrent::OSMemoryPriority::Normal)); m_comboBoxOSMemoryPriority.addItem(tr("Below normal"), QVariant::fromValue(BitTorrent::OSMemoryPriority::BelowNormal)); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 44c7a789d..feb0ebc92 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -61,7 +61,7 @@ private: void loadAdvancedSettings(); template void addRow(int row, const QString &text, T *widget); - QSpinBox m_spinBoxMemoryWorkingSetLimit, m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize, + QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize, m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS, m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketBacklogSize, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, @@ -80,7 +80,7 @@ private: QCheckBox m_checkBoxCoalesceRW; #else QComboBox m_comboBoxDiskIOType; - QSpinBox m_spinBoxHashingThreads; + QSpinBox m_spinBoxMemoryWorkingSetLimit, m_spinBoxHashingThreads; #endif // OS dependent settings diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 5ee3fca8c..9fb72df5b 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -913,7 +913,7 @@
- +   QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog]