Saturday, September 15, 2012

Tuning Linux to play nice on SSDs

While assembling my PC, the first Storage system I bought was a 160 GB caviar green. Sounds silly. It is, except that the reason was I wanted Linux (which as an OS and limited commercial apps) isn't as bloated as windows (you can see me recommending a 30 GB Corsair Nova SSD for linux boot) and therefor does not require so much space. And secondly, the HDD prices when i bought my computer parts were priced through the roof (which I was expected pricing to drop in a 2~4 months based on whatever I read on the net). Unfortunately the prices didn't seem to be falling much (partly because of the depreciation of rupee) and I am stuck with a slow linux installation that I didn't ask for :-(

And hence I decided to move to SSD and use part of my WD RE4 HDD. And the immediate task on hand is how to tune Linux for SSD and HDD install. We are going to use the same principle as we did for Windows 7 tuning, except apply them to Linux:
  1. Write as less as possible to the SSD
  2. Move Core OS, application and configuration files to the SSD
  3. Retain the dynamic OS data, dynamic application data and user storage to the HDD
Luckily compared to Windows the Linux File-system organization is pretty simple and feels more organized and uniform than Windows where applications go about their business anywhere they want.  To begin doing this we need to understand what the Linux root filesystem is composed of. I checked the Linux System adminstration guide as well as my root folder, and here's what we got (this is for an OpenSUSE 12.1 upto date system):

Filesystems suitable for SSD
For my case I need to move this on the SSD. For people doing install for first time. this should be put on the SSD
  • /binLooks like UNIX command line shell commands & utilities. Read only material.
  • /sbin - Looks like Linux specific superuser commands * utilities are here. Read only material
  • /lib and /lib64 - 32/64 bit shared and static libraries. always read, updated but never modified.
  • /mnt and /media - Non-removable and removable storage are mounted here. This is just a link to external file-system in those devices and to my opinion should not cause any writres to local filesystem
  • /etc - Configuration files. Mostly read, occasionally modified. Being on SSD will speed up startup
  • /root - Root's home. it is written as & when root logs in. I rarely use this (thanks to su and sudo). I do not want to  put this on HDD, and stand a risk that root cannot be logged in case I lost the HDD. I  decide let this be on SSD therefore
  • /usr - This is where all application/add-on programs are installed. This has to be the biggest folder on the SSD and this is again mostly read only data with only updates generating the writes.
  • /boot - Has the bootstrap loader or simply boot-loader (GRUB in my case) as well as kernel images. Again this is mostly read-only data and rarely updated.
  • /proc - This is an illusionary filesystem, which isn't on disk  but in memory. We move it to SSD therefore ;-))
  • /lost+found - this is the output of fsck being run when you lose power. This is rarely read and rarely written. I think we will leave it on the SSD and also create one on the HDD
  • /opt - This is used for additional applications and add-on packages not part of the distribution. Since it has just applications, this is mostly read only with updates driven by program updates.
  • /dev -
  • /selinux - security enhanced linux. Its an empty folder on my system . most probably its not installed or configured and I read this is like /proc with a database of policies.
  • /srv - This contains site specific server data for services such as web-server, ftp, etc. Again this is configuration data which is infrequently modified or updated and therefore suitable for SSD
  • /sys - files for PnP hardware and devices. like /proc it is a file system in memory and therefore I do not anticipate any disk writes

Filesystems suitable for HDD
In my case the task on hand is to move them to the bigger 1 TB WD RE4 HDD one by one.
  • /var - System's run-time data. Preferably on the HDD, though I feel if I lose the HDD, I will run into trouble booting the system also. Logs, cache, etc all go here. It can store app data and the difference between /var and /tmp is that /var is not cleaned across reboots and cleamup must be done manually.
  • /tmp - temporary files stored by applications. This is cleaned up automatically on every reboot and can be done manually by root user if it runs out of space. This is really dynamic and we do not want this on SSD and generate the additional writes
  • /run - this has the similar data as in /var/tmp where it survives reboots and is used by both startup programs and applications. This was created by linux community (fedora, OpenSuse, Ubuntu and Debian support this) to take care of some data which was being written to /dev. Good for SSD users.
  • /home - User folder. I will generate the writes heer based on what I am doing. Its best to leave this on the HDD. my data is also here and the only way I can guarantee reliability is to hardware RAID this HDD
  • swap (Linux swap) - I have an 8 GB RAM (had 16 but lost one bank most likely due to ESD), so mostly I need less swap and want this to be on HDD preferably. If I cannot do this, I will put this to SSD, but make a swap not exceeding 2GB.
Counted. 21 folders on my ls-l output and 22 here (the extra one is the linux swap file-system which does not show up in "/" folder). Sorry if the above sounds an abstract of linux SAG, but my intention was to show you what I want to do & why do I want to do that. only 4~5 odd folders should be on HDD.

The choice was now to try and move the existing install from 160 GB to a new SSD and partitions on on the RE4 HDD or just do a clean install. Linux is easy to setup and upgrade. I have only free software, no licensed or pirated one and therefore the 2nd option looked simpler to me. My opportunity came with the upgraded OpenSuse 12.2 release in early September 2012 and I took the plunge. Created Manually 5 HDD partitions (within an extended one) on the HDD for swap (32 GB), /var (20 GB), /tmp (10 GB), /run(10 GB) and /home (178 GB) and just one "/" (all of 27+ GB) on the SSD. The distro accepted my partitiioning scheme and the install went smooth ands now i have a slightly faster booting and importantly a very zippy install with very little lag in starting applications from KDE. And the text console based utils are going insanely fast.

Also their are tones of articles on the web regarding file-system optimizations like addition of noatime, nodiratime, discard to etc/fstab entries for SSD partitions as well as tuning other things like scheduler. I did all of them too. Readers can search "tuning linux for SSD" or something similar to get these ToDos.