Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OS X have an equivalent to /dev/shm?

Does OS X (Snow Leopard in particular) have an equivalent to (some versions of) Linux's /dev/shm , ie something where you can write to and read from a file without necessarily touching the hard drive?

like image 397
Andrew Grimm Avatar asked Jan 09 '10 12:01

Andrew Grimm


People also ask

Is Dev SHM in RAM?

/dev/shm is a temporary file storage filesystem (see tmpfs ) that uses RAM for the storage.

Why is OS X better than Linux?

When comparing macOS vs Linux, macOS feels smoother, faster, and easier. It's true that not everything on Mac “just works” like Apple would have you believe. Even still, though, it's an incredibly easy OS to get used to.

What is Dev SHM :/ dev SHM?

/dev/shm is a traditional shared memory concept. One program will create a memory portion, which other processes (if permitted) can access. Mounting tmpfs at /dev/shm is handled automatically by systemd. Rationale: Any user can upload and execute files inside the /dev/shm similar to the /tmp partition.

Where is Dev SHM?

/dev/shm is not on the hard disk. It's a virtual filesystem implemented in memory, that's why it's faster.


1 Answers

You can create and mount a ram based disk as follows:

  1. Create a disk

    hdiutil attach -nomount ram://$((2 * 1024 * SIZE_IN_MB)) 

    hdiutil will return the name of the ramdisk.

  2. Format and mount the disk

    diskutil eraseVolume HFS+ RAMDisk NAME_OF_DISK 
  3. Access the disk under /Volumes/<diskname>

    cd /Volumes/RAMDisk && touch testfile.txt && ls 

Creating a 100MB ramdisk:

$ hdiutil attach -nomount ram://$((2 * 1024 * 100)) /dev/disk3  $ diskutil eraseVolume HFS+ RAMDisk /dev/disk3 Started erase on disk3 Unmounting disk Erasing Initialized /dev/rdisk3 as a 100 MB case-insensitive HFS Plus volume Mounting disk Finished erase on disk3 RAMDisk 

Original source: http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/

like image 55
adamse Avatar answered Sep 17 '22 13:09

adamse