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.

  • 2
    +1. I am interested in a method that works for XP.
    – Xavierjazz
    Commented Jan 24, 2011 at 16:28

4 Answers 4


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.

  • Perhaps quoting this bit from the article would put it in context: "Locking pages into memory may degrade the performance of the system by reducing the available RAM and forcing the system to swap out other critical pages to the paging file. Each version of Windows has a limit on the maximum number of pages a process can lock. This limit is intentionally small to avoid severe performance degradation." (My emphasis)
    – user3463
    Commented Mar 19, 2011 at 19:04
  • 1
    @Randolph: I never recommended it, I just mentioned that, unlike what most other people seem to think, it's possible. I personally just hate telling the OP "Let's kill your idea" -- I think the OP's understood that the fact that he shouldn't do this, but if he still wants to, I think he has the right to know how to. (There's a reason they created these functions, and I'm not the person to judge whether the OP should use them or no.)
    – user541686
    Commented Mar 19, 2011 at 19:05
  • There is a lot of code in Windows that was left in for backward compatibility. If there is a reason for having it, that would be it. One could compare it to the Shrink feature in SQL Server, which should not be used under any circumstances, but was left in for compatibility reasons. Windows 7 is a modern OS with proper memory management, and the page file should not be deleted, nor should programs try to stay in memory outside of the "rules". It's very poor practice and can result in an unstable and / or unusable system.
    – user3463
    Commented Mar 19, 2011 at 19:12
  • 1
    @Randolph: (I see you abandoned the analogy. :] ) Make a tiny program (shouldn't be more than ~10 lines) to open the other process and call SetProcessWorkingSetSize. That's one way. If course, if you don't know what that means because you're not a developer, then obviously there's not much you can do. But it's still possible, and saying it's impossible is still incorrect, it just requires more knowledge than the OP might have.
    – user541686
    Commented Mar 19, 2011 at 19:27
  • 1
    @Randolph, you can download various freeware apps that force running apps to all go to the pagefile (by calling SetProcessWorkingSetSize in each process).
    – Chris O
    Commented Mar 19, 2011 at 19:29

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.

  • 3
    Do. Not. Delete. The. Page. File. Ever.
    – user3463
    Commented Jan 24, 2011 at 22:42
  • 7
    I. Have. Been. Using. Win7. With. No. Pagefile. For. Months. Without. A. Hitch.
    – mtone
    Commented Jan 24, 2011 at 23:19
  • 1
    I also use Win7 without page file all the time, however it seems to me that it might be not enough for my current work :(
    – Darqer
    Commented Jan 25, 2011 at 0:10
  • 3
    @Randolph: MS knows what they're talking about, because they know that their customers aren't exactly always computer pros. But for those people who actually know exactly what the pagefile does and doesn't do, there's no reason to force them into a practice that they don't need.
    – user541686
    Commented Mar 19, 2011 at 4:47
  • 2
    @Randolph: If you drive over the speed limit without a seatbelt, you can die and also kill other people, not to mention increasing the insurance costs for others. The worst that can happen if your computer pages out its memory is that you'll just lose a bit of time, depending on the situation. Don't you see something a little (read: a lot) wrong with the analogy here? Also, have you used Linux/Unix? Ever noticed how they give you more than enough rope to hang yourself with, unlike Windows? People still use them -- is that like driving under influence or something?
    – user541686
    Commented Mar 19, 2011 at 19:08

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.

  • What's the registry key to control swappines in windows?
    – DustWolf
    Commented Jun 17, 2022 at 13:51

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .