How to limit disk usage (Write/I/O) by application? (NOT space usage)

I'm really annoyed by not being able to do a few jobs at a time even if I have plenty of RAM and CPU left to utilise - so it's the disk usage, for example when I am extracting big archives using WinRAR or other disk-write-hungry stuff.

I want to be able to limit this, let's say to 20%, So WinRAR would only use up to 20% of the write capabilities of my disk which should result in

"no more hang ups of my OS and being able to multitask even when the I am unpacking a big archive"

when doing such disk-intensive jobs.

If you know how to limit I/O of a disk by application then this will really help!

My OS: Windows 7 Ultimate x64. I tried setting process affinity and priority, but without luck.


Solution 1:

In Process Explorer, in addition to the regular Normal 8, Below normal 6, Idle 4 priority level, there is an additional Background 4 level, which says that it has Low I/O and Memory Priority. Background 4 results in Very Low I/O priority, according to the corresponding column. That should accomplish what you want.

I believe it is available in Vista and above, as Wikipedia suggests that I/O prioritization was added then.

From your comment it looks like you also want to do this from the command line. I'm not sure if that is available in Process Explorer, but PsTools might have something useful in this regard. I know PsExec lets you launch processes with low priority. If not, it shouldn't be too difficult to whip up a command line program or script to set the priority of a running process.

Solution 2:

The comment from @AlexandrZarubkin should receive more attention. The pointer to a Russian language forum habr.com helps a lot. Trottle made a registry file that allows to permanently change the priority when an executable is launch by right click in explorer: Windows Executable -> Set base priority -> Below normal CPU, low IO

This text should be saved as a .reg file and imported into the Windows registry:

Windows Registry Editor Version 5.00 

;Copyright 2016 Trottle 
;This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3. 
;This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
;See <http://www.gnu.org/licenses/> for more details. 

[-HKEY_CLASSES_ROOT\exefile\shell\Bpc] 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc] 
"HasLUAShield"="" 
"MUIVerb"="Set base priority" 
"subcommands"=""

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\01low] 
"MUIVerb"="Idle CPU, lowest IO, low paging" 
"Icon"="comres.dll,9" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\01low\command] 
@="cmd /q /c echo Windows Registry Editor Version 5.00>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & for /f \"delims=<\" %%i in (\"%1\") do echo [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%%~nxi\\PerfOptions]>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"CpuPriorityClass\"=dword:00000001>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"IoPriority\"=dword:00000000>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"PagePriority\"=dword:00000001>>%%TEMP%%\\pr.reg & regedit /s %%TEMP%%\\pr.reg & del %%TEMP%%\\pr.reg & msg * %~ni priority is set to IDLE" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\02below] 
"MUIVerb"="Below normal CPU, low IO" 
"Icon"="comres.dll,12" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\02below\command] 
@="cmd /q /c echo Windows Registry Editor Version 5.00>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & for /f \"delims=<\" %%i in (\"%1\") do echo [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%%~nxi\\PerfOptions]>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"CpuPriorityClass\"=dword:00000005>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"IoPriority\"=dword:00000001>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"PagePriority\"=->>%%TEMP%%\\pr.reg & regedit /s %%TEMP%%\\pr.reg & del %%TEMP%%\\pr.reg & msg * %~ni priority is set to BELOW NORMAL" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\03above] 
"Icon"="comres.dll,8" 
"MUIVerb"="Above normal CPU" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\03above\command] 
@="cmd /q /c echo Windows Registry Editor Version 5.00>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & for /f \"delims=<\" %%i in (\"%1\") do echo [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%%~nxi\\PerfOptions]>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"CpuPriorityClass\"=dword:00000006>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"IoPriority\"=->>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"PagePriority\"=->>%%TEMP%%\\pr.reg & regedit /s %%TEMP%%\\pr.reg & del %%TEMP%%\\pr.reg & msg * %~ni priority is set to ABOVE NORMAL" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\04high] 
"MUIVerb"="High CPU" 
"Icon"="comres.dll,16" 
"CommandFlags"=dword:00000040

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\04high\command] 
@="cmd /q /c echo Windows Registry Editor Version 5.00>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & for /f \"delims=<\" %%i in (\"%1\") do echo [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%%~nxi\\PerfOptions]>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"CpuPriorityClass\"=dword:00000003>>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"IoPriority\"=->>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & echo \"PagePriority\"=->>%%TEMP%%\\pr.reg & regedit /s %%TEMP%%\\pr.reg & del %%TEMP%%\\pr.reg & msg * %~ni priority is set to HIGH" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\06ask] 
"MUIVerb"="Show current priorities" 
"Icon"="shell32.dll,23" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\06ask\command] 
@="cmd /q /c for /f \"delims=<\" %%i in (\"%1\") do reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%%~nxi\\PerfOptions\" /s | msg *" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\07default] 
"MUIVerb"="Restore to default" 
"Icon"="comres.dll,4" 

[HKEY_CLASSES_ROOT\exefile\shell\Bpc\shell\07default\command] 
@="cmd /q /c echo Windows Registry Editor Version 5.00>%%TEMP%%\\pr.reg & echo.>>%%TEMP%%\\pr.reg & for /f \"delims=<\" %%i in (\"%1\") do echo [-HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%%~nxi\\PerfOptions]>>%%TEMP%%\\pr.reg & regedit /s %%TEMP%%\\pr.reg & del %%TEMP%%\\pr.reg & msg * %~ni priority is restored to default" 

; If you do not want to have uninstaller you can skip next part: 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BpcSubMenu] 
"DisplayName"="'Set base priority' submenu" 
"DisplayIcon"="imageres.dll,73" 
"UninstallString"="cmd /q /c echo Windows Registry Editor Version 5.00>%TEMP%\\pr.reg & echo.>>%TEMP%\\pr.reg & echo [-HKEY_CLASSES_ROOT\\exefile\\shell\\Bpc]>>%TEMP%\\pr.reg & echo.>>%TEMP%\\pr.reg & echo [-HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\BpcSubMenu]>>%TEMP%\\pr.reg & regedit /s %TEMP%\\pr.reg & del %TEMP%\\pr.reg" 
"DisplayVersion"="1.1" 
"URLInfoAbout"="http://habrahabr.ru/post/317802/" 
"NoModify"=dword:00000001 
"NoRepair"=dword:00000001

Priority value list

IoPriority Value    Priority
0   Very Low
1   Low
2   Normal
3   High
4   Critical (only for memory io)

PagePriority Value  Priority
0   Idle
1   Very Low
2   Low
3   Background
4   Background
5   Normal