Ask Leo! by Leo A. Notenboom

How should I configure my swap file / virtual memory settings?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

Home » Windows » Windows Configuration

Summary: The default setting for virtual memory are typically good enough for most. Tweaking virtual memory settings depends on your computer and what you do.

I have Windows XP Pro SP2 MCE with 2 gigabytes of RAM, to which I just added a 500 MB hard drive to the original 250 MB HD. The new drive is now the primary. Both are 7200 rpm SATA. What do you recommend for a swap file? The "3X RAM" rule of thumb doesn't make much sense. It should be bigger with less RAM, not more. It's currently set to a 2 GB minimum and 4 GB maximum size on the C: drive partition. What size should I set it to, should it be on a different partition, and should I give it its own partition? I will be doing a lot of scanning and Photoshop, if that affects the answer. It's my understanding that a fixed size reduces fragmentation (or at least makes defragmentation easier). I've also seen suggestions for making the swap file an entire partition. (I have Partition Magic.) Would putting it onto the second drive improve read/write speeds? The second drive will be for backing up data files and not in constant use.

You're asking a lot of good questions, and providing a lot of the right kind of data from which to make some recommendations.

I've written about Virtual Memory a time or two already and it does seem like so much voodoo to many people. The same is true for figuring out what to do with it.

But if you're trying to eke out a little more performance from your machine, then it's possible that a couple of settings might help.

First, realize that your swap file really only becomes a performance bottleneck if your system has used up all of your available RAM. There are two important take-aways from that statement:

  • The best way to maintain performance is to make sure you're not trying to use more RAM than you actually have. Run Process Explorer and watch Physical Memory in the System Information viewer. If "Available" becomes small or zero, then consider running fewer programs at once if you can.

  • If you're not using all of available memory, then tweaking your swap file settings isn't going to buy you a whole lot, because it hasn't really come into play.

So let's say that you're running only your image editing software, and you've closed all the other programs that it makes sense for you to close, and you start editing that massive masterpiece. Your available physical memory goes to near zero, and you can hear the hard disk start thrashing as the swap file starts being used heavily.

Now it's time to tweak those settings.

"... there's nothing at all wrong with having a swap file that's too big ..."

I'm not really sure where the "three times RAM" rule comes from. It certainly doesn't apply in all cases. As you point out, machines with less memory may need more swap space or virtual memory in order to be able to run some applications. On the other hand, machines with sufficient RAM typically need less swap space since there's enough RAM to do the job. Sometimes they don't need any swap space at all.

Without knowing how a machine is used I typically set up along these lines:

  • Machines with less than 1 gigabyte of RAM: I set swap space to be roughly three times RAM.

  • Machines with between 1 and 2 gigabytes of RAM: I set swap space to be about twice RAM or perhaps less.

  • Machines with 2 gigabytes or more: I set swap space to be the same as RAM, or sometimes one gigabyte, though there's even an argument for setting it to zero in a case like this.

Note though that I prefaced that with a caveat: I don't know how the machines are being used. This is just a gut-level estimate for average use.

Now, if you want to save time, there's nothing at all wrong with having a swap file that's too big aside from the disk space that it might use. It sounds like you have plenty of disk space, so you could save yourself a bunch of time and just set the swap file to a fixed, maximum size and get on with your life.

If you want to do the analysis, though, then what I would do is set the swap space to be large, run Process Explorer, and watch commit charge in the System Information viewer. Now run your memory intensive program.

Commit Charge will give you a good upper limit of how much memory your system is attempting to use. Subtract from that maximum value the amount of RAM you have and you'll get a reasonable approximation of how much swap space you need. I'd probably round that up by a healthy amount, just to be safe.

For example if on my system with 2 gigabytes of RAM my commit charge ended up being something like 3650meg (3.6 gig, roughly), then I'd subtract off the 2 gig to come up with about 1.6gig. I'd round that up and set my swap space to 2 gigabytes.

If your system does end up using the swap file frequently, placing the swap file on another drive can indeed improve speed. With your system and data files on one drive and the swap file on another, a single hard disk isn't trying to serve up both, and things like disk head movement can be significantly reduced, thus serving up each file more efficiently.

Finally, defragging the swap file can be a problem. It's not done by the normal defragging tools, because the swap file is "in use" while your system is running. You can use the free utility PageDefrag to defragment your virtual memory. (Synonym overload: in this context "paging file" is the same as "swap file" which is the same as "virtual memory".) And yes, once you set it to a fixed size and defrag it, you shouldn't need to defrag it again.

Related:

Helpful? Get new articles weekly by email in my FREE newsletter!

Your Name:
Your Email:


Why Subscribe?

Article C3062 - June 20, 2007

Recent Comments
10 Comments

The best way to defrag a swap file is to set it to 0, restart, set it back to whatever, restart. Nothing in it needs to be saved.

Posted by: Dan Ullman at June 21, 2007 9:18 AM

Hi, just a tip: you can also use Diskeeper Pro to defrag your paging file by running a boot-time defrag during which it defragments the paging and other system files. Apparently, this is the method Microsoft recommends. Anyways, even for normal defragging of your drives, diskeeper is a great program with lots of very useful performance and scheduling features that the Windows Disk Defragmenter unfortunately lacks.

Posted by: Arena at June 21, 2007 11:19 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dan: Not quite true. If there's no contigous space available to hold the swap
file, it'll be fragmented from the start. (It's possible that even if there is
space somewhere that's large enough the swap file may still be allocated
elsewhere and start out fragmented - though I'm not totally certain on this.)

Leo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)

iD8DBQFGez4BCMEe9B/8oqERAu+2AJ43+KS5PfmkwCBMiOZdSyXj6SQ7pwCfQZbI
4+Y0nBr5rVBCyzgtxfz3GsY=
=IGNx
-----END PGP SIGNATURE-----

Posted by: Leo A. Notenboom at June 21, 2007 8:12 PM

I moved my swap file onto another drive over a year ago & have never had any problems with my setup. I have 768 ram & a 4 gig swap file on the FIRST partition on my second drive. By having it on the FIRST partition of a drive the seek time is quicker as the heads don't have to travel as far to reach the partition.

Posted by: David Burlakoff at June 22, 2007 6:31 PM

No useful comment but to prove I read the article -- it should be "eke" not "eek" and "editing" not "editting". Sorry, I'm an editor :-) (and you can delete this once you fix the errors, if you want).

Posted by: dunstergirl at June 22, 2007 9:17 PM

My defrag play in w98 is to set the swap file to 0 in "safe mode", defrag, re-set the swapfile to 500mb minimum with no maximum...this tends to put it at the end of the drive where frag doesn't occur as quickly...am I wrong?

Posted by: Wayne Scharf at June 22, 2007 9:19 PM

" Posted by: David Burlakoff at June 22, 2007 06:31 PM: I moved my swap file onto another drive over a year ago & have never had any problems with my setup. I have 768 ram & a 4 gig swap file on the FIRST partition on my second drive. By having it on the FIRST partition of a drive the seek time is quicker as the heads don't have to travel as far to reach the partition."

Thats a good suggestion. That is the setup I use too. I have 1 GB RAM and XP is installed on the first partition of drive 0, and my swap file is on the first partition (small one) on drive 1.

Posted by: Arena at June 23, 2007 3:39 AM

With hard drives as large as they are now, is there an advantage or disadvantage to setting up a swap file that equals with RAM the max memory your 32 bit system can handle (4 GB). Therefore your physical RAM and your static swap file would always equal 4096 MB's (4 GB).

Posted by: Richard Dore at March 18, 2008 11:52 PM

it's great it helps me too much..

Posted by: Archie at August 28, 2008 5:42 AM

You need minimum 50Meg of Swap file for some programs to actually work properly.

You can also set Min and Max to the same value, reducing fragmentation of the swap file.

The swap file ideally should be placed on another drive (not another partition, just in case)

Even with high amounts of Ram (over 3Gig) you can still have a reasonable swap file (say 2Gig Min and Max)

No one seems to have a definitive guide on what amounts to place in the Swap File, as it depends on what you run.

:)

Posted by: KimslanD at September 4, 2008 12:07 AM

Post a comment on "How should I configure my swap file / virtual memory settings?":






(Email Address will not be published.)

Remember Me?

By popular demand...
my tip jar
Cuppa Joe
Buy Leo a Latte!

(you may use HTML tags for style)

RSS feed Subscribe to the RSS Feed specifically for comments on this article.

Before commenting, please...

  • Read the article at the top of this page. If your comment shows you didn't, it'll be deleted and ignored.

  • Comment only on this article. Use the Google search box at the top of the page if you have a question about something else.

  • Don't include personal information in the comment. No email addresses. No phone numbers. No physical addresses.

  • Don't spam. Excessive links to unrelated sites within a comment or across multiple comments will cause all such comments to be removed.

  • Don't ask me to recover lost passwords or hacked accounts. I can't, and those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...


Question? Ask Leo!