I’ve seen /dev/shm in df output for years and never once wondered what it was. Turns out it’s a tmpfs filesystem mounted by default on basically every Linux system, and it lives entirely in RAM.

$ df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           7.8G     0  7.8G   0% /dev/shm

It’s there for POSIX shared memory, so processes can map the same chunk of memory and pass data around without going through a socket or a pipe. But it’s also just a normal world-writable directory, so nothing stops you writing files to it:

$ cp big.csv /dev/shm/
$ ruby process.rb /dev/shm/big.csv

Which makes it quite nice for anything you’d otherwise dump in /tmp and delete five seconds later — test fixtures, build scratch space, a big file you’re about to chew through.

The size you see isn’t reserved. It defaults to half your RAM and only uses what you actually write, so an empty /dev/shm costs you nothing. Fill it up though and that’s real memory gone from everything else. Everything in there also vanishes on reboot, and tmpfs pages can get pushed to swap under pressure, so “it never touches the disk” isn’t something to rely on if you care where your data ends up.

If you want to change the size, remount it:

$ sudo mount -o remount,size=2G /dev/shm

And to make it stick, in /etc/fstab:

tmpfs /dev/shm tmpfs defaults,size=2G 0 0