Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/tmp vs. /dev/shm for temp file storage on Linux?

Tags:

I have scripts that make hundreds of quick succession, small, temp files needing to be created and very soon read back in, then unlinked.

My testing shows little if any performance difference by putting said files in /tmp (to disk) or into /dev/shm (filesystem-level shared memory) on Linux even under moderate load. I attribute this to the filesystem cache.

Granted the disk will eventually get hit with the fileystem actions, but on multiple small write-read temp files, why would you (not) recommend /dev/shm over disk-backed directory? Have you noticed big performance increases with shared memory directory over a cached VFS?

like image 964
Jé Queue Avatar asked Mar 16 '12 22:03

Jé Queue


People also ask

Does Dev SHM use disk space?

/dev/shm is a temporary file storage filesystem (see tmpfs ) that uses RAM for the storage. It can function as shared memory that facilitates IPC. It is a world-writeable directory. The size of /dev/shm is limited by excess RAM on the system, and hence you're more likely to run out of space on this filesystem.

What is tmpfs Dev SHM in Linux?

shm / shmfs is also known as tmpfs, which is a common name for a temporary file storage facility on many Unix-like operating systems. It is intended to appear as a mounted file system, but one which uses virtual memory instead of a persistent storage device.

Is Linux tmp RAM?

Temporary files on Linux have traditionally been written to /tmp, at least those that don't need to persist across boots. Several Linux distributions are now planning to mount /tmp as a RAM-based tmpfs by default, which should generally be an improvement in a wide variety of scenarios—but not all.

How big is Dev SHM?

Note the /dev/shm partition now has 3 GB of space available.


2 Answers

/dev/shm is intended for a very special purpose, not for files to be put to by arbitrary programs.

In contrast, /tmp is exactly made for this. On my systems, /tmp is a tmpfs as well, in contrast to /var/tmp which is designed for putting larger files, potentially staying longer.

like image 98
glglgl Avatar answered Sep 22 '22 14:09

glglgl


It is essentially the same (shm is also backed implicitly by the disk when you have a swapfile).

/tmp has the advantage that it fills up harder (considering your hard disk is likely larger than your swapfile). And also it is more widely supported.

like image 32
ᅙᄉᅙ Avatar answered Sep 23 '22 14:09

ᅙᄉᅙ