Comment 0 for bug 18661

Revision history for this message
John Moser (nigelenki) wrote : Temporary /tmp and /var/tmp

Because temporary files are temporary, there is no need to eventually write them
to disk. Tasks which rapidly create, alter, and remove temporary files will
have extra write-back cache flushed to disk needlessly (i.e. journals?), and
will incur checks in the file system driver to locate enough allocation space.
This can slow down tasks relying on heavy short term usage of /tmp.

I find that a more optimal configuration seems to be to use a tmpfs on /tmp and
/var/tmp, to avoid disk usage for short-lived files such as files being used by
apt or synaptic. The space on a tmpfs is treated similarly to disk cache,
except that it gets swapped out rather than invalidated; the decision to swap is
made under the disk cache rules.

Using a tmpfs, rapidly created, altered, and deleted files stay in memory until
removed, and space allocation is the much simpler task of checking how much
memory is available and how much is used in the tmpfs; in the worst case, longer
lived file data will swap out. Swapping is less intrusive than managing a file
system, so it is negligibly faster, though not noticibly. The avoided disk
access is nice, but also /tmp self-cleans on reboot and is almost absolutely
unrecoverable; a crypted swap partition would make it impossible to recover.

Below are fstab lines that set up a tmpfs on any amount of ram (1M, 256M, 4G,
etc). I always set it as 2G in size because that much will never be used; it
uses the same amount of memory no matter the value of size.

# temporary file systems
none /tmp tmpfs size=2G,nr_inodes=200k,mode=01777 0 0
none /var/tmp tmpfs size=2G,nr_inodes=200k,mode=01777 0 0