VuULF Dot Com Geek, Tweak and Game


Optimizing Your Swapfile – Step 3

Step 3 - Introducing Your Swapfile to a Clean Drive

Alright, this is the final, and probably easiest, since we have done this already, step. You must now place your swapfile on the fastest performing hard drive, which we have defragmented and even left open space for the swapfile in the previous step. This is where it gets fun, because this is where the performance kicks in.

First off, we have to tell the computer that the swapfile should be located on the fastest hard drive. In case you don't remember how to do this, we will go through the motions here. First, open the System properties (Start --> right click Computer --> click Properties --> click Advanced System Settings --> click Continue on UAC--> click Settings on the Performance pane). Alright, now click the Advanced tab, and then the Change button on the Virtual Memory pane. Have you got something that look like this?

Virtual Memory Window

If you recall, you set the swap file by clicking the slowest drive and then entering a value into Initial and Maximum on the custom pagefile. Now we need to remove the old swapfile that we set on the slow drive and put it on the fastest drive. For uni-drive people, this simply means to set your drive to a fixed swapfile size so skip to the next section.

OK. For those with multiple drives, you want to click the slower drive and click the No Paging File radio button and then click the Set button. Now you want to click the faster drive and type 2048 (unless you want to use the Windows recommended size, as long as you have enough free space at the beginning via our mathematical calculation in the last step) in the Initial Size text box and then 2048 in the Maximum Size text box. The reason you want to set a fixed size is so that the file never shrinks or grows., this means that it is finite and will always perform as you wish it to. Setting it at a both minimal and maximum of 2048 will guarantee you will have a minimum and maximum of 2 gigabytes. As I mentioned before, this is more than enough for most users. If you chose to go with the Windows recommended number, make sure that you left enough room at the start of the drive via the JkDefragGUI Free space option. Now, once you have set your swapfile values, whatever they may be, click Set. You will now have to reboot again after clicking OK to all of the windows. Do so, and we are done! Enjoy your new found swapfile performance!

For uni-drive people, or those with one drive, simply open the System Properties window (Start --> right click Computer --> Properties --> click Advanced System Settings --> click Continue on UAC --> click Settings under Performance --> Click Advanced tab --> Click Change under Virtual Memory pane). Now set your Initial and Maximum sizes for your drive under the Custom Size radio button to 2048, for both text boxes. Hit OK on all screens and reboot. Woohoo! You have now optimized you swapfile on a uni-drive system as well!

One final thing left to do, and that is to turn System Restore back on. Simply click Start, right click Computer, click Properties. In the System window on the left pane click system protection and then click Continue on the UAC window. For those with one drive, simply put a check mark in the box corresponding to your hard drive. For those with multiple hard drives you will probably want to set the slower drive as the one to hold the restore points, which will keep file access to the faster drive to even more of a minimum keeping your swapfile performing as best it can.

For the uber-geeks, like me, you may want to do something special. I won't walk you through the entire process, because if you're an uber-geek, this was child's play, but I will tell you how to set yourself up with the best, and I mean absolutely best, performing swapfile. This, of course, bases it's roots in the UN*X and UN*X like system's history. If you are serious about performance, you will want to set up  at least two partitions in a Windows (or other) environment. Set up the small partition first, let's say 2048 MB. Do not allow Windows Setup to format the drive. Then set up the secondary partition using the rest of the hard drive (or partition, accordingly, whatever). Now install Windows to the second partition. When you are done installing and at the Desktop, use Disk Manager to format the first small partition. Then simply put the swapfile on the small hard drive and you are in business. Does this work to increase performance? You betcha!  This is because the swapfile is always at the beginning of the hard drive and the hard drive you set it up on, or partition for that matter, is never even used by Windows. Of course, this is designed for people setting up a new system. My tutorial for doing this with an existing partition, however, works almost as well! Enjoy!



Optimizing Your Swapfile – Step 2

Step 2 - Defragmenting Your Target Drive

In order to get the swapfile to perform better, we will need to defragment your target hard drive. Defragmenting basically means that you are taking data that is spread out in small chunks over your hard drive, a putting them into a single chunk on only one place on your hard drive. Windows Vista does a pretty good job of keeping your hard drive defragmented automatically, but I have found that you will still end up will a lot of fragmented files, especially if you don't leave your system on 24/7. While I prefer to use a professional defragmentation software called Diskeeper, for this article I want to keep things free. You could use the trail version of Diskeeper, however I tend to place a small utility on client systems called JkDefrag. Now before you run off and download JkDefrag, I would also like to mention a little piece of software that goes hand in hand with JkDefrag called JkDefragGUI. This program will automatically download the latest version of JkDefrag as well as some other support files from SysInternals and from Lars Hederer. Here is a direct link to the JkDefragGUI download file:

After your have downloaded the software and unzipped it, simply run the program called JkDefragGUI.exe. Luckily this program is smart enough to know that it needs Administrative rights so we don't need to go through the hassle of setting that up. However, for some reason, Emiel Wieldraaijer, the author of the JkDefrag script, doesn't automatically detect if you are using Windows Vista, and the software will tell you that it couldn't find Mark Russinovich' program called PageDefrag, and asks if you would like to download the file. PageDefrag is not compatible with Windows Vista, so you want to say no (Note to Emiel - you should have your AutoIT script detect Vista and ignore downloading PageDefrag if it encounters Vista - use the macro @OSVersion to detect which will allow you to save the end Vista user the download of Vista incompatible PageDefrag). Now you should have a clean looking GUI with a whole bunch of tabs and options available. You can close this program for now, I just wanted you to have a look at the software and get the support files that will be needed later. For now, let's start cleaning up that hard drive.

First off, If your computer is running smooth and clean, without any hiccups, you will want to completely disable System Restore, thus removing all of the files. This step is optional, but it will allow you to free up some space and give you a more thorough defrag. While I do suggest doing this step, it is completely up to you. System Restore keeps snapshots of your system at various points. If your system doesn't work for some reason, you can rely on the System Restore points to go back to a point where the system was working OK. Still, this eats up a lot of space and becomes very fragmented over time. Simply disabling the System Restore function temporarily will delete the files it has stored, and thereby eliminate those fragmented files. This is a perfectly acceptible thing to do, however, if you do this step, and some fluke thing happens to your system and you cannot use System Restore to recover it, I take no responsibility whatsoever for your action - you must make the decision whether to turn this function on or off, I have nothing to do with that decision.

That said, in order to turn off the System Restore Function, click Start, right click Computer and click Properties. On the window that pops up, on the pane on the left you will see a link to System Protection. Click that link and click Continue on the UAC panel. You will end up with a window that looks like the one below.

System Restore Window
System Restore Window

For every hard drive that you have check marked, remove the check mark by clicking it. You should be prompted with the following window, to which you should respond by clicking Turn Off System Restore.

Turn Off System Restore
Turn Off System Restore

If you want to save yourself the hassle of reopening the System Restore window, and also serve yourself a reminder to turn System Restore back on when we are finished defragmenting, hit Apply on the System Restore window and the window will stay on the screen, otherwise hit OK to turn it off, but remember how to get it open again as referenced above.

Normally, I would suggest to eliminate a lot of other junk on your system using CCleaner or the Windows file cleaner, but CCleaner tends to be too aggressive for some users, and the Windows version takes a long time to complete. While it would cut down defrag time a bit, and give you more free space on your hard drive, it isn't really necessary for this tutorial, so I will leave that to your own discretion. I wouldn't bother at this point. Besides, JkDefragGUI has a nice little feature which will allow you to get rid of some of the useless stuff anyway, which we will now do.

Open up the JkDefragGUI.exe program. When opened, click on the Cleaner tab and you will be shown various options that you may or may not want to clean from your system. I would suggest not removing cookies, especially if you rely on IE to store passwords for websites you vist often. Also the recent folder is best used at your own discretion. I tend to dump it, but I don't really use recent items anyway, so the choice there is yours. You should have something that looks like this when you are finished.

JkDefragGUI Clean Function
JkDefragGUI Clean Function

After you have made all of your selections, you should click Run. Do note, that on Windows Vista you should select the All Users variety of file deletion, as some of the system accounts and UAC may place files in administrative folders. You should also optimize the registry and empty the prefetch folder. Optimizing the registry will, essentially, compact it. When Registry Optimizer is running your computer may act as if it is crashed: DON'T PANIC! Let it do it's thing and all will be well. Emptying the prefetch folder will get rid of information that Windows stores to make your programs start faster. This will rebuild over time, and it is a good idea to dump it once in a while to get rid of the bloat; once every three months or so is usually a good measure. After a few minutes of cleaning, you will be back at the Clean Tab on JkDefragGUI. Once that is finished, it is time to start messing around with the swapfile itself.

In order to get the best performance from your hard drive, you want to place the swapfile at the front end of your disk. To do this we will want to offload the swapfile to the slower hard drive temporarily while we defragment. To do this, open the System window again (Start, right click My Computer, click Properties). This time we want to click the Advanced System Settings link in the left pane. This will bring up a System Properties window on the Advanced tab. We will want to click the Settings button located in the Performance pane, as shown below.

System Properties Window
System Properties Window

Having done this, you will now have a Performance Options window, where you will want to click on the Advanced tab. Under the Virtual Memory pane (another name for the swapfile, which is additionally known as a pagefile), you will want to click the Change button. In this window, we have a few things to do. First, find your slower hard drive in the list and click it. There should not be a swapfile on your slower drive, hopefully, however if your slower drive is the one that has the swapfile, ignore this section and skip past to where we defrag. For anyone who has the swapfile located on their faster hard drive, you need to select the slower drive. Click the Custom Size radio button and then set the size to 2048 (that's two gigabytes) in both the Initial Size and Maximum Size text entry boxes, and then click Set. A quick note here; Windows may recommend a larger swapfile for you, using that size for the Initial and Maximum size is fine, but really, 2 Gigs is more than enough for almost everyone reading this article. Now, we need to remove the swapfile on your faster hard drive. To do this, select that drive in the list and click the No Paging File radio button and then Set. If you get a warning window regarding sizing your swapfile, click Yes and continue on, as we have a swapfile set on the alternate drive. Click OK on all of the open windows and you will be prompted to reboot. Do so. I will wait here for you. No, really. Go ahead and reboot.

Yay! You're back! You may notice your system is actuing a little bit sluggish. That is because the swapfile is now located on the slower hard drive, and accessing it isn't as zippy as on the first drive. Another note, because I know it will be asked, is that when Windows boots, it places files in the prefetch folder. Why did we clear the prefetch before the system rebooted? Basically, the prefetch folder will now have only the essential system services and programs required to start up stored in it, and it will be defragmented for quickest response, without having to wade through all of the other stuff.

Now let's defragment. Open JkDefragGUI.exe. On the General tab we will want to select the hard drive from the pulldown menu which corrensponds to your fastest hard drive. We will also want to make sure that the Action pulldown is set to Analyze, Defragment and Fast Optimization. Finally, we will want to make sure we have enough free space at the beginning of the hard drive for the swapfile. Since we want at least two gigs, leaving it at 1 percent is probably fine. Just do the basic math. If your hard drive is 200 gigabytes then 1 percent will be 2 gigabytes. For those with less than 200 gigs you will want to allocate at least 2 percent, or perhaps even more if you are using a very fast smaller hard drive. If you are at, say, 80 gigabytes, set the percentage to 3 percent which will give you 2.5 gigs of free space at the beginning of the hard drive. Basically, this is what you should see.

JkDefragGUI Ready to Defrag
JkDefragGUI Ready to Defrag

Now you will want to click Run. You will see the JkDefrag window open and you will finally be defragginng your fastest hard drive. Remember, though, while defrag is a good thing, like beer and wine, too much of a good thing is detrimental. Defrag stresses your components and you should only do a full defrag at most once every month or longer, or purchase software that will keep your hard drive fragment free automatically and safely, like Diskeeper. At any rate, you should see something like the following image pop up while you are defragmenting. Now you can go grab a coffee and sit back and read a book for the next little while; this will take some time to complete.

JkDefrag in Action
JkDefrag in Action

Done now? Great! As you saw, JkDefrag will alert you when it is finished. Now you can quit all of the Jk programs, including the JkDefragGUI, and we can set up your swapfile on the fastest hard drive, and you can feel confident that you are getting the most performance out of your swapfile.

Now onto the finale, STEP 3.


Optimizing Your Swapfile – Step 1

In order to optimize your swapfile you should first ascertain the fastest hard drive you are using. If you are using a single hard drive, then you can skip to Step Two. However if you have multiple hard drives or RAID arrays, you will definitely want to put your swapfile on the fastest available hard drive. Basically what I will show you here is how to determine which is your fastest hard drive using "DiskSpeed". Then we will defragment that hard drive completely and finally we will adjust the swapfile to a reasonable fixed size for your system.

A few myths that should be dispelled. Myth on is that the swapfile should be twice the size of your RAM. This is just inaccurate. Even in a gaming environment, the swapfile is not used as much as you'd think. A large swapfile is good for kernel dumps on blue screen, and for caching a lot of served data. For day to day use, however, maintaining an overly large swapfile is just a waste of space. A good size on the Vista platform is around 2 gigabytes. This leaves you oodles of overhead, and with today's high capacity hard drives, takes very little room. The second myth is that the swapfile should be on a separate hard drive than the system. This, simply put, is not true. If you score an average of 700+ on one hard drive using DiskSpeed to test your drives and an average of 600+ on a second hard drive using Disk Speed, you will still be better off using the hard drive that scored higher. If your secondary hard drive scores roughly 25 points less or better when testing with DiskSpeed then you should use the secondary disk. While a lot of files will come from your primary, or C:\ drive, unless your secondary hard drive scores are near equal to that of the C:\ drive, you will actually lose performance by putting the swapfile on the secondary drive. Keep these items in mind as we walk through the tutorial.

Note: This tweak will work equally as well in Windows Vista, XP and 2000, however, this article will primarily cover tuning for Windows Vista. If there is enough demand for tweaking XP then I will post a secondary tutorial for that.

Step 1 - Determining Your Fastest Drive

If you have multiple hard drives, and are not certain which drive is the fastest, you should perform this step and isolate which drive will be the best candidate to hold your swapfile. The faster the hard drive performs, the better. If you have only one hard drive, and aren't at all curious as to the speeds it achieves, you can skip this step.

First you will need to download a good tool to benchmark your hard drives performance. While there are a plethora of great tools, the one I choose to use is a freeware application called DiskSpeed. You can find DiskSpeed at the following URL. or for a direct download of the file without the authors information

Download the program and unzip the file using your favorite decompressor (I prefer 7-Zip, but that's a different article altogether...). You should now have an icon in a folder called DskSpeed.exe with a picture of a cat on it. Since I am assuming you are using Windows Vista, and are smart enough not to have turned off UAC, you will have to run the program with Administrative options set. To do this, either right click the DskSpeed.exe and click Run As Administrator and click Continue on the UAC screen, or, the better option, permanently set this file to run using the Administrator by right clicking the DskSpeed.exe file and then click Properties. You will be presented with a standard properties screen. Click the Compatibility Tab and then put a check in the box in the Priviledge Level pane which says Run As Administrator.  You should have something that looks like the following:

DiskSpeed Properties Set To Run As Administrator

DiskSpeed Properties Set To Run As Administrator

Now click OK and then run the DskSpeed.exe program, selecting Continue on the UAC system prompt. You will be greeted with a simple interface which will allow you to select all of your hard drives from a pull down menu. You should run this test on all hard drives that are present in your system.  If you have multiple partitions per drive, just run the test on the first partition of the hard drive and/or the partition that houses the most space. If you are unsure if you have multiple partitions on a single hard drive vs. more than one physical hard drive then you can probably assume you have multiple parttions. Why else wouldn't you know if you had more than one hard drive? If this is your case, simply run the test on C: if you are curious to see what speeds you get, and skip to Step 2. The number you should be most concerned with for the sake of this test is the Overall Score. The higher your score, the faster your hard drive runs, therefore making the drive with the highest score the best candidate to hold your swapfile. Here are a few screenshots of DskSpeed.exe in action. The first demonstrates the GUI for the DskSpeed.exe program. The second shows the final result of my first hard drive and the third shows the final result of my second hard drive.

Disk Speed GUI

Disk Speed GUI

First Logical Hard Drive (2xMastor SATA RAID in my configuration)

First Logical Hard Drive (2xMaxtor SATA RAID in my configuration)

2xWestern Digital PATA RAID in my configuration

Second Logical Hard Drive (2xWestern Digital PATA RAID in my configuration)

As you can see, my first hard drive outperforms my second hard drive by almost a full one hundred points. This mean that I would be best off keeping my swapfile located on drive C:\. If the Overall Score was closer, say by about 25 or so points, perhaps even closer to 15 with todays hardware, then we could test to see if the performance would increase by placing the swapfile on drive D:\, however, as it stands, we want to keep the swapfile on drive C:\ using the scores I achieved.

Now onto STEP 2