Feb 25, '09 07:30:01AM • Contributed by: mayathemacjedi
There isn't a 64-bit RAM disk Mac application that will allow creation of RAM disks larger than 2.2GB (or maybe I haven't found it yet, as Google comes up with nothing useful). So instead, here is a method using the built-in tools in Leopard. I cant find the original post that had the initial RAM disk creation scripting, but I give huge props to the person that initially posted it. It was much more optimized than my own, except that mine uses the maximum allowable RAM disk size, and adds RAID functionality.
Uses: Scratch disk for iShowU and other screen capture programs; scratch disk for any program (especially Shake, Photoshop, After Effects); particle disk cache in Maya; PFTrack, etc. In short, a RAM disk is good for anything that you don't want your hard drive to be involved in --crunching huge numbers, etc.
You can create RAM disks with the $25 ramBunctious, or the free Esperance DV. Esperance DV does the exact same thing as ramBunctious, but for free and with better options and a better interface. However, as far as I know, both programs only allow the disk image to be approximately 2GB, and I have tried everything to make this limit disappear, with no luck. I also can't make multiple RAM disk images with Esperance DV.
So I came up with this method to create a RAM disk larger than 2GB: make multiple RAM disks and RAID stripe them! If you have enough RAM, give this a shot. I routinely use 10GB ram disks on my cluster machines, as it makes things ridiculously fast. I got this idea from running whole Linux distributions booted completely into RAM, and loving the immense speed.
First make sure you have enough RAM for this hint! You computer will slow to a crawl if you don't have enough RAM for the size of the RAM disk you want to make.
To create a 2.2GB RAM disk (the largest possible, I think -- any larger and you may get memory allocation errors and it will fail), run this Terminal command:
diskutil erasevolume HFS+ "r1" `hdiutil attach -nomount ram://4661720`;
Divide the last number (which is the size of the disk in blocks) if you don't have enough RAM (keep at least 1GB free) left for the OS. Eject this disk like normal when finished and you will be good to go. To create two 2.2GB RAM disks, striped as a RAID volume (making the OS see 4.18GB as a RAM disk), use these commands:
$ diskutil erasevolume HFS+ "r1" `hdiutil attach -nomount ram://4661720`;
$ diskutil erasevolume HFS+ "r2" `hdiutil attach -nomount ram://4661720`;
$ diskutil createRAID stripe SpeedDisk HFS+ /Volumes/r1 /Volumes/r2;
When you're done, you can use Disk Utility to delete this RAID set. If you don't (i.e. you just eject them in the Finder), they will stay online and linger in RAM. (When you run top after ejecting the disks in the Finder, you'll see two diskimages processes in the list.) You could use kill -9 PID_of_disk_images to kill the processes, but I am not sure how cleanly this works.
If you know how to unmount RAID volumes in Terminal, and reverse this whole process and recover the ram, please post. I have a few methods using diskutil that destroy the RAID volume (separate it into its own disks), then unmount the stripes. This seems to work, but I don't want to submit it, as it's not fully tested. I also use kill -9 pid_number, which is a dirty method but works without a hitch (so far, at least).
[robg adds: I created a smaller 2GB striped RAID RAM disk as a test, using this site to convert GB to block size for the ram:// portion of the command. The test worked well, as did ejecting the disks via Disk Utility.
In researching this hint, I found this page, which has some interesting notes about RAM disks -- in this user's tests, a RAM disk was actually slower than a physical striped RAID, apparently because OS X caches disk I/O on RAM disks. This not only makes things slower, but means that a full RAM disk will require twice as much RAM as its size -- i.e. a full 2GB RAM disk will require 4GB of RAM.
On the linked page, there's also a downloadable set of scripts for creating and deleting RAM disks, which may provide a Terminal-based alternative to removing the RAID array using Disk Utility.]
