Check if Linux shared memory is using RAM or HDD

/dev/shm/ and /run/shm/ map to a RAM drive on typical Linux systems, useful for IPC. They are also present in Cygwin and Windows Subsystem for Linux (WSL). However, on Cygwin and 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.

RAM or HDD?

  1. examine df -kh /dev/shm and free -h
  2. this uses 1 GB of space on RAM or HDD
    dd if=/dev/zero of=/dev/shm/blah bs=10M count=100
    
  3. recheck df -kh /dev/shm and free -h for which one has 1GB space more used.

Why use /dev/shm for IPC?

For programs very aggressively using shared memory for heavy writing operations, WSL can cause two slowdown problems:

  1. order(s) of magnitude slower /dev/shm/ operations on WSL and Cygwin since HDD is being used instead of RAM
  2. wearing of solid state drive if /dev/shm is pointed there (e.g. C: drive)

Example

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

You’ll see

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

Leave a Comment