How to control RAM / swap usage

Is there a way (application) to control RAM / swap usage policy at application level.

I have some applications that I use all the time and I want them to stay in RAM all the time and there are also application that I use quite seldom and they might be thrown to swap at demand. I know that default configured windows should give me best performance but I want to check whether I can get more :).

I use windows 7.


Yes there is: have the program call the VirtualLock function:

Pages that a process has locked remain in physical memory until the process unlocks them or terminates. These pages are guaranteed not to be written to the pagefile while they are locked.

I believe the SetProcessWorkingSetSize function might also be helpful.


For those people thinking I'm a heretic for even suggesting that this might be useful:

Notice that there are can be valid reasons for locking pages in memory. A valid reason might be that the user is running a CD burner, and the CD burner constantly pages out and hence causes a buffer underrun, creating a coaster. In that situation, It would be valid to lock the memory buffers so that they aren't paged out, even if that means the rest of the computer slows to a crawl, because that's still better than giving the user a coaster. There can be other valid reasons too -- my point is, while it's usually not recommended to lock pages in memory, valid situations still exist, and I don't think killing the idea would help the OP here.


Update: Take a look at Process Hacker's Reduce Working Set menu option.


The only way I found is to disable the page file. However it's not a perfect solution: you will get error messages if you go near or over your RAM limit, and it may not save crash dumps properly, so turn it back on if you need to troubleshoot. Other than that, I have been using Win7 with no pagefile for months without a hitch.

My experience: I had this problem with a piano software (1GB RAM usage) which would be throw into swap after not being used for a while. Playing a piano key a few hours later would result in a glitchy mess since the swap would not be reloaded fast enough for the sound to play. (I would then put my whole arm on every key to force a reload!)

If RAM is a concern, I suggest you buy more (eg. 8 to 12GB with Windows 7 x64). For the RAM-conscious, having plently of RAM is a godsend.

But before, you should consider getting a SSD drive and putting your swap on it. It will accelerate swap recovery greatly, as well as providing many other system benefits. RAM does not provide benefits when not in use.


Page file usage depends on a lot of factors. If you use a lot of programs and don't have enough RAM for all of them at the same time, then parts of them (or all) may be swapped out to the page file.

If you have 4GB of RAM and let's say around 3GB of it is available due to video cards and other resource users blocking out parts of the 4GB, and you only use a few programs that don't take a whole lot of memory, theoretically you should never need a swap file. However, Windows Vista and 7 are notoriously aggressive in their swapping of programs to disk.

I used to have a setting that reduced the swappiness of Windows 7 (swappiness is a Linux term but it applies to Windows just as well, and since there is a registry setting to tame Windows swapping aggressiveness it seems Microsoft agrees grudgingly, albeit in a well hidden manner), but I cannot seem to find it anymore. Searching for it is how I ended up here. The best alternative to this setting that I have found is to make sure that you use a fixed size swap file (I go for 4096-4096 on 32-bit OSes, and 12GB on 64-bit ones as I have 6GB of system RAM) on a dedicated partition. Having a spare 7200rpm 200GB drive, I place all of my swap partitions (windows XP, 7, 7 64-bit and various Linuxes) on this drive. It seems to work for me, but YMMV.


Worth mentioning: when windows detects you're frequently using certain applications, it has the superfetch put those apps into memory so they'll load faster. I think trust windows to do its thing here.