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).
If you have little or no available/free physical memory, it’s likely that you’re using virtual memory.
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”.
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.