When should I use /dev/shm/
and when should I use /tmp/
? Can I always rely on them both being there on Unices?
Answer
/dev/shm
is a temporary file storage filesystem, i.e., tmpfs, that uses RAM for the backing store. It can function as a shared memory implementation that facilitates IPC.
Recent 2.6 Linux kernel builds have started to offer /dev/shm as shared memory in the form of a ramdisk, more specifically as a world-writable directory that is stored in memory with a defined limit in /etc/default/tmpfs. /dev/shm support is completely optional within the kernel config file. It is included by default in both Fedora and Ubuntu distributions, where it is most extensively used by the Pulseaudio application. (Emphasis added.)
/tmp
is the location for temporary files as defined in the Filesystem Hierarchy Standard, which is followed by almost all Unix and Linux distributions.
Since RAM is significantly faster than disk storage, you can use /dev/shm
instead of /tmp
for the performance boost, if your process is I/O intensive and extensively uses temporary files.
To answer your questions: No, you cannot always rely on /dev/shm
being present, certainly not on machines strapped for memory. You should use /tmp
unless you have a very good reason for using /dev/shm
.
Remember that /tmp
can be part of the /
filesystem instead of a separate mount, and hence can grow as required. 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.
Comments
Post a Comment