Swap file optimization?

Dennis Faas's picture

Speaking of Windows optimization, Infopackets Reader 'Harkatcan' asked me a very interesting question the other day that dealt with the Windows Swap File.

" Dear Dennis,

How can I get my swap file to empty when I start my computer? When my system boots up, a dialogue window appears and reports that I have 572meg in my swap file. Could this be why my computer is running so slow? I use win98se.

A techie friend of mine suggested that I write a simple batch file [program] so that my swap file is deleted every time I reboot the computer. That way, it will be replaced with a new swap file that is empty once Windows is loaded. I don't know anything about this and certainly don't want to play with something I don't know anything about! Any help will be greatly appreciated. Thanks! "

Side note: A swap file is a file set aside to temporarily store information once system memory (RAM) on the computer runs low. Since a hard disk drive is much slower than system memory, a frequently accessed swap file can severely deteriorate system performance. (Source: Orielly.com and members.aol.com)

My response:

Unfortunately, what your friend said is incorrect. You're much better off defragging your drive and setting the page file to 1 constant size. This will prevent the swap file from fragmenting, plus acquisitioning the file will be done in a much more efficient manner.

Defragging: How it works

The defrag process will attempt to place the swap file in side-by-side [contiguous] clusters on the drive so that access time (to the file) will be quick and efficient.

As I have discussed in the Gazette a few times before, a single file can span across multiple areas on a hard disk drive. If the file is fragmented, the hard drive heads must move back and forth to read or write each portion of the file (as seen in the picture above). This is referred to as hard drive latency or access time. Defragging, on the other hand, puts related files in a close proximity so that when they are accessed, the drive head efficiently moves (at best) in 1 direction. The drive arm is referred to as the "boom", and a move in one direction of the boom is referred to as a "sweep".

On a side note: Contrary to what your friend suggested, deleting the page file at boot up will only worsen system performance. As soon as the page file is deleted at boot up, new files will overwrite the sectors of the drive where the swap file once occupied. When the swap file is created again, parts of the file will be written to the first available blank areas of the drive (which are typically sporadic). The swap file therefore becomes even more fragmented, resulting in increased latency.

To change your swap file settings (also known as virtual memory):

  1. Boot into safe mode
  2. Run defrag on the drive letter that has Windows on it
  3. Go to the Desktop, right-click My Computer and select Properties
  4. Go to memory settings (Advanced -> Performance Settings -> Advanced -> Virtual Memory Settings in WinXP) set the page file to 2.5x the size of RAM in your computer. For example, if you have 256 meg, set the page file to 640 meg.

I remember reading this formula somewhere, and have tried it myself on a few machines and it has worked well for me in the past. However, as Infopackets Reader Curt W. points out, computers today typically have more than 512 megabytes of system memory (RAM), and so a new 'rule' comes into effect:

" The 2.5x rule as you mentioned, is a bit out-dated. As a rule of thumb, I wouldn't go higher than 500MB unless you are monitoring your system and know for a fact that you need to set the size higher than that. With RAM memory commonly reaching 512MB or greater in PC's these days (I personally have 1GB in my machine) it would be absurd to set the swap file to anything more than 500MB unless you're using super memory-hungry applications. "

Rate this article: 
No votes yet