July 26, 2008: Windows Memory Management
Unless you’ve studied it a bit, you probably have a few wrong impressions about how Windows memory management works, and that may be hurting your understanding of how to get good performance from the OS. So here are a few links that are worth reading. On this topic, there seems to be a lot of just plain wrong advice out there on the web. So here are a few links which avoid those common misconceptions:
- Understanding Virtual Memory by Perris Calderon. This will really help form your base understanding of how the backing store works, and why several ‘common sense’ virtual memory tweaks are in fact kind of disastrous.
- The above article doesn’t cover improvements to the VMM (virtual memory manager) which are now implemented in Vista/W2003. Mark Russinovich explains the new stuff here.
- ArsTechnica has a very clued-in member who goes by the name DriverGuru. From time to time he answers questions about memory and pagefile usage. Those threads can walk you through some realworld examples, and so they help drive the message home.
- MSDN has a large section on memory management.
- The best reference is a book: Windows Internals 4th Edition, by Mark Russinovich and David Solomon. The 5th Edition is due out soon.
- Update: Mr. Russinovich has a new blog article out, which really helps to provide a more depth-ful answer to the question: Dude, Where’s My 4 Gigabytes of RAM?

The above picture is of Tmurgent’s ATM tool, very handy on Vista/W2008 (though it also works on earlier versions of the OS). I added a bit of text to the above screenshot of the tool running on my own system (2GB of RAM installed).
OK, you’re saying, that’s fine and dandy, but you don’t want to deal with a lot of mumbo jumbo. You just want to know if your system is using memory optimally! OK, here’s how to check. Open Perfmon (it’s part of Windows), remove all the default counters it is graphing, and add this one counter: Memory, Page Reads/sec. You’ll get a graph like the one below:

Your goal is to make that line as flat and low as possible while you are using your system normally. That’s the number of times Windows has to fetch data out of the pagefile on disk and stick it back into RAM. You’ll probably never get it to the point where it stays perfectly flat at zero, but you do want it to return to zero much of the time, with only occasional spikes, and those spikes should usually be to 10 or less. Note that in this example, I set the multiplier scale to 10, so that spike to ‘60’ on the graph was really only a value of 6 page reads per second. This is a system that’s responsive and very rarely goes to disk to retreive data that should be in RAM.
If you’re seeing too many page reads, you have two basic choices: 1) buy more RAM, or 2) run less memory intensive processes. Choice #2 can mean a lot of things. It may mean just closing programs you are not using, or it may mean looking around for one or two programs which seem to hog a lot of RAM.
Tweaking your page file isn’t going to do anything to make this graph look better, and in many cases will make it a lot worse. Unless you really really understand this stuff and are in fairly unusual circumstances, tweaking the pagefile or other OS parameters is not going to be a winning strategy. Don’t say I didn’t warn you!