The page file is the source of a lot of frustratingly bad performance on Windows, especially on a notebook computer running Vista. So of course there are a lot of articles out on the web talking about page files. I’ve found most of it pretty uninformed and pseudo-scientific.
I wanted to write about this while it’s on my mind. My lady just got a new notebook (a fun and inexpensive convertible tablet by HP) and I’m having to go through the same Vista optimizing crap with hers that I had to do with my old Sony. Right now for example I have to research how I got mcupdate.exe to stop locking up the hard drive for 30 sec after restoring from hibernation (oop, found it: it’s in Task Scheduler under Media Center).
Well, one of the first things I did on that machine was disable the page file. But oh no! Aren’t those necessary or simply useful? On older Windows systems, yes. On modern systems, filled with periodic update checkers and scheduled tasks, a page file is a giant anchor, dragging everything down.
Why a Page File?
Wikipedia as usual has a good article on page files. What they are, how they work, why we have them.
Based on my own Windows-specific experience, they’re good for a few things. The main and obvious one is that they let you use more memory than you have available. Slow but effective. It was a key feature of Windows way back. Without page files, Windows 95 simply wouldn’t have run at all on most systems. Apps were huge compared to the amount of memory available. Memory was so expensive that OEM’s regularly sold new machines with half the memory they needed to run even decently well. XP had a similar issue when it came out. But today, memory is ultra cheap. Systems are shipping with far more physical memory than the typical user will use. The HP I mentioned, which was already a steal for $800, came with a free upgrade from 1G to 3G.
Another supposed page file advantage is that they let you swap out unused memory from inactive apps you have running in the background. Then you can use that memory for things the active apps need like disk caching. And what a waste to use up memory on stuff you almost never use, like the print spooler, right? Swapping these inactive things out can potentially boost performance, but it really depends on usage. In my experience, this is the key behavior that hurts. More on this later.
Very rarely, some programs will use specific “page file-backed” memory allocations. See MSDN docs on CreateFileMapping with hFile set to INVALID_HANDLE_VALUE. I heard from a friend who does audio production that some of his apps didn’t work when he disabled his page file and I bet it’s because of this. Nothing I use currently has this problem so I’m ignoring this one. Also, the behavior may have changed on Vista. I’m not certain but I remember hearing that Vista can create temporary page files if needed per process. No me importa.
And lastly, the system requires a minimum amount of page file space on the system drive in order to do certain kinds of crash dump for reporting system failures to Microsoft, especially on Vista. Disabling this will prevent your system from being able to report detailed info about blue-screens to Microsoft or something like that. Now, I typically feed back crash info to MS, but in this case it wouldn’t help. All of the (very rare) issues I have on my notebook are Sony driver related, and they don’t even support Vista on this old thing so these reports would just gather dust.
Why Not a Page File?
Well, page files can really slow down a system, particularly a notebook computer where the drives are much slower than the big desktops. My PC at work has a 10K drive but my notebook’s is 5400. For serial reads such as streaming movies or music or loading a game world, no problem. But when it comes to random access, these drives fall down hard. And page files are all about the random access. Software is inherently random access, because the user’s whims are totally random. At least, from the point of view of the computer.
Now, I happen to have 2 gigs in my notebook which is plenty to do everything I need. On occasion I’ll get low memory warnings when running Eclipse+Flex, Visual Studio, Firefox, a web server, and a few other things at once, but I have yet to get close enough to running out to have issues. So there is no compelling need for me to use more memory than the system has.
But…why not just leave it on anyway? After all there’s that whole thing about paging out stuff you don’t use to make room for caching. Performance should be much higher, right? In my experience, performance is worse. Far, far worse.
The State of Modern Windows Systems
Consider the state of Windows today, even if you’re diligent about spyware and toolbars and so on.
Our machines are increasingly filled with update checkers for the system and individual apps. I keep disabling these and every time I manually do an update they keep reinstalling them (in the doghouse: Apple, Sun, Microsoft, Intel). Autoruns is a good friend here.
Modern Windows systems are also filled with periodic tasks. For example, the mail program checking mail, a tray app or widget fetching RSS feeds, a task to fire up mcupdate.exe every day (grr), or the scheduled tasks Google installs to check for updates. Or maybe you’ve got Firefox running in the background and there’s some add-in that does its own scheduled thing (checking Gmail, fetching news, or compacting its own little very important sqlite database).
And lastly, there are the triggered events. For example, say you turn on Wifi, or you restore from hibernate and the Wifi is getting reactivated. Well, that triggers mobsync.exe for some reason, which in turn causes Windows Media Player to scan its entire database. This happens even if you’ve disabled the wmplayer network sharing service. Infuriating.
I’ve managed to disable as many of these as I can without affecting my work, but here’s the big problem.
The Windows Paging Algorithm Hates You
Experiment time. Load up the Vista Resource Monitor. Wait a few minutes for the system to settle down. Suspend the computer, then wake it back up. It should pop up pretty quick. Just a few seconds of disk activity, and then the Monitor’s disk panel should show some minimal stuff from WDI and performance loggers. I’d like it if the WDI stuff didn’t happen but it’s not too bad.
Next, try waiting a couple days between suspending and resuming, say over the weekend. This is a common scenario for me. I’ll often hibernate my machine on Friday, and then won’t end up touching it until Monday morning on the bus. While I was using it on Friday, all of the apps I had minimized or sitting in the tray got paged out by the system. Services as well, like Windows Update and so on - all paged out because they hadn’t been used in a while. Minimizing an app also tells Windows “I’m not using this for a while” so it dumps them. And at some point I probably ran a big app like Flex or Corel that ate a bunch of memory and convinced Windows to page stuff out to keep the file cache at 25%-50% of memory (doesn’t that seem like crazy overkill?). So at the time I put it to sleep, it was running fast and fine, and lots of stuff I wasn’t actively using at the time was sitting in pagefile.sys or was released by the system if it was a read-only mapping from disk (such as code and rdata sections of EXE’s and DLL’s).
Well when waking the thing up on Monday, guess what happens. Every single app and service notices that it’s been three OMG THREE whole days since they last checked for updates or mail or RSS feeds or phoned home or scanned for network shares or compacted their databases or reticulated splines or whatever else. And all of them wake up simultaneously to try to do their little tasks. Unfortunately, they were all paged out from being idle. So now, my machine locks up with hard page faults and tries to pull in a billion little 4K pages at once. The system is either totally unresponsive or severely degraded for several minutes while I wait for things to settle. I can watch this all happen on the Resource Monitor. Hard faults and disk accesses like mad.
This several-minute wait is absolutely infuriating when all you want to do is just open your computer to do a quick check on something like the news for the day.
Apple Gets It
It’s even more infuriating because my slow old clunker of a G5 iMac with only 1G of memory does nothing of the sort. And by slow I mean it was slow and outdated on the day I bought the thing, like all pre-Intel Apple hardware was. Yet on my Mac, I can leave all manner of giant bloaty apps loaded in memory (Firefox, iMovie, iTunes, iChat etc.), put it to sleep, and wake it up a week or two later to do some quick task. It has always, without fail, popped up and been ready to use instantly. Any apps I had minimized or hidden are active almost immediately, regardless of how long it had been since I had hidden or sent them to the Dock.
What the hell?
Clearly, OS X is doing something right, and Vista is doing something absolutely brain-dead. Thinking more about this, I’ve never had the Mac lock up on me unless I peg the CPU. On Windows I can have a minimal CPU load but a locked up machine because it’s just sitting and spinning waiting on the slow hard drive. I think what I’m seeing is a far superior virtual memory manager and I/O subsystem on OS X.
Does nobody at Microsoft notice this? This has been the case on just about every Windows computer I’ve used or been asked to “fix because it’s slow” by a friend.
So Disable It
So! Just disable the damn thing! My main complaint here is that on Windows, and especially on Vista, it’s just about impossible, without a lot of tuning work to the system, to have a notebook available for immediate use. At home if I want to do something quick on the web (look up a drink recipe or check email or whatever) I will always go to the Mac first because I know it will be available within 3-5 seconds, regardless of what state I left it in last. This one thing alone almost makes me want to switch to a Mac full time (more on this in the future).
It takes a bit of work to get the system waking up quickly, and keep it that way, but by far and away the biggest speed-up comes from disabling the page file. I’ve done a lot of testing with it both enabled and disabled. With a reasonable amount of memory, it’s a huge, easy win. The “page out to help the file cache” thing is, in practice, total bunk.
Furthermore, I am in favor of disabling the page file even on non-mobile systems where you don’t care that much about wake-up speed. When I work from home, I use my workstation which runs XP. If I’m sitting down to do some serious work, I don’t care if it takes a few minutes to wake up and get settled. But I do care about its runtime performance while doing normal work. And Filemon tells me that pagefile.sys is the main drive activity while I’m sitting and waiting frustrated. So, I disabled the page file here too!
At work I can’t disable it because I actually can run out of memory from Maya, a few copies of Visual Studio, the game, a running build, some console dev tools, etc. The 10K drives and split page file really help here of course, though I still get lockups on occasion. When I get back from Peru I’m going to see about switching it to Vista x64 (if the dev tools will run under that) and bumping the memory to 8 or 12 gigs and then disabling the page file. After doing some perf testing to see what the win is, of course.
Special Note: SSD’s
Solid state drives (drives with no moving parts, typically flash memory-based) completely change this equation. No moving parts means no rotational latency, no physical read/write head bouncing around. These drives seem ideal for a page file, in fact, where random-access performance matters much more than read/write performance. I’m waiting just a bit longer for prices to drop before swapping my notebook drive out for an SSD, but I’m pretty certain I’ll turn the page file back on when I get one.
A side benefit of SSD’s is that the drive doesn’t make any noise. Windows has a serious problem with insisting on constantly accessing the hard drive. Watching it on Diskmon I see regular physical access to the disk by the system, and who knows any of it is necessary. I don’t know why Microsoft even bothered putting in power-saving options to spin down the hard drive automatically. It’s impossible for it to ever get there because something is always messing with it. So the end result for me is that I can hear my drive parking the head, then tick tick for some access, then wait, then another head park, over and over again. In a silent room it gets obnoxious. Not to mention the noise of the spinning platter.
I was thinking the other day about how much crap is in Windows to deal with the problem of mechanical latency. If you didn’t have that head moving back and forth and have to wait for the right spot of magnetized goo to rotate under it, so many things would be totally unnecessary. Think of all the stuff in Vista that could be removed or simplified with SSD’s: the defragger, SuperFetch, disk caching, ReadyBoost, etc. You could treat the hard drive as simply “slow but consistently slow memory” instead of “slow memory that is sometimes really slow and maybe even stupidly slow depending on the current drive layout”. Consistency of experience always wins. I’m excited to get one!
Optimized Page File Configuration
So ok, maybe you decide to use a page file anyway. Well, it’s important to configure it right. By default, Windows “manages” the size of your page file. This means it may change size depending on system needs. With a fragmented hard drive, you’ll have the page file growing into fragmented space. This takes bad performance and squares it.
I see this problem quite a bit with non-technical users. They often like to ride their hard drives at 98% full, and when they run out, gaining space by just deleting a bunch of music or pictures. This is about the worst use case for a system-managed page file.
In my experience a lot of IT departments are clueless about this as well, leaving Windows at the default configuration. Give the average user a year and they’ve taken their drive performance into the toilet, and start complaining about how slow their machine is. In most cases it’s simply a heavily fragged hard drive and page file. Doing the instructions below and setting a nightly/weekly scheduled defrag.exe run eliminates most performance issues. Note that Vista has automatic defrag set up out of the box.
Tell the system to leave the page file alone. To do this, do the following:
- Turn off your page file and reboot.
- Fully defrag your hard drive. Make sure there is a contiguous free space that will fit your page file (see below for size considerations). Keep defragging until you get there, or use a trial of a commercial defragger to force it.
- Turn on the page file but set its min/max size to be the same. This prevents the dreaded automatic growing/shrinking.
Some commercial defraggers can do the page file during the startup blue screen, so you could take that route instead. But the main point is to set the min/max size to be the same.
If you have two hard drives, the page file should go on whichever drive gets less random access usage. Typically the non-system drive. Make sure it’s a fast drive like your main drive, and not a USB or whatever. You can spread the page file across multiple drives if you like. Test first to make sure it actually is faster. Remember that by adding a page file it’s cutting into the other random-access activity you’ll be doing on that same drive.
As for how large to make the drive, go for 2-4G or so. It really depends on how many things you keep open at once, and how much memory they tend to use. Photoshop, Eclipse, PC games, and so on can be virtual memory hogs. If you run out, do the steps above to increase the size some more.
The common recommendation is to set your page file to double your RAM size. I don’t know where this came from or why but it’s outdated and irrelevant. Tune the size based on your needs. If you have lots of hard drive space then just set it to “really big” and don’t worry about it. Everyone’s usage is very different.
But of course I prefer to “optimize” my own page file by completely disabling it!