How should I configure my virtual memory settings?

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

//

I have a Windows machine to which I just added a second hard drive. The new, larger, drive is now the primary. What do you recommend for a swap file? The “3X RAM” rule of thumb doesn’t make much sense to me. It should be bigger with less RAM, not more. It’s currently set to the same as my RAM size as its minimum and twice as much as a maximum size on the C: drive. 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.

Swap file = Paging file = Virtual Memory (VM)

First, some terminology. Depending on who you ask, you might actually get three different definitions for the terms “swap file”, “paging file”, and “virtual memory”. For our discussions here, they’re all equivalent.

The concept is relatively simple: when Windows needs more RAM than you actually have installed on your machine, it can use an area of disk space instead. Things that are currently in RAM are “swapped out” – written to disk – to make room. When those things that have been written to disk are needed again, they’re “swapped in”. Technically, a “page” is the unit of memory that’s actually written to disk, say 512 or 2048 bytes at a time. As a verb, it also refers to the act of actually reading and writing to disk, making that form synonymous with “swap”.

Finally, this whole concept of treating disk like memory is referred to as “virtual memory”.

RAM matters most

Virtual memory only becomes a performance bottleneck if your system has used up all available RAM.

That implies that there are two approaches to avoiding the problem:

  • Use less RAM, typically by running fewer programs simultaneously.
  • Add more RAM, if your computer is capable of expansion.

If your computer isn’t using all available memory, then tweaking your virtual memory settings isn’t going to buy you a whole lot, because it hasn’t really come into play.

A quick way to see how much of your RAM is being used is to fire up Task Manager (right click on the task-bar clock and click on Task Manager). Click on the Performance tab, and click again on “Memory”.  Look at the “Available” number (or the “Free” number, in Windows versions prior to 8).

Windows Task Manager - Performance - Memory

If you have little or no available/free physical memory, it’s likely that you’re using virtual memory.

Default settings

I’m not really sure where the “three times RAM” rule that you mention comes from, though I’ve heard it before. It certainly doesn’t apply in all cases; in fact, I’d say it rarely applies at all. As you point out, it’s machines with less RAM that need more virtual memory, whereas machines with sufficient RAM typically need less virtual memory, and indeed sometimes none at all.

Without knowing how a machine is used, I typically use Windows’ default setting: “Automatically manage paging file size for all drives”.

Virtual Memory System Managed

You can find this setting by right-clicking on My Computer (Windows 7 and earlier), or right clicking the Start menu and clicking on System (Windows 8.1 and later), clicking on Properties, then Advanced System Settings, the Advanced tab, and the Settings… button in the Performance section, the Advanced tab in the resulting dialog, and finally the Change… button in the Virtual memory section. (Whew!)

Again, since I don’t know how the machine is being used, I figure Windows knows better than I do, so I won’t second guess it. What it does and how it does it doesn’t matter, either. The only thing I might keep an eye out for is the “Currently allocated” number. If that gets big, I know Windows has decided that virtual memory is needed. (Note that there will typically always be some allocation – in the example above, 512 megabytes is very small. The system in question has 3 gigabytes of RAM.)

No virtual memory

As I mentioned, it’s perfectly valid to have no virtual memory at all, as long as your computer has enough RAM for all of the applications to work properly.

The advantage to not using any virtual memory is simply that it’s one less thing for Windows to manage and one less thing that consumes resources, even though with enough RAM, the resources allocated to virtual memory would be small. Most often I see virtual memory turned off (“No paging file” for every drive in the Virtual Memory configuration) as a way to be able to actually delete the paging file from disk completely.

Separate partitions, no; separate disk drives, yes

In my opinion, moving the virtual-memory paging file to a separate partition can help, but only if that partition is on a different hard disk than your system drive.

By placing the paging file on a partition on the same physical hard disk as your system, you’re forcing Windows to have to move the disk’s read/write head back and forth between partitions frequently, as it alternates between accessing the files on your C: drive and the paging file on the other partition.

On the other hand, if you have a separate physical hard disk available, then moving the paging file there can help distribute the load of accessing hard disks across the two physical drives.

Note that you cannot place a paging file on an external or removable drive. Not only would accidental removal cause your system to crash, but external virtual memory would be excruciatingly slow, due to the typically much slower speed of the external connection.

Defragment the paging file, probably not

There are arguments for defragmenting the paging file, and arguments that it’s somewhat of a pointless exercise.

Defragmenting a file optimizes its layout on disk for sequential reading – meaning that if you start reading the file, and read large chunks of it, having those chunks of a file all physically next to each other makes for less disk-head movement and faster reads. While this can benefit many, if not most, files, the paging file is somewhat of a different beast – it’s accessed fairly randomly. As a result, the argument is that whether or not it’s defragmented makes little performance impact.

I’m not sure I agree 100%, but in most cases, the swap file isn’t heavily fragmented anyway, given that it’s usually created once, early on, and then simply accessed in place without change to its layout.

The free “page defrag” tool that Microsoft used to provide appears to have stopped working as of Windows 7, and most certainly never supported 64 bit Windows. There are alternative tools out there, but none that I would care to recommend.

The only other approach to defragmenting the paging file that I’m aware of is to perform a system image (not clone) backup, and then turn around and restore that backup. Most image backup tools work one file at a time, in sequence, so when an image is restored, it’ll be restored without fragmentation – including the paging file.

But ultimately, it’s probably not worth the effort.

This is an update to an article originally posted : June 20, 2007
Play

Comments

  1. Dan Ullman

    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.

  2. Arena

    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.

  3. Leo A. Notenboom

    —–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—–

  4. David Burlakoff

    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.

  5. dunstergirl

    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).

  6. Wayne Scharf

    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?

    • Reid

      Win98?! Anyway, two things: I wouldn’t recommend no maximum — I’ve seen the swap file grow very large, and it never shrinks. Second, if you set a minimum and maximum swap file size and recreate it as you described, it will take pre-allocate as much contiguous space as possible, regardless of where that is physically. The only part(s) subject to fragmentation are 1) if you’re drive is already heavily fragmented when the swap file is created, and 2) the new parts of the swap file that get created when it grows if a maximum size hasn’t been defined. Whether it’s at the inner our outer portion of the platter has very little performance impact.

  7. Arena

    ” 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.

  8. Richard Dore

    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).

  9. KimslanD

    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.

    :)

  10. Glenn P.

    My pagefile setup?

    1Gb RAM, 2Gb Pagefile in a separate FAT32 partition on the main 80Gb harddrive, which is otherwise NTFS (apart from three other small partitions).

  11. Coly Moore

    Just a note: Putting it on a separate drive may help performance, but putting it in a separate partition on your main drive will gain you nothing – your main hard drive is still doing all the work, perhaps more because of the need to access the MBR every time…

  12. Glenn P.

    This is for Coly Moore:

    I put my SwapFile in a separate partition on the same drive for three reasons: (1) so it could be FAT32 instead of NTFS, and (2) to isolate it from the rest of the filesystem, since it is of a fixed size and has no reason to interact with it, and — most relevantly of all — (3) I have exactly ONE physical drive — which makes the placement of the SwapFile partition kind of a no-brainer. Like, “Duh?”     :)

  13. welzki

    Me, whenever I fixed a machine I always set the swap file around 4 Gigs. It does improve the performance a lot and my customers are satisfied with it. But before I initiate it I always check if there is a lot of space on the Hard disk drive, if not I set it to 1 Gigs or 2. It depends on the available space on the Hard disk, I just use my common sense. Along with it I also tweak the Visual Effects, set it to Custom and unchecked everything except for the “use drop shadows for icons and visual styles”

  14. Mark Jacobs

    It seems Windows 8 has both a page file and a swap file. According to what I’ve researched, one of for Windows the other for the Metro Apps. Any insight on this. If this is true, I’d like to be able to regain the disk space of the Metro swapfile as I never use the Metro Apps, not even on my Windows 8.1 tablet.

  15. Geo

    Quick and dirty method.

    Copy an image file of the original HDD to the new HDD, Just like backing up your HDD.

    This assumes you don’t want to make any changes from your old system.

    If so, you can do them now.

  16. CRB

    Over the years, I’ve played with all variations of file size and location. I did see a performance boost in the right system, when I moved it to another physical disk. However, I never saw much point in defragging the file, nor much improvement.

    There is a windows policy or a registry setting you can set to delete it when you shutdown your system. Many people worry about someone accessing the paging file and pulling passwords from it. This will also stop the paging file from becoming over fragmented.

    https://support.microsoft.com/en-us/kb/314834

  17. Marc Menard

    I agree with Leo, stick with the default in Windows. If one wants better performance, there is little to no gain to be obtained by playing with this. Putting the operating system on an SSD (Solid State Drive) will yield far better results performance-wise. I’ve been testing Windows 10 TP on a vintage Core 2 Duo E8400, 3 GHz equipped with 4 GB RAM, and it feels zippy alright on an 120 GB SSD. Even if the board is old, as long as it supports SATA 2.0 and up, the difference is astounding.

    • James B

      Isn’t a SSD just a higher end version of flash memory? Wouldn’t putting the virtual memory on a SSD cause it to die prematurely? For the low price of memory these days, I think increasing RAM if you can would be better than putting in on a SSD.

      • Mark Jacobs

        SSD is essentially a higher end flash memory. It’s not only much faster than low priced flash, but it’s high end enough to handle a swap file under normal conditions. Although I’d make sure I had enough RAM so that I’m not abusind the swap file.

  18. Clade

    Dear Leo!

    I suppose equipment with 8 GB of memory ram installed, will rarely have any difficulty. . .
    There is a form of benchmark to compare whether there was improved performance after the change in the paging file?
    Grateful!

  19. eric

    until pagefile is eliminated we will need it what if we were to turn it off. down the line it might be needed and for me under windows vista it will not turn off.

Leave a reply:

Before commenting please:

  • Read the article. Seriously. You'd be shocked at how many people make comments that prove they didn't.
  • Comment only on the article. If you have a new, unrelated question start with the search box at the top of the page.
  • Don't post personal information. Email addresses, phone numbers and such will be removed.

VERY IMPORTANT: because of a rise in comment spam that's making it through our filters any comments that do not add to the discussion - typically off topic or content-free comments - run a very high risk of being flagged as spam and removed.

If you have a new question unrelated to the article above, ask it on the Ask Leo! ask-a-question page.

Your email address will not be published. Required fields are marked *