Sunday, August 2, 2009

Braggin' and Defraggin'


My Saturday morning project was simple, and useful, even if my initial task proved to be a failure. This discussion might be a bit technical, but, suffice to say, if you know what Page Files or Disk Defragmentation is, you might find it interesting.

Quick Disclaimer:
I'm not, in theory, a hardware professional. This is personal knowledge, and I might, gasp, even have things wrong. I've been doing things this way for awhile without glaring system instability or trouble, but this risk is warranty-free. YMMV.

I may have spoke too soon on not having hardware problems - As it turns out, Mirror's edge is the first game I've bought in awhile that taxes my systems. I went digging for ideas on ways to improve my performance, short of upgrading my machine with a new video card or RAM, and recalled some ideas for page file tweaking, and defragmenting.

I spent the rest of the morning seeking ways to clear my hard-drives to that crucial 15% that Disk Defragmenter wants, but I found a few other tidbits. Here's a quick rundown of the idea behind defragmenting, and my experiences with the process:

Defrag 101

The idea is, that if a big file is in a contiguous block, it's basically in one place on your hard drive and easier and faster to retrieve. Otherwise, the system is jumping around, trying to find the different parts. On a full Hard Drive, big files tend to be heavily fragmented, and so when a game or program seeks that big file, it has to look more places, seek time goes up, performance goes down.

Defragmenting, in theory, takes all of your scattered files, tries to make a spot on your drive big enough to stash it in one piece, and moves it. So defragmentation works best when you have a lot of empty space at the end of your hard drive, so it can move those big files to the end, then compress the rest back into those gaps that open up.

Page File 101

Your computer needs space to put things it's working on. That's Memory, usually RAM, Random-Access Memory. More is better for most computers, Especially when gaming, since the machine has to juggle tons of textures and graphics and other information.

RAM is fast. It is like thinking about something - you pretty much just have to think about it and you know it. However, Ram is expensive, and Windows can only handle so much of it. So, Windows wants a Page File. This is like a notepad on your computer that windows writes down things to remember on. At first, this seems awesome. You have Gigabytes of space on your hard-drive, but only 1 or 2 gigs of RAM. But, using the hard drive is an order of magnitude slower. As if you had to go look things up in a filing cabinet when you wanted to think about them.

Windows thinks it can manage paged memory for you, and knows what's best. Windows is actually retarded, and in high performance experiences, it's really not that good at this. So, the best bet is to make your 'page file', the scratch file of 'virtual' memory that Windows writes to, a specific size, so it's always in the right place, and always open to use. I think the recommended size is like, twice your system RAM, give or take. It's my rule of thumb anyways.

However, like files, the chunks of your hard drive you set aside for page files can become fragmented. If each piece is, like, 500 megs, this isn't bad. But if it's in tiny slices all over your hard-drive, then seek time becomes even worse.


The Procedure

The theory is, open up tons of space at the backside of the hard drive, turn off page files, defragment, and then turn the page files back on, allowing them to settle into the big chunks at the end of the hard drive. The process took me a good part of my day and about 2 system restarts. There's a few basic steps.

1. Turn off the page files.
This is done by right clicking on my computer and then clicking properties. under the 'Advanced' tab, there's three buttons. You want the one up top, under 'Performance'

The second tab of performance is 'Advanced' again, and then once in there, you'll see Virtual Memory at the bottom. That's where these page files are. In order to turn them off, you need to set each drive you own to 'No Page File'.

!WARNING!
If you have a gig of ram or less, this may make Windows XP run like a dog. this is okay - You won't be doing much other than defragmenting, and after that, it'll all be over and back to normal, or better.

Restarting turns off these page files, and allows for the hard drive space they locked up to go free. If you have defragmented before and seen big green lines, those are, most commonly, page files. Or so I think.

2. Defragging
Once your page files are gone, and you have at least 15% disk space free, the boring part - Defragging. This is the most straight forward, but most tedious portion. The defragger is under start menu > system tools > disk defragmenter.

Got that going? Good. Go get lunch or something.

When you get back, you'll want to look at the report. This is sort of the defragmentation equivalent of hypermiling. You look and see what files remain fragmented, then consider if you can fix that. If the files are very large, you might just need more free space at the end of your drivespace to move it in one piece. For me, I found that TF2, Counter Strike, Guild Wars, and Beyond Good and Evil were my big offenders. By uninstalling the latter three (Which I hadn't been playing lately) I made enough room that the huge 2.5 gig datafile for TF2 that was broken into literally 980 pieces could be put together and defragmented.

I ended up tinkering with this, but when Disk Defragmenter tells you you don't need to defrag, it's usually right, and there's little performance gain to be had.

3. Turning On Pagefiles
Hopefully, you'll have pretty blue bars at this point, with maybe just a little red or green mixed in. Now, you can go and re-enable your page file(s).

You go to the same place as before (right click my computer, properties, advanced, performance, advanced, virtual memory)

This time, you want to set the page file to a specific size, rather than letting XP handle it. If you're a typical gamer with 2 gigs of ram, 4 gigs (That's 4096 MB) is probably in the right ballpark. I'd stick with twice your ram.

Give your page file a custom size - And make sure that the initial and max sizes are identical. This keeps XP from having to screw around with allocating sizes or changing anything.

Restarting allows Windows to actually use these page files.

Quick note: if you go to defragment without turning off page files, you'll see big green bars. This is unmovable disk space, such as that allocated by a page file. You can still defragment around it, especially ig you have lots of free space, but for a thorough compacting spree, it's probably best to repeat the procedure.

The above is my defragment dialog for my two partitions, a 33 gig system partition and a 116 gig applications and games disk. This is a day after my defrag sweep, with some of those bigger games re-installed. Already fragmentation creeps back in, but I should be reaping performance benefits in seek time for awhile yet before trouble brews again.