How do you set memory priority (not cpu priority) on windows

5,658

Solution 1

As far as I know there is no way to make sure a process stays in memory on Windows. There is a Win32 API called VirtualAlloc() that will allocate memory in such a way that the memory manager won't try to push it to disk. This have to be coded into the application and can not be set by any program as far as I know. You will probably have much better results by increasing the amount of ram in your computer.

Solution 2

In Windows the MM will only page-out pages that are not being accessed for some time, also when "Context switch" happens your code will stop running.

It sounds like you either need to write your code in the kernel in High IRQL and access only none paged memory which is a very bad idea, or change the target OS to a real time OS.

Solution 3

You can set memory priority with SetProcessInformation:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh448389(v=vs.85).aspx

I have hit problems with working-set draining in processes that accidentally got set to low memory priority in several cases. It's not fun. The restart manager and task scheduler can both end up doing this.

Share:
5,658

Related videos on Youtube

Not a Name
Author by

Not a Name

Hello World!

Updated on September 18, 2022

Comments

  • Not a Name
    Not a Name over 1 year

    I need to know how to change "memory priority" of a process. I need a utility that changes the memory priority of the process. Certain ram intensive programs can still make my important programs freeze up by sending them to the page file. I need to stop this, and I need to be able to select the EXACT priority of any program. Additionally I am using windows vista.

    For reference, I googled, found nothing. Please note that this is not "process priority" or cpu priority. Anyone know of a free tool which does this?

  • Jamie Hanrahan
    Jamie Hanrahan over 8 years
    This answer is correct. I will add that the use of VirtualAlloc to allocate nonpageable virtual memory is a particular option on VirtualAlloc; its use is quite rare, it is somewhat awkward to use, and there are severe restrictions on how such virtual memory can be used by the process. It applies not at all to code, stacks, or heaps, for example. So it doesn't get used much.
  • Bruce Dawson
    Bruce Dawson about 6 years
    This is correct for processes with normal memory priority, but it is incorrect for processes with low memory priority. In the low memory priority case the working set will be drained in a few minutes. Once the working set is drained to the standby pool it is vulnerable to being paged out due to disk activity. SetProcessInformation can be used to set memory priority.