How to make a RAM disk larger than 2 GiB

2008-08-06 12:10:55 UTC

UPDATE 2009-09-23: This procedure is no longer necessary since Snow Leopard.

The most frequent question I get about Make RAM Disk is “How do I create a RAM disk larger than 2 GiB?”.

Make RAM Disk uses Mac OS X’s disk images system to do its work. Unfortunately, as of Leopard, the command to create a single RAM disk refuses to create one that is larger than 2 GiB in size, even if you have the RAM to do it.

However, there is a solution.

Jennek Geels, a user who asked the aforementioned question, worked with Jean-Sébastien Rousseau to figure out a solution using Mac OS X’s software-RAID feature. Here’s a refined version of their solution:

  1. dev1=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  2. Repeat step 1 as many times as necessary, changing the variable number each time (dev1, dev2, dev3, and so on).
  3. diskutil createraid stripe $VOLUMENAME HFS+ $dev1 $dev2 .. $devN

So, for example, to create an 8 GiB RAM disk:

  1. NUMSECTORS=4194304
  2. dev1=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  3. dev2=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  4. dev3=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  5. dev4=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  6. diskutil createRAID stripe $VOLUMENAME HFS+ $dev1 $dev2 $dev3 $dev4

diskutil createRAID will format and mount the RAID device automatically; you don’t need to run newfs_hfs and diskutil mount like you do when creating a single-device RAM disk.

I tested the speed briefly (just one run each, not averaged over several runs). Copying 2,000 MiB from /dev/zero to an 8 GiB RAIDed RAM disk was about one second faster (~5 seconds) than copying it to a 2 GiB single RAM disk (~6 seconds). Your results may vary.

When you’re done, you’ll need to eject all of the devices separately, starting with the RAID:

  1. diskutil eject $RAIDDEVICE
  2. hdiutil detach $dev1
  3. hdiutil detach $dev2
  4. ..
  5. hdiutil detach $devN

If you don’t remember the device name of the RAID device, you can look it up in the output of diskutil listRAID. Look for the line labeled “Device Node:”.

I have no immediate plans to add this RAID feature to Make RAM Disk, because I’d also need to write an app to handle the full clean-up procedure. For now, if you really need a RAM disk that big, you can probably handle creating it and tearing it down yourself.

Leave a Reply

Do not delete the second sentence.