Balancing RAM, disk, and disks that looks like RAM.
You’re asking good questions and providing the right data from which to make some recommendations: thank you!
I’ve written about virtual memory a time or two already, and it seems 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, it’s possible that a couple of settings might help.
Become a Patron of Ask Leo! and go ad-free!
Configuring virtual memory
Virtual memory only comes into play if your computer doesn’t have enough RAM to do what’s being asked of it. Configuring virtual memory settings is useful only if you find yourself in that situation. Doing less or adding RAM are more practical long-term solutions.
Swap file = Paging file = Virtual Memory (VM)
First, some terminology. Depending on who you ask, you might get different definitions for the terms swap file, paging file, and virtual memory. While technically different, for our discussions here they’re all equivalent.
The concept is simple: when Windows needs more RAM than your machine has installed, it can use disk instead. Things currently in RAM are “swapped out” — written to disk — to make room. When things written to disk are needed again later, they’re “swapped in” — read from disk.
Technically, a page is the unit of memory actually written to disk — say 512 or 2048 bytes at a time. As a verb, it also refers to the act of reading and writing to disk, making it synonymous with swap. We might say that the system is paging by writing and reading pages of memory to and from disk.
Finally, this whole concept of treating disk like memory is referred to as virtual memory.
RAM matters most
Virtual memory is a performance bottleneck only if your system has used up all available RAM.
That implies that there are two approaches to avoid 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 won’t do much because it hasn’t really come into play. Put another way, if your system is running fast enough, then it’s likely your system isn’t using virtual memory much at all.
A quick way to see how much of your RAM is being used is to fire up Task Manager (right-click on an empty area in the taskbar and click on Task Manager). Click on the Performance tab; then click again on Memory. Look at the Available number.
In the example above, I have over 40GB of available RAM. It’s extremely unlikely that virtual memory will come into play.
If you have little or no available/free physical memory — the “Available” number is small or zero — 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. 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.
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 the Start menu and clicking on System, then Advanced System Settings (which may be on the right side of the screen), 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!)
I figure Windows knows better than I do what makes sense for the system, so I rarely 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 — say over a quarter the size of your installed RAM — I know Windows has decided that virtual memory is needed. (Note that there will typically always be some allocation. In the example above, it’s 9728MB.)
No virtual memory
It’s perfectly valid to have no virtual memory at all as long as your computer has enough RAM for all the applications to work properly.
The advantage of 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) to be able to delete the paging files from disk completely.
Separate partitions, no; separate drives, yes
By placing the paging file on a partition on the same physical hard disk as your system, you’re forcing Windows to move the disk’s read/write head back and forth between partitions more frequently as it alternates between accessing the files on your C: drive and the paging file on the other partition.
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 problems, but external virtual memory would be excruciatingly slow because of the slower speed of the connection.
Defragment the paging file? Probably not
There are arguments for defragmenting the paging file and arguments that it’s a pointless exercise.
Defragmenting a file optimizes its layout on disk for sequential reading. This means having all the chunks of a file 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 a different beast — it’s accessed fairly randomly. As a result, whether it’s defragmented makes little performance impact. (And of course if it’s on an SSD, there’s no reason to defragment at all.)
The swap file isn’t heavily fragmented anyway, given that it’s usually created once, early on, and then 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 never supported 64-bit Windows. There are alternative tools out there, but none I care to recommend.
The only other approach to defragmenting the paging file 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 images are restored without fragmentation — including the paging file.
But it’s probably not worth the effort.
Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.
I'll see you there!