Monday, January 21, 2013

Creating a ramdisk in OSX 10.7 - For Games :)

Comments on Facebook
Lately I have been pondering buying an SSD for my Mac Pro to improve my IO but for some reason I can't pull the trigger. I am not sure what the hell I am waiting for all I know is I can't decide on size or fully trust the reliability. I put an SSD in my wife's laptop 8 months ago and everything is fine. So who knows.. Maybe I will take care of business and get one. In the mean time I decided to go a different route.

I got all these here megarams..

So my mac pro is sitting pretty with 24 gigs of RAM. I know it sounds like a lot because well.. it is but when you rock a few VMs on it it starts to get chewed up pretty quick. I have the standard fair 7200RPM 1TB drive that came with this mid 2010 Mac Pro and I wanted more so I thought maybe I should do a RAMDISK!

What is a RAMDISK?

A RAMDISK is simply a drive located in memory. It is similar to SSD in that it is fast but has one serious drawback... It's gone when you reboot or dismount it. So don't write a 400 page thesis and save it to a RAMDISK or you are done. Consider yourself warned. Now for games its great because I can put the entire game in a RAMDISK and it loads super snappy like. There are tons of other uses for RAMDISKS and google is your friend if you are looking for other uses.

So how many megarams do I need?

Well this really depends on how big your game is. Currently my Diablo III uses around 13 gigs so I made my ramdisk 15 gigs. The joy is you can make you RAMDISK crazy sizes and it only takes from RAM what is actually being used. So if you specify a 2 gig RAMDISK and you copy 500M to it you will see that you are only using 500M of memory. Keep in mind that though if you oversubscribe this drive you will start to page and your system will run like dog doo.

Ok I get it now what?

First thing is first.. you have to calculate the size of your RAMDISK. To do this pick how many megabytes is going to be. For quick math sake let's assume we are creating a 10M ramdisk. So the calculation would be as follows: 10 * 2048 = 20480. Now remember 20480 because we are going to need it.

Now lets go ahead and create this bad boy. Use the following command:
diskutil erasevolume HFS+ "Geekempire" `hdiutil attach -nomount ram://20480`
You should now have a 10M RAMDISK called Geekempire mounted up.  The cool part is you don't need root to do this. Now lets kick it up a notch when it comes to Diablo III and automate this mug. create a file called diablomount.sh in your home directory using your favorite text editor and drop the following in there and then:

diskutil erasevolume HFS+ "Diablo3Ramdisk" `hdiutil attach -nomount ram://30720000``
 rsync -a --progress /Applications/Diablo\ III /Volumes/Diablo3Ramdisk/
open /Volumes/Diablo3Ramdisk/Diablo\ III/Diablo\ III.app
Next make this puppy executable by running:
chmod 755 diablomount.sh
Then run it with:
./diablomount.sh
This will create a 15GB Ramdisk and copy your Diablo III install to it then launch it. Keep in mind you will NOT want to run this script multiple times! Once the RAMDISK is created you will have to go click on it or just use the last line again from the shell script. Make sure you are launching it form the RAMDISK otherwise you are wasting all those megarams for nothing.

I would write a guide for windows but I only have home premium which has a 16GB limit on RAM. So you are on your own if you want to do it it winders. I am in the process of working on a gui based program where you can basically pick a game you want to do this with etc. We'll see how that goes.

Smooth out