macOS Catalina ramdisk with APFS

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,096
How to create a ramdisk on macOS Catalina with APFS instead of HFS+

Code:
diskutil partitionDisk $(hdiutil attach -nomount ram://2048000) 1 GPTFormat APFS 'ramdisk' '100%'

The number 2048000 is the result of 2048 times the amount of megabytes you want, in this case 2048 * 1000 (you end up with 1 gig of memory)

So to get a ramdisk of 5gb, you do 2048*5000, which will be ram://10240000
and 16gb would be 32768000

Screenshot 2019-12-04 at 13.45.31.png

To unmount
Code:
diskutil eject /Volumes/'ramdisk'

Fair warning; a ramdisk is temporary storage (for as long as it has power). Meaning anything you put in there will be gone on a power cut, shutdown, etc. Use it as a temporary tool.

You can tell by the results from a gzip tarball creation test in the below post, that nvme and ramdisk have a significant performance/time benefit over older types of drives and external ssd, even over usb-c. If you have certain time consuming tasks it can be an option, such as cache/scratch disks for certain programs (adobe loves ram).
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,096
Testing gzip/tarball creation on 10gb null-file to get a sloppy impression of benefits from a temporary ram disk

Internal drive (NVMe SSD) : 0m37.9
Code:
Floriss-iMac:ziptest floris$ cd Desktop/ziptest/
Floriss-iMac:ziptest floris$ time tar czf 10000M.tar.gz 10000M

real    0m37.939s
user    0m34.177s
sys     0m2.355s

External drive (Sata3 SSD on USB-C) : 0m56.2
Code:
Floriss-iMac:ziptest floris$ cd /Volumes/SSD\ 525/ziptest
Floriss-iMac:ziptest floris$ time tar czf 10000M.tar.gz 10000M

real    0m56.197s
user    0m18.744s
sys        0m2.026s

External drive (Sata3 HDD on USB-3) : 1m52.4
Code:
Floriss-iMac:ziptest floris$ cd /Volumes/Backup\ HDD\ 2TB/ziptest/
Floriss-iMac:ziptest floris$ time tar czf 10000M.tar.gz 10000M

real    1m52.416s
user    0m34.692s
sys     0m1.978s

Ramdisk (2400 MHz DDR4 SO-DIMM, APFS) : 0m36.5
Code:
Floriss-iMac:ziptest floris$ cd /Volumes/ramdisk/ziptest/
Floriss-iMac:ziptest floris$ time tar czf 10000M.tar.gz 10000M

real    0m36.507s
user    0m34.525s
sys     0m1.738s

The old fashioned HDD over usb-3 requires nearly two minutes to create the tarball file, and the ramdisk takes the lead with just over 35 seconds.

Depending on the type of data you're processing, and how much the cpu/gpu is involved, tasks that can be up to 32gb and could take an hour to process, could save you more than a handful of minutes.
 
Top