[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Moving /tmp to tmpfs makes it useless

I've read across different debates about whether using tmpfs is good or bad
but I could not find the most important reason, so here it is...

What's a temporary file? Really, why would applications temporarily store
its data in a file? They do that to *free some memory*. Placing those files
back to memory renders the whole process of writing the file useless.
If the files are small and can stay in memory why would application save it
to file?

Moving /tmp to tmpfs is effectively the same as suggesting to delete /tmp,
because there's no use for it as a temporary files storage any more.

Filesystem Hierarchy Standard defines two directories for temporary files:
/var/tmp — for files that should be preserved between reboots
/tmp — for files that should not be preserved between reboots
It's simple and clear.
Since it's only reasonable to store large data sets in temporary files,
standard sets no size limits for these files. So if application's author
had actually read FHS he should expect these directories to handle
large files.

Who uses /tmp
Let's check the real world and see what applications actually use /tmp.
When you copy files in `mc` they're copied over /tmp/mc-username (to
handle some complex cases, like copying from inside iso-image to ssh).
When you click on a file in Firefox and select "Open with", Firefox stores
that file in /tmp. You cannot assume these files to be small. When you
watch large videos, adobe flash stores downloaded part of it as something
like /tmp/FlashXXG49VWF. Archive managers may unpack archives to /tmp.
CD burners store iso-files there. Image processing software was already
mentioned in this list.

All these files may be large, but should not be preserved on reboot, so
according to FHS they should go to /tmp.

And the most important thing: file managers, browsers, image editors,
cd burners — these are not some rare scientific stuff, but a common
programs, that most people use every day. Putting them on a small tmpfs
will break them. Putting them on large tmpfs may slow down or freeze
the system due to heavy swapping.

Do not mount /tmp as tmpfs by default. Instead...
Debian already allows custom partitioning during the system install. For
example it's possible to mount /tmp on a separate partition. The suggestion
is to extend partitioner with a new option "Configure tmpfs partitions".
That option should allow to mount anything as tmpfs (not just /tmp, but
also /var/run, /media, /opt or whatever the user might want). It would be
nice to have the `size` option there as well.

In that case most users won't get new problems. But really smart people,
that really know what they're doing, will be able to put /tmp on tmpfs
with the options they need.

PS: To save some discussion time I'll try to answer the most common
questions I've seen:

Q: I extremely care about my / fs and want to use it as rarely as possible.
A: There're a lot of options:
   * symlink or mount-bind /tmp to i.e. /home/tmp
   * have /tmp on a separate partition (common and probably best solution)
   * you hate partitions? make /home/tmp_ext3fs.img and loop-mount it.
   That would solve your problem without making your system unstable because
   of high memory usage, or break programs because of no free space in /tmp.

Q: /tmp on tmpfs increases apps performance.
A: What apps? Real apps don't write files during performance-critical
   operations. Even if they do, they write large files. And large files are
   written faster when they're written on real disk, rather then swapped
   out and slow down the entire system (see the "Who uses /tmp" part).
   The apps that can really benefit from tmpfs are too rare. And we're
   talking about default settings and most common cases.

Q: gcc writes small files in /tmp
A: usually it does not, especially when used with -pipe option

Q: Solaris uses /tmp in tmpfs for years.
A: Yes. And Linux uses it on extfs for years.
   And, BTW, Linux's faster than Solaris: http://www.tux.org/lkml/#s9-12
   Solaris had no such a fast extfs, so it had to use tmpfs instead. :)

Q: But still solaris uses /tmp in tmpfs and has no problems
A: That's not true. Solaris users/admins actually have problems because
   of the whole swap space being exhausted by a few iso-files in /tmp.
   The matter is that /tmp is being tmpfs under Solaris for so long that
   solaris admins are used to look for free space in /tmp and fix the
   problems, that linux users never had.
   I don't want to get used to problems, do you?

Q: I'm a smart man, I know what I'm doing, what apps I'm breaking and what
   consequences my decision might have, but I still need my /tmp in tmpfs.
A: Then you should do that. In those rare cases when defaults need to be
   changed they should be changed.

That's it. Thanks for reading.

PS: should I had filled this as a bugreport?


Reply to: