23/01/2005

SHOVEL TIME

This is the second in a series of back-dated site updates that have only just got around to being published

Interlude: tmpfs

Before moving on to installation of Sarge on caco I'd like to mention a little thing I am quite taken with. It's called tmpfs (formerly shmfs) and is built into the linux kernel. It quite simply puts a filesystem in RAM.

How is this helpful? Well, as the name suggests, what you do is mount one over /tmp. When files get created in it they are simply cached in memory. Files unused after a while get swapped out. The thing can grow and shrink, unlike a RAMFS which is created with a fixed size (you give it an upper bound when you mount it, though)

Compare the following two setups:

I hope it's fairly obvious that these two setups are roughly the same. Of course if your /tmp is on disc it won't get wiped if you reboot, but, in Debian at least, /tmp gets cleaned on boot anyway unless you tell it not to (and if you really cared you could write an init script to save and restore a tmpfs on disc)

The only difference is how the filesystem gets synced to disc. With a "normal" disc filesystem this happens quickly if not instantly. A tmpfs is a memory filesystem and files are treated like process data, that is will only go to disc if it doesn't get used for ages. However due to Linux being pretty clever about swapping and the fact that I have lots of memory and huge amounts of swap space, the only effect I've noticed is that writing files to a tmpfs is faster. I can extract a kernel source tarball in half the time. And even though it's 300MB unpacked the computer doesn't slow down or complain of lack of memory! Ice creams all round! Of course it'd screw up if it got too full, so you pick a maximum size wisely and keep an eye on it if things (or people...) fill it up.

The fact is I've got a tmpfs /tmp on both baron and caco and it works fine on both of them. Indeed if anything it works better. In conclusion I think tmpfs is much better for a directory of transient files that do not require disc storage integrity or preservation over reboots.