On Windows 2000/Xp

And Virtual Memory

The Technical Files
Single Drive Computers
2 or more drives
Raid Configurations
All Computers
Example
History
Common Misconceptions
Helping Software
How Do I Do It?
Final Conclusions
Footnotes
I once did some research into Windows 2000/XP and Virtual Memory.  This article was originally written as an answer to a question on the subject at the TechTV Call For Help message board.  The question inspired me to read up and learn all I could find about it.  I have since expanded on and reformatted it for this page.  You can read this whole article or you can skip over those parts that don't pertain to you.  The asterisks for the footnotes are also linked to make reading easier.  I've also made it so clicking on each heading brings you back to the top of the page. So you can skip around without a lot of annoying scrolling.

On single drive computers
The swap file works best when it's located either close to the beginning of the drive or where there is expected to be the most drive head activity.  When the drive reads or writes data, it moves the heads to the location where it must do it's work.  But then it does not move the heads away from that area when it's done.  If the swap file is located close to the area where the heads are most often doing work, then the heads have less travel distance and thus less travel time to get to the swap file.  It is not recommended to place the swap file in a separate partition in the NT kernel since this places the swap file away from the areas of other activity.  Thus, the heads have to travel back and forth from one partition to the other.  In XP, the swap file also provides double duty as a memory dump location in case of an unrecoverable crash.  This memory dump allows for a post mortem analysis to find the cause of the crash and is sometimes the only way to discover what went wrong.  Please note, however, that not just anyone can read this file the NT kernel creates it.  There are few outside of Redmond VA. who can make sense of the information in this file, and most of them charge for this service.  This feature is therefore mostly for businesses who have a stake in finding the root cause of a cataclysmic error and correcting it.  The cheaper, quicker, and easier way for the rest of us to deal with cataclysmic crashes is to simply do a repair install or a clean install of the OS.*  This memory dump must be onto a swap file located in the same partition as the OS and the swap file must be large enough to receive this data.  Which means that in order to have this feature, you must have a swap file on your OS partition anyway.  The argument that the swap file should be the only file in a partition for faster access is no longer valid with Windows 2000 and XP since it's disk location is stored in memory.  The master file table is accessed only once for the location of the swap file.  After that, the OS never again reads the MFT unless it must increase the size of the swap file.  More on that later

With 2 or more drives
First, see above for reasons why you should have one swap file on the primary drive with your OS.  Beyond that, there is no sense in having a second swap file if your second drive is set up as the slave.  When there is a read/write request to the slave, it must wait for the master drive to release control of the data bus before it can honor any requests.  This translates into a noticeable performance loss if the computer has to wait for the master drive to finish before it can access the swap file on the slave drive.  However, if you set both drives up as the master on 2 different channels, then there is no performance loss.  In fact, having 2 master drives with a swap file on each is the most desired configuration in terms of performance and swap file usage.  Microsoft claims that Windows XP optimizes swap file usage in this configuration for optimum performance.  So it can read an executable file from one disk while simultaneously writing to the swap file on the other disk.

RAID configurations
Although you can get extra performance out of a swap file on a 2 disk raid, the performance gain is not nearly as much as one might expect.  This is because RAID primarily outperforms single disks in sequential reads and writes but holds little or no performance improvement with any other read/writes.  The swap file usage is not limited to sequential reading and writing.  However, RAID performance becomes stellar when there are more than 2 drives in the array.  But the hardware support for this is generally more expensive.  Software RAID support performance is typically far below that of a single drive in all areas.  So, unless you have a RAID with more than 2 drives, your performance is little better than a single drive.  Don't expect large performance gains from placing a swap file on a typical RAID with only 2 drives.  However, since Windows XP can manage 2 swap files, if one is one a RAID, it should have about the same performance gains as having one on a second drive set up as the master on a second channel.

For All Configurations
My swap file size recommendation is 1.2 Gigabytes minus whatever your physical memory size is.  This is the high end of many recommendations but within the safety margin of most users.  Windows XP prefers to have at least 1 Gigabyte of total memory at it's disposal.  Use your best judgement with your systems needs.  If you do little multitasking and have few running processes and programs, then you can reduce the amount of total memory available to your system accordingly.
So if you have 512MB of Ram installed then your swap file should generally be about 1228MB - 512MB = 716MB.  It can be larger if you have a large drive with a lot of free space and it can be smaller for those drives with little free space available or if you find you simply don't need that much virtual memory.  But in all circumstances, the minimum swap file size should be no less than what Microsoft recommends for the type of memory dump, if any, you specify. See Here for further details.  You can specify what kind of memory dump you want with XP at the Startup and Recovery section in the Advanced Tab in the Properties of My Computer.  Others will set their virtual memory at 256MB or some arbitrarily low figure and let Windows adjust it's size up from there.  However, by doing this, they also make it suseptible to fragmentation.  Fragmentation is when the file is no longer in one continuous block, but rather gets broken into smaller blocks with intervening files stuck in between.  This makes the heads move more from one small block to the next and thus degrades performance. One way to help prevent fragmentation is to set the swap file immediately after a clean install and make it a permanent fixed size.  However, one must consider the fact that doing this precludes XP from adjusting the size to fit it's needs.  Resulting in either wasted disk space if it's too large, or "ram cram" if it's too small.  But this is the price one would have to pay for consistently improved performance.  Use your best judgement.
Placing a separate partition for the swap file on the primary (boot) drive is redundant since you also need a swap file in the bootable partition anyway if you plan to use any of the memory dump options.  It also slows down access time as it moves the swap file away from the rest of the drives activity.  The general idea is not to create two swap files on the same physical drive.  Therefore, you can partition your boot drive with a single partition.  Unless, of course, you have some other reason for creating a second partition that is unrelated to the swap file. This also applies to the second drive as well.  Don't bother making a separate partition just for the swap files.  It will only slow performance down and will do nothing to improve stability**.
There is one other alternative that I have not explored yet.  That is not to have any memory dump at all.  This eliminates the need for having minimum partition size and also reduces the need to have the swap file located in the boot partition.  However, I still recommend having the swap file in the boot partition because of the performance losses of moving it away from the rest of the activity.

Example
Let's assume you have 2 hard drives, plan to use the Kernel Memory Dump on your system, and you have 512Meg of physical ram so you need a minimum of a 512/3=171MB swap file on your primary boot drive.  Now lets assume you plan to create two swap files.  One on each of your physical drives.  I have heard several recommendations stating that each swap file should be the same size.  Several people have reported improvements in both stability and performance when both swap files are the same size but this recommendation has never been tested or measured.  But let's go with this because no harm can come of it.
So, we want a 1228MB of total memory available.  1228-512 of physical ram leaves 716 meg of total swap file size.  Breaking this into two swap files means we want a 358MB swap file on each physical drive.  Checking with the the memory dump requirements shows us that this is over twice the minimum required for the memory dump method you chose.  In fact, this is a very good time to consider making them permanent to prevent fragmentation.  We even have some room to reduce their size if you wish.  For instance, if you really only want 1GB of total memory, then you can safely go with 512MB physical and 2x256MB swap files.
Now, all raid controllers will have their own channel.  So both a primary drive and a raid drive would be on separate channels and both would be the primary drive for their respective channels.  This configuration will have near optimum performance.  On the other hand, most people will have a second hard drive and a CDRW or DVDR or RW drive on their second IDE channel.  In this case, they will have to make a choice either:
having a 2nd swap file on a master drive, and having the CD drive as a slave.  This will reduce performance of the CD drive and possibly burn a coaster or two.  But system performance is maximal in this case.
Or,
Having a 2nd swap file on a slave drive and having the CD drive as the master.  This will degrade performance somewhat while the CD drive is working but the CD drive will not burn coasters because of it.
Or,
Placing a single swap file on the boot drive and leaving the second drive alone.  This, of course, is the slowest and the most stable bet for those who regularly watch movies and burn CDs or DVDs.

Back in the Day
There's a lot of conflicting information out there on this subject.  Some people insist on it being in a dedicated partition and other insist on it being in the Windows directory.  The reason for this conflict is history.  The swap file on a FAT system was accessed faster and was most stable when placed in it's own partition.  In the days before Win98 the computer did not have the means to store disk locations in memory.  Windows 95 had a very rudimentary way of doing so, but it was'nt until windows 98 that they started getting it right.  So a drive always had to read the FAT (file allocation table) before going to the file.  The heads had to move to the beginning of the partition and then out to each file.  Fragmentation was even worse since it forced the heads to go back to the beginning of the partition to get the next location of the file and then back to the file, and so on, and so on for each file fragment.  Placing the swap file in a dedicated partition meant no fragmentation, and little movement from the FAT to the file and back, thus improving performance.  FAT also was suseptible to lost clusters and cross linked files.  When a file was written to the disk, the head had to update the File Allocation Table.  But sometimes, used clusters got overwritten or the FAT was not updated.  This problem was reduced if the swap file was the only file in the partition.
But the NTFS format eliminated the need for extra stability and storing the disk location of the swap file in memory eliminated the need for accessing the FAT, or the Master File Table as it's called in NTFS partitions.  In other words, there was a valid reason to place the swap file in it's own partition, but that is no longer the case.
But a lot of 'old timers' are still out there recommending that you put it into a separate partition.  Either they have not updated their research into this opinion, have not brought themselves to trusting the NTFS system, or are too stubborn to change their previously well researched opinion.  And I don't blame them.  15 years ago, when this debate raged the first time, people spent a lot of time and effort researching and debating this subject and I'm sure many do not wish to do it all over again.  I personally was one of these 'old timers' until I took the time to do the research.

Common Misconceptions
The following are common mistakes that everyone else is recommending and why they are mistakes.

If you have not noticed already, this article essentially refutes the 'hard and fast' rules that are commonly bandied about by technitions. Decisions about the swap file are not simple cookie cutter decisions that will work the same for all machines. I am attempting to give you all the information you need, but you need to do your own thinking.


Helping Software
I was lucky enough to find a small software program that will help you users of Windows XP and 2K. This little program will tell you what your maximum swap file usage is. Those of you familiar with the Task Manager already know how to calculate this. But for the less technically savvy, this program will make it easy to see how much of your swap file you are using. After a few weeks of normal use, you can use this information to adjust your swap file size according to your needs.
So how do I do it?
Now that you have put some thought into what you plan to do, this is where you find out how to do it.

Changing the Page File's Location and Size

If necessary, defragment the hard disk that you'll be using for the page file.  Then follow these steps to change the hard disk that Windows XP uses to store the page file as well as the page file sizes:

  1. In 2000's Control Panel, click Performance and Maintenance, and then click System.  In the System Properties dialog box, on the Advanced tab, under Performance, click Settings.
  2. In XP's Control Panel you click on System, choose the Advanced Tab, then click on the Settings button. Then you click on the Advanced tab and click the Change button under Virtual Memory.
  3. In the Performance Options dialog box, on the Advanced tab, under Virtual memory, click Change. The Virtual Memory dialog box opens, as shown below.

  1. Select the hard disk drive you want to use from the Drive list.
  2. Select a page file size option you wish to use:
    • Custom Size—Choose this option to set your own page file sizes using the Initial Size (MB) and Maximum Size (MB) text boxes.  Make sure you enter a maximum size that's equal to or larger than the initial size.
    • System Managed Size—Choose this option to let Windows XP manage the page file sizes for you.
    • No Paging File—Choose this option to disable the page file on the selected drive.  It is not recommended to have no paging file at all.
  3. If you want to split the page file over a second drive, set the original drive as you want and then select the second drive, and choose either Custom Size or System Managed Size to create a second page file on that drive.  If Custom Size is specified for either or both drives, set the new values now, and then click Set.
  4. Close all the dialog boxes.  If you changed the drive, or if you decreased either the initial size or the maximum size, you need to restart your computer to put the changes into effect.

To determine whether the page file is defragmented, run Disk Defragmenter and analyze the partition that contains the page file.  View the analysis report and, in the Volume Information list, find the Pagefile Fragmentation item.  The Total Fragments value tells you the number of fragments used by the page file. If the page file is severely fragmented and simply restarting windows does not solve the problem, then you can defragment the paging file.

Defragmenting the Paging File

As Windows XP dynamically sizes the page file, it's possible that it can become fragmented, resulting in a small performance loss.  But if you want the best performance from your computer, and a simple restart does not resolve the problem, then you should probably defragment the page file.  I usually don't recommend doing this since it will move the page file to a location after all the other files on your drive.  This puts it away from the normal drives activity and will cause the drive heads to move a greater distance, decreasing overall speed.  But sometimes this is better than a highly fragmented swap file.

Unfortunately, Windows XP Disk Defragmenter tool does not defragment the page file.  To accomplish this, you have to temporarily move or disable the page file. Here are the steps to follow:

  1. Open the Virtual Memory dialog box as described in the previous section.
  2. You have two ways to proceed:
    • If you have a second hard disk drive on your system, first set up a page file on the other hard disk drive using the same initial and maximum values of the original page file.  Then select the original drive, select Custom Size, and reduce the initial and maximum sizes to 0 for the page file.
    • If you have only one hard disk drive, note the current values, and then select No Paging File to disable the page file.

  3. Restart your computer in safe mode by pressing F8 at the inital (text only) screen. If Windows starts to load, then you missed it. From the text menu, select Safe Mode.
  4. Defragment the hard disk drive that contained the original page file.
  5. Open the Virtual Memory dialog box and restore the original page file settings.
  6. Restart your computer.

Final Conclusions
There are a few simple rules that one can abstract from this article. Following these rules may get complicated, but the results will always work best for your computer. These are listed in order of importance; from most critically important to simple recommendation.
  1. Never have more than one partition on the same physical drive.
  2. Always have a swap file on the same drive as the rest of Windows.
  3. Never create a separate partition for your swap file.
  4. Avoid putting a swap file on a slave drive
  5. Size your swap file at least 1024 Megabytes, I recommend 1280 Megabytes minus your physical memory. But the minimum needed for your memory dump, if any, trumps this rule.
  6. Make them a fixed (permanent) size
  7. Try to keep multiple swap files about the same size

Click on the red asterisk for each footnote to return to your place in the main article.


* If you really want to, you can learn how to debug a cataclysmic error yourself by studying the Microsoft website articles starting with http://www.microsoft.com/whdc/ddk/debugging/default.mspx?gssnb=1.  Microsoft does not make it easy to follow all the links and people often get lost in the labyrinthine structure of their support site.  However, persistence does have it's rewards.

** Please note that this was not always the case.  Back in the Win 3.x days, this was a good idea for improved performance and drive integrity.  Under the NTFS file system, it only slows things down.  But you will find plenty of old timers who still recommend it for new systems.  Back then, the benefit of doing this was obvious and easily verified.  See Back in the Day for more information about this.  

Many people with 1+GB RAM have tried to eliminate the swap file entirely and have reported serious performance loss.  I have never heard a good explanation as to why that is, but trying to go without virtual memory in XP is a an obviously serious mistake. However, people have reported that the more physical RAM they have, the less virtual memory their system uses.  So yes, you are safe in reducing the amount of virtual memory you use as you add RAM.