Mac OS X,  Mac OS X Server

RAMdisk on MacBook Air

I can’t remember where I picked up how to get a RAM Disk mounted in OS X, but it’s a great way to get some unbelievable speeds on your Mac for those minor IO intensive processes that don’t need persistent data. It should be mentioned that the contents of RAM disks are erased, once ejected, but the speed of processes while they’re running can be pretty phenomenal on systems with fast RAM. The best example is a MacBook Air, where the memory is surface-mounted QFP and so really fast.

Let’s say you have 4GB of memory and you want to run a process that isn’t going to take more than a gig of memory. You have 3GB of memory you can then use as a RAM Disk. To mount up the RAM disk, I usually create a .command file with the following contents:

diskutil erasevolume HFS+ "rdisk" `hdiutil attach -nomount ram://6144000`

I usually call that file mountrdisk.command

Then I create another .command file called unmountrdisk.command with the following:

hdiutil detach /dev/disk1

These allow me to mount and unmount the RAM disk, quickly. I then add a line at the top of the second command file to backup the contents to a folder on my local computer, since anything in there doesn’t get saved once detached:

cp -R /Volumes/rdisk ~/rdiskbackup

Running the first .command file will create the rdisk with the following output:

Started erase on disk1
Unmounting disk
Erasing
Initialized /dev/rdisk1 as a 3 GB HFS Plus volume
Mounting disk
Finished erase on disk1 rdisk

You can then cd into it and treat it as you would any other volume. Once you’re done, run the backup command file and then the unmount command file to back it up and trash it. Speed tests show anywhere from 325 MB/s to well over a thousand according to what you are doing. The performance can degrade quickly in some cases, but when used properly it’s a great little tool.