NT Swapfile Tricks

  1. #1
    Tyler D-A-L Guest

    NT Swapfile Tricks

    The pagefile is a critical part of Windows NT, and having a poorly tuned pagefile and severely degrade NT's performance. NT likes RAM, and it also likes a large pagefile. Don't think for a second that since you have 256MB RAM in your new computer than you can skimp out and live with a 64MB pagefile. NT simply does not work this way. NT's paging scheme is not like Windows 9x, Linux, or Solaris where you can live without much swap space on systems with large amounts of RAM. Microsoft recommends having a pagefile that is at least 12MB larger than your physical RAM size. I recommend that you at least create a pagefile that is twice the size of your RAM. Disk space is cheap, so this really is not a problem.
    Why does NT like a large swap area?

    NT's VM subsystem does not wait until you have overcommitted your physical RAM before it starts paging memory out to disk. NT pre-emptively pages out data (which still remains in RAM) so it can be discarded later on without any work if the memory is needed for other processes. Microsoft's goal was to create a system that will handle large memory loads without performance degrading significantly. While this may be true, it also means that NT's performance under light loads leaves something to be desired. In addition, NT doesn't use LRU (least recently used) page replacement, but instead uses a FIFO (first in, first out) scheme. See Working Set Flaw and Wasting RAM... for more info.
    I created a 256MB swapfile on your 128MB system, but swap performance is slow -- why?

    Even though you created a large swapfile, you may have done one of a few things 'wrong'. The first and foremost problem is that NT might have created a swapfile with thousands of fragments. Don't think for a second that NT wouldn't do this because you had a few gigs free on your disk. NT's cluster allocation isn't very smart in many cases, especially on NTFS. See my page on Fragmentation for evidence. Get a defrag utility such as Diskeeper from Executive Software (they have a free version called Diskeeper/Lite). Analyze your disk and see if your swapfile is fragmented. I've had cases where NT created a swapfile with over 5000 fragments on a partition with 1GB freespace (with many large contiguous chunks).

    NT Internals also has a utility that will defragment pagefiles.

    NOTE: Having a pagefile which is fragmented is not necessarily a bad thing. Since the contents (the actual memory pages stored) of the pagefile are most likely scattered in the pagefile, your disk is going to have to seek when retrieving/writing pages. It can be a bad thing if your pagefile is fragmented all over your disk, which is what happened in the case above with 5000 fragments. But then again, a fragmented pagefile might not negatively affect performance at all since you aren't always doing sequential reading to retrieve a group of pages.

    If you do have a fragmented pagefile and want to defrag it, do the following:

    Get the Pagefile defrag utility from SysInternals or purchase Diskeeper 4.0 from Executive Software

    NOTE: I deleted the process for manually defragmenting your pagefile as there is now a freely available utility to do the same thing available.
    My pagefile isn't fragmented -- what else could it be?

    One more factor affecting your paging performance could be the location of your pagefile. There are several recommendations depending on the number of disks in your system and the number of partitions on each disk. Skip to the section which best describes your disk configuration.
    I only have one hard disk.

    Ok, having one disk makes things very simple. Your pagefile has to go on a single disk, so the only choice is which partition to put it on. In my opinion, the pagefile should go on the partition which will have the most utilization under NT. The logic behind this choice is that the disk heads will most likely be near the pagefile since it is on the most utilized partition. Do not create a separate partition for your pagefile with a single disk. You are basically guaranteeing that NT will have to move the heads in a near-worst-case to reach your pagefile. Latency is not your friend.

    If you already have multiple partitions on a single disk, one thing to make sure of is that you do not have a pagefile on each partition. NT balances the swapping load between all pagefiles, so once again you are doing too much seeking on your disk subsystem. NT doesn't work like Linux where you can give priorities to swap areas. For Linux, you could have two swapfiles on a single disk, but configure the OS so it won't touch the 2nd swap area until the first is 100% utilized.
    I have two or more disks.

    Things just got complicated, but your performance might get a boost -- especially if you have SCSI disks. (SCSI disk performance shines with multiple-disk configurations due to scatter/gather and command queuing) You can either create a large pagefile on a single disk, or split up your pagefile between your disks. I prefer to split the pagefile and NT will balance the load between the disks. For example, if NT has to page out 40MB of memory between two pagefiles, each pagefile will get 20MB. This will most always be faster than paging 40MB to a single disk. (given disks of nearly equal performance)

    Also, you can put your pagefile on a RAID0 array to boost performance. Just don't put it on a RAID5 array -- this is due to how disk writes are handled under RAID5.


  2. #2
    Cache is offline Super Moderator
    Great bit of well laid out information there, Tyler. Maybe you should think about making a tutorial section for the forum.

    Good read8-)

  3. #3
    Tyler D-A-L Guest
    Quote Originally Posted by cache
    Great bit of well laid out information there, Tyler. Maybe you should think about making a tutorial section for the forum.

    Good read8-)
    There will be a Article section NOT in the forum but in the forum . Hard to explain, but will be very nice! :mrgreen:

+ Reply to Thread