mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 19:40:18 -07:00
Add option to control qBittorrent process memory priority
This is to avoid Windows swapping out other application data from OS cache and put in torrent data which hinders other program responsiveness. The default value "Below normal" is choosen because casual users have other higher priority apps (such as browser) running and they don't expect OS to swap out its data. Dedicated seeders most probably will not have other app running on their system and would expect qbt has priority over other background services. The option only has effect on Windows >= 8.
This commit is contained in:
parent
c1e0207454
commit
0f60121b94
4 changed files with 137 additions and 0 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <utility>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <Windows.h>
|
||||
#include <wincrypt.h>
|
||||
#include <iphlpapi.h>
|
||||
#endif
|
||||
|
@ -344,6 +345,9 @@ Session::Session(QObject *parent)
|
|||
return tmp;
|
||||
}
|
||||
)
|
||||
#if defined(Q_OS_WIN)
|
||||
, m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal)
|
||||
#endif
|
||||
, m_resumeFolderLock {new QFile {this}}
|
||||
, m_refreshTimer {new QTimer {this}}
|
||||
, m_seedingLimitTimer {new QTimer {this}}
|
||||
|
@ -930,6 +934,10 @@ void Session::configureComponents()
|
|||
disableIPFilter();
|
||||
m_IPFilteringConfigured = true;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
applyOSMemoryPriority();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Session::initializeNativeSession()
|
||||
|
@ -2753,6 +2761,59 @@ QStringList Session::bannedIPs() const
|
|||
return m_bannedIPs;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
OSMemoryPriority Session::getOSMemoryPriority() const
|
||||
{
|
||||
return m_OSMemoryPriority;
|
||||
}
|
||||
|
||||
void Session::setOSMemoryPriority(const OSMemoryPriority priority)
|
||||
{
|
||||
if (m_OSMemoryPriority == priority)
|
||||
return;
|
||||
|
||||
m_OSMemoryPriority = priority;
|
||||
configureDeferred();
|
||||
}
|
||||
|
||||
void Session::applyOSMemoryPriority() const
|
||||
{
|
||||
using SETPROCESSINFORMATION = BOOL (WINAPI *)(HANDLE, PROCESS_INFORMATION_CLASS, LPVOID, DWORD);
|
||||
const auto setProcessInformation = Utils::Misc::loadWinAPI<SETPROCESSINFORMATION>("Kernel32.dll", "SetProcessInformation");
|
||||
if (!setProcessInformation) // only available on Windows >= 8
|
||||
return;
|
||||
|
||||
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
|
||||
// this dummy struct is required to compile successfully when targeting older Windows version
|
||||
struct MEMORY_PRIORITY_INFORMATION
|
||||
{
|
||||
ULONG MemoryPriority;
|
||||
};
|
||||
#endif
|
||||
|
||||
MEMORY_PRIORITY_INFORMATION prioInfo {};
|
||||
switch (getOSMemoryPriority()) {
|
||||
case OSMemoryPriority::Normal:
|
||||
default:
|
||||
prioInfo.MemoryPriority = MEMORY_PRIORITY_NORMAL;
|
||||
break;
|
||||
case OSMemoryPriority::BelowNormal:
|
||||
prioInfo.MemoryPriority = MEMORY_PRIORITY_BELOW_NORMAL;
|
||||
break;
|
||||
case OSMemoryPriority::Medium:
|
||||
prioInfo.MemoryPriority = MEMORY_PRIORITY_MEDIUM;
|
||||
break;
|
||||
case OSMemoryPriority::Low:
|
||||
prioInfo.MemoryPriority = MEMORY_PRIORITY_LOW;
|
||||
break;
|
||||
case OSMemoryPriority::VeryLow:
|
||||
prioInfo.MemoryPriority = MEMORY_PRIORITY_VERY_LOW;
|
||||
break;
|
||||
}
|
||||
setProcessInformation(::GetCurrentProcess(), ProcessMemoryPriority, &prioInfo, sizeof(prioInfo));
|
||||
}
|
||||
#endif
|
||||
|
||||
int Session::maxConnectionsPerTorrent() const
|
||||
{
|
||||
return m_maxConnectionsPerTorrent;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue