Saturday, December 22, 2012

SSD optimisation part 1: Temporary File System (tmpfs)


tmpfs is a file system that stores all files in virtual memory. Everything in tmpfs is temporary in the sense that no files will be created on the hard drive, but resides completely in RAM. This can be very beneficial in some cases. Having files in RAM is a lot faster than on a disk and no writes are made to the SSD at all, saving a lot of wear and tear. Most guides will recommend you make use of tmpfs and it does make sense. There are some cons to consider though, like that everything is lost at reboot. This is a good thing, if you use tmpfs for /tmp as this is the way it should work, but for other uses it could cause problems.

Cons
Sometimes /tmp is used as a working directory for some pretty big files. It could be backup software or DVD authoring tools. If your tmpfs /tmp is using the default settings (50 % of your RAM), then to burn a DVD (4,7GB) with such tools you need to have at least twice that amount available. That is a lot of RAM, but if you have it available, great! If not, maybe you can change the software's working directory or mount a normal /tmp partition.

Debian developers tried to use tmpfs for /tmp as default but this caused some bugs and problems. Here are a few of the complaints from a quick google search: One, two, threefour.

I did a quick test to see what would happen on my system if I ran out of /tmp space with a simple copy to /tmp. The copy operation exited with an error and strange things started to happen. For example TAB completion in the terminal didn't work and gave a disk full error. If the system end up with no RAM left, it could kill or crash the application, lose the files in /tmp (that might still be needed until reboot) or even crash the whole system. This risk of course rise when less RAM is available, as when some is used to host a tmpfs /tmp.

Pros
No files on the SSD means no wear at all. RAM is also a lot faster than even the fastest disk drive. Files in /tmp are meant to be deleted anyway, hence the name, so why not keep them away from the drive completely if possible?

My recommendation
Only use it if you know you have enough RAM. Limit it in size (for example "size=2G" or "size="50%") according to your total available RAM and keep an eye on it in the beginning ("df -h /tmp"). You might also want to look into “ramfs”. If you point other directories to a tmpfs /tmp (like browser cache) be careful that the correct permissions are set.





Hint
If you want Firefox cache in RAM, but don't want to use tmpfs, you could do this instead according to Mozillazine.org:
  • Open up about:config in firefox
  • Set browser.cache.disk.enable to "false"
  • Set browser.cache.memory.enable to "true"
  • Set browser.cache.memory.max_entry_size to the amount of KB you want to use or use -1 for automatic cache size



In Opera you change the cache directory like so:
  • Open opera:config
  • Search for "Cache Directory4"
  • Change it to wherever you like

This post was written for the Linux Mint forum. Please ask any questions there (: