From c7daaf95fcfa977093ae1deccdc631eaa1ecafe1 Mon Sep 17 00:00:00 2001 From: summer <79678786+summerqB@users.noreply.github.com> Date: Sun, 26 Jun 2022 10:26:21 +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. --- src/app/application.cpp | 6 ++++-- src/app/application.h | 2 +- src/gui/advancedsettings.cpp | 8 +++++++- src/gui/advancedsettings.h | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 405114555..213fea66a 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -220,7 +220,9 @@ void Application::setMemoryWorkingSetLimit(const int size) return; m_storeMemoryWorkingSetLimit = size; +#ifdef QBT_USES_LIBTORRENT2 applyMemoryWorkingSetLimit(); +#endif } #endif @@ -621,7 +623,7 @@ void Application::processParams(const QStringList ¶ms) int Application::exec(const QStringList ¶ms) { -#ifdef Q_OS_WIN +#if (defined(Q_OS_WIN) && defined(QBT_USES_LIBTORRENT2)) applyMemoryWorkingSetLimit(); #endif @@ -794,7 +796,7 @@ void Application::shutdownCleanup(QSessionManager &manager) } #endif -#ifdef Q_OS_WIN +#if (defined(Q_OS_WIN) && defined(QBT_USES_LIBTORRENT2)) void Application::applyMemoryWorkingSetLimit() { const SIZE_T UNIT_SIZE = 1024 * 1024; // MiB diff --git a/src/app/application.h b/src/app/application.h index 54b35ae81..5c45dd3eb 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -126,7 +126,7 @@ private slots: #endif private: -#ifdef Q_OS_WIN +#if (defined(Q_OS_WIN) && defined(QBT_USES_LIBTORRENT2)) void applyMemoryWorkingSetLimit(); #endif void initializeTranslation(); diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index cba5e8330..c08f0b393 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -62,9 +62,11 @@ namespace // qBittorrent section QBITTORRENT_HEADER, RESUME_DATA_STORAGE, +#if (defined(Q_OS_WIN) && defined(QBT_USES_LIBTORRENT2)) + MEMORY_WORKING_SET_LIMIT, +#endif #if defined(Q_OS_WIN) OS_MEMORY_PRIORITY, - MEMORY_WORKING_SET_LIMIT, #endif // network interface NETWORK_IFACE, @@ -198,7 +200,9 @@ void AdvancedSettings::saveAdvancedSettings() } session->setOSMemoryPriority(prio); +#ifdef QBT_USES_LIBTORRENT2 static_cast(QCoreApplication::instance())->setMemoryWorkingSetLimit(m_spinBoxMemoryWorkingSetLimit.value()); +#endif #endif // Async IO threads session->setAsyncIOThreads(m_spinBoxAsyncIOThreads.value()); @@ -443,6 +447,7 @@ void AdvancedSettings::loadAdvancedSettings() + ' ' + makeLink("https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-memory_priority_information", "(?)")) , &m_comboBoxOSMemoryPriority); +#ifdef QBT_USES_LIBTORRENT2 m_spinBoxMemoryWorkingSetLimit.setMinimum(1); m_spinBoxMemoryWorkingSetLimit.setMaximum(std::numeric_limits::max()); m_spinBoxMemoryWorkingSetLimit.setSuffix(tr(" MiB")); @@ -451,6 +456,7 @@ void AdvancedSettings::loadAdvancedSettings() addRow(MEMORY_WORKING_SET_LIMIT, (tr("Physical memory (RAM) usage limit") + ' ' + makeLink("https://wikipedia.org/wiki/Working_set", "(?)")) , &m_spinBoxMemoryWorkingSetLimit); +#endif #endif // Async IO threads diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 217ce48f3..8ef0f43ec 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -82,8 +82,10 @@ private: // OS dependent settings #if defined(Q_OS_WIN) QComboBox m_comboBoxOSMemoryPriority; +#ifdef QBT_USES_LIBTORRENT2 QSpinBox m_spinBoxMemoryWorkingSetLimit; #endif +#endif #ifndef Q_OS_MACOS QCheckBox m_checkBoxIconsInMenusEnabled;