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.
This commit is contained in:
summer
2022-06-26 10:26:21 +06:00
committed by Chocobo1
parent b760f37093
commit c7daaf95fc
4 changed files with 14 additions and 4 deletions

View File

@@ -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 &params)
int Application::exec(const QStringList &params)
{
#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

View File

@@ -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();

View File

@@ -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<Application *>(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<int>::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

View File

@@ -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;