The Truth About Virtual Memory

Okay, class, today we’re going to talk about virtual memory. I’ve chosen this topic because there are quite a number of inaccuracies in common circulation. Here are a few false beliefs about virtual memory.

  1. More is better.
  2. There is a set rule for determining how much you need.
  3. Setting a static swap file size will make virtual memory more effective.
  4. Emptying the Pagefile will increase system performance.
  5. You can eliminate the page file if you have enough physical RAM installed.

All of these are false!!!!

I’m going to give you a brief overview of Virtual Memory, destroy these myths, and give you some good advice about how to manage it. So let’s begin.

Virtual Memory is Windows’ name for a swap file. It allocates a portion of your hard drive space for use by your system RAM. As programs run on your PC they load instructions into RAM. These instructions are then passed to the processor. The more active programs are running, the more RAM your system requires. Very often this amount is more than your physical RAM has available so some of the information is unloaded to the page file.

Windows makes an effort to keep memory full at all times. So often programs that have been closed still reside in memory. This is by design. That’s why the use of RAM cleaner programs will typically decrease system performance rather than improving it. When programs are unloaded to the page file, the oldest least used ones go first. When you’re running enough programs that active ones are moved to the page file, this is when your computer bogs down. It slows down because the swap file is only as fast as your drive seek speed and your IDE transfer which are much slower than the FSB transfer speed that your RAM uses.

The NT kernel is designed to use virtual memory. Period. Never eliminate the page file by setting your virtual memory to zero. You only hurt your performance. So the big question now is:

How much virtual memory do you need?

The answer is – that depends on what you’re doing. At minimum, you want to have the amount of physical RAM plus about 512MB. Having too little forces your system to completely unload information it needs just to have to load it into memory again later, and having too much forces your computer to attempt to fill it pointlessly. That’s why there can’t be a rule of thumb on how much you need. It’s different for every system and every user.

You want to have a dynamic page file that way it only contains useful information. However, if your system is forced to resize it too much, this makes the process take longer. So we need to determine the happy medium. How can we do that? Well, we need to determine what kind of memory usage we’re using. We can do this using the Performance tab in the Windows Task Manager. This shows all of the memory statistics for the current session (since your last reboot). There are a couple of key numbers in this display.

Physical Memory Total – The amount of physical RAM installed on your machine.
Kernel Memory Paged – The current size of your page file.
Commit Charge Peak – The total (phys + virt) peak amount of memory used this session.

With these numbers we can make a pretty good determination of your memory needs. The first step is to determine the minimal amount. You do this by checking your usage immediately after a reboot. If your peak is less than your installed RAM, then set your minimum to your installed RAM + 512MB. Otherwise, set it to a number just below the peak amount.

Then open as many applications as you would commonly run simultaneously. Internet browser, email client, office program, whatever a common “heavy” system load would be. Then check your peak again. Set your upper limit to about 512MB above this number.

This should make your page file stay at it’s smallest size while always remaining full. This is your optimum set up. You may find the need to tweak the upper limit a bit after you run your system for a while. Different combinations of running programs will change your requirements.

Creating a dedicated partition for your page file will also improve its performance dramatically. Likewise, if you frequently access multiple drives, creating a separate page file on each drive will also improve overall performance.

Emptying the page file at shutdown is a good idea if you don’t mind the additional time it takes to do so. This ensures that your system is only filling the page file with information pertinant to the current session. However, emptying it during a session will decrease performance since Windows will stop and take the time to fill it up again.

Hope these tips helped clear up a few misunderstandings. For most users, simply letting Windows manager your page file is enough, but for those of you who like to tweak out the last drop of performance from your system, this should put you well on your way.

Stop by these links for more valuable information:

NT Memory Primer
Understanding Memory Usage in Windows 2000

Tags

Like the read? Share it!

6 Comments

  • Awesome entry! This is one of the most controversial topics.

    It is quite amazing to read all of the myths debunked and the whole Virtual Memory phenomenon demystified.

    Thanks,
    Tony

  • Having too little forces your system to completely unload information it needs just to have to load it into memory again later
    Assuming 2GB of physical RAM, why would it force to unload when it can keep residing in the physical memory even when 1GB of physical memory is still available ?

    If your peak is less than your installed RAM, then set your minimum to your installed RAM + 512MB.
    Assuming 2GB of physical RAM, does this mean that we need to set the Paging-file-size to 512MB or 2.5GB ?

    Creating a dedicated partition for your page file will also improve its performance dramatically
    How is it possible to set C:’s page-file to say, X: ? By default, C:’s page-file resides in C:\Windows

  • Hi anjanesh,

    Thanks for the reply. You can change the location of the paging file from the within the System Properties control panel applet. Details can be found in the following knowledgebase article.

    http://support.microsoft.com/kb/307886

  • Will there be a seek-time-delay if the partition to where I change the paging-file location is on another hard-disk ? (but a better one – SATA2)

  • Moving the paging file to another drive or partition that is accessed less frequently than the boot partition will provide noticeable improvements. Since your secondary drive will be accessed much less, the seek time should improve over that of your primary drive–and the fact that your secondary drive is faster will be an added bonus.

  • The author does a good job of dispelling a number of myths. Unfortunately he injects a number of new myths and inaccuracies.

    First, there are the persistent references to the pagefile as virtual memory. Not only is this incorrect but it also encourages further misunderstandings. The pagefile is an important part of the virtual memory system but it is only a part. Only modified data will be written to the pagefile, not program code.

    The default setting of letting Windows manage the pagefile is best for most users. If you have little RAM you may have to raise the lower value to avoid warnings. There is no need or value in restricting the upper limit, except that the Win32 platform does not support a single pagefile over 4GB.

    There is no value in clearing the pagefile at shutdown except for security purposes. Windows will not permit this during a session.

    Larry Miller
    Microsoft MCSA

Leave a Reply

Contact

Wanna say hello?
Drop us a line!

You'll find us here

1 Microsoft Way,
Redmond,
WA 98052, United States