Detect tmpfs shmem RAM or HDD

/dev/shm/ and /run/shm/ map shmem shared memory to a RAM drive on typical Linux systems, useful for IPC. They are also present in Windows Subsystem for Linux (WSL). On WSL, they write to HDD instead of RAM. It’s easy to tell if RAM vs. HDD is being used for shared memory, since RAM has GB/sec speeds vs. HDD having MB/sec speeds.

Note free space in df -kh /dev/shm and free -h Write 1 GB to shmem:

dd if=/dev/zero of=/dev/shm/blah bs=10M count=100

Recheck df -kh /dev/shm and free -h for which one has 1GB space more used. This tells if hard drive or RAM was used.

For programs using shared memory for heavy writing operations:

  1. order(s) of magnitude slower /dev/shm/ operations when HDD is used versus RAM
  2. wearing of solid state drive if /dev/shm is pointed there

Example data bandwidths:

  • SSD: 100s of MB/sec
  • HDD: 10s of MB/sec
  • RAM: 1000s of MB/sec

macOS RAM drive

macOS doesn’t have tmpfs shmem enabled by default, but a macOS RAM drive can be created.