Managing the Windows Swap File What is the Swap File? To execute a program in Windows, it first needs to be loaded into memory (RAM). Windows lets you run multiple programs simultaneously and chances are that they won't all fit into memory at the same time. For that purpose, Windows uses what is called Virtual Memory to simulate RAM, pretending it has more memory than what is actually build into the PC. It does this by moving data from real memory to a special file on the hard drive, called the swap file in Windows 95/98 or page file in Windows NT. This, in effect, allows Windows to address more memory than the amount of physical RAM installed. Without it, we would not be able to run windows on machines with limited RAM. For example, think back to when Windows 95 first came out, the average computer had 8 to 16 Mb of Ram. It would not have been possible to run Win95 and applications without using virtual memory. Program code and data are moved in pages (memory allocated in 4K or 16K segments within a 64K page frame) from physical memory to the swap file. As the information is needed by a process, it is paged back into physical memory on demand and, if necessary, windows may page other code or data to the swap file in its place. The Windows Managed Swap File Grows and Shrinks By default, windows manages the swap file dynamically, meaning that Windows increases and decreases its size as needed. For most users it is recommended to let Windows manage it to ensure that there is always sufficient memory addressing for applications and processes. The advantage of a dynamic swap file is that it does not permanently make hard disk space unavailable, it can only grow if there is sufficient disk space. When you shut down, the swap file is being deleted. It is re-created again when Windows is started. The disadvantage of a Windows managed swap file is that it becomes fragmented, and performance can be lost due to frequent resizing as your computer is performing memory intensive tasks. Fortunately, educated users of Windows can specify their own virtual memory settings if they deem it necessary. Specify Your Own Virtual Memory Settings You access these settings from within the System Control Panel applet. The easiest way to get to that from the Desktop is to right click on the My Computer icon and choose Properties from the menu. Another way is to click Start/Settings/Control Panel/System. Click the Performance tab and click the Virtual Memory button. If you see this for the first time, the option "Let Windows Manage my virtual memory" is probably selected and the other fields are grayed out. Click the "Let me specify my own..." and choose the drive you want to put your swap file on by clicking the drop list in the Hard Disk field and state the minimum and maximum swap file size in the appropriate fields. But What Settings Should I Specify? Most importantly, you do not want Windows to run out of memory, so make sure that the size you specify will be sufficient. Base your decision on how much RAM you have, and how demanding your applications are. A good way to get a handle on this is to monitor free physical memory, swap file size, and swap file in use. Install System Monitor from Add/Remove Programs in Control Panel. Click the Windows Setup tab and highlight the System Tools category and click details. Put a check in System Monitor and click OK and then OK again. You will be prompted to insert your Windows CD. After you get System Monitor installed, open it by going to Start/Programs/Accessories/System Tools and go to Edit and choose Add Item. Click the Memory Manager Category and choose the items above. Use this utility for a while to monitor what Windows is doing while you run your applications. Choosing the Drive If you only have one hard drive, obviously there won't be another one in the list to choose from. In general, choose the fastest drive for your swap file. If you have a second hard drive, and it is on the Second IDE controller (Secondary Master or Secondary Slave) you should choose that drive for your swap file to reside on. The reason for this is, modern Dual PCI IDE controllers on Pentium motherboards allow simultaneous access to two drives on separate IDE channels. The technical term for this is Peer Concurrency. Drives on the same IDE channel cannot be accessed simultaneously (and also, the read/write heads on a single drive can't be in two places at once). The benefits of having your swap file on a drive on the second IDE controller should be obvious: Windows will be able to work from the C: drive AND page to and from the swap file on the other drive at the same time! If your system uses the swap file often, this will increase performance significantly. Setting the Swap File Size There are advantages to setting a fixed swap file size (that is, equal minimum and maximum settings). The swap file will be a static size, which means that it can occupy contiguous cluster chains and not become fragmented. Another advantage is that since it is always the same size, Windows doesn't have to take the time or resources to resize it. This will improve access time. The disadvantage of a fixed size swap file is that it cannot grow beyond the maximum if the need arises. (Can you say "crash"?). If you want to have the best of both worlds, a swap file that doesn't grow and remains contiguous, yet can be increased if you inadvertently bite off more than you can chew performing some memory intensive graphics editing operation or something, then choose a minimum size that is large enough that it will never need to be increased. For example, if you set a minimum of 128 Mb and a maximum of 500 Mb, you should never see the swap file size increase, but more will be available to Windows if something screwy happens. Again, System Monitor is an excellent tool to use in making this decision. Where is My Swap File? In Windows 95/98, the swap file is Win386.swp and is located in the Windows directory if you are using a Windows managed swap file. If you are specifying your own settings, it will be in the root directory of the drive you chose to put it on. In Windows NT, the swap file is called pagefile.sys. In Windows 3.1, if it is a dynamic swap file it will be called win386.swp and if it is a static swap file it will be called 386spart.par and be located in the root directory of the drive that windows 3.1 is installed on. System.ini - The Real Swap File Settings The settings for the swap file are actually under the [386Enh] section in the System.ini file. You can actually override the swap file settings here, if you prefer. Here is a typical [386Enh] section, note the last three lines pertaining to the swap file. Note that the values for min and max are in KILOBYTES in the system.ini file. (not Mb like the setting in system properties) [386Enh] ebios=*ebios woafont=dosapp.fon mouse=*vmouse device=*dynapage device=*vcd device=*vpd device=*int13 keyboard=*vkd display=*vdd,*vflatd PagingDrive=C: MinPagingFileSize=65536 MaxPagingFileSize=395264 If you decide to edit the system.ini file, be sure to use upper and lower case exactly as it appears. It matters. For example, pagingdrive=c: is NOT the same as PagingDrive=C: (in fact, there is an issue in Win98 Second Edition where the computer hangs if a lower case drive letter is specified for the paging file location...but that's another story). The settings shown here are for a swap file on drive C: with a minimum size of 64 MB and Maximum size of 386 MB. (multiply each MB value by 1024 to get KB) Conclusion You can improve performance by specifying your own Swap File settings. This is particularly significant if you have less than 64 MB of RAM and Windows is using your swap file frequently. If, however, you have a nice fast hard drive and a large amount of RAM (like 128 MB or 256 MB) then little will be gained by changing the swap file settings from Windows managed. If your swap file is rarely used, then the fact that it is of variable size and fragmented will not degrade your computer's performance appreciably. A little tip for good measure: If you ever copy a hard drive's contents or the directory that contains the swapfile using Windows Explorer, be sure NOT to copy the swapfile. If you do, most likely Windows will crash. http://www.PCNineOneOne.com