SSD Optimisation

De Organic Design

I've had one too many mechanical disk failures and have finally decided to move over to SSD. They still have a long way to go as a technology since they still suffer from the major problem of flash technology in general which is that each memory bit can only be written to a thousand times (3 thousand on the most recent technology). So I'm just going to get a small cheap one initially and hopefully in six months or so they'll be longer lasting and more practical sizes. I've started with a 120GB Samgsung 840 series, for these reasons. Most of the following optimisation tips are taken from SSD optimisation in the Debian wiki, and another good artile here in the Arch Linux wiki.

Swap

Most systems these days have enough RAM that they rarely ever use the swap file at all unless there's a bug that chews up memory. If you have 4GB or more you may as well disable the swap partition completely from /etc/fstab or by installing your OS with no swap in the first place.

I upgraded my RAM to 8GB when I got the SSD and then installed Debian 7 with no swap by electing to manually set up my partitions and then making a single primatry partition that occupies the entire disk. The installer strongly warns against continuing without a swap partition, but allows you to continue and installs fine without it.

Mount options

There are some important mount options that should be enabled in /etc/fstab for the filesystem on SSD paritions. The filesystem should be ext4 not ext3 to work well with an SSD.

  • discard: SSD's use the ATA TRIM command for sustained long-term performance and wear-leveling, but it needs to be activated by adding the discard mount option.
  • noatime: Use this option to prevent logging of read accesses to the file system via an update to the atime information associated with the file.
  • commit=N: Set this to the number of seconds to wait before committing changes to the physical storage. By waiting longer before performing a journal commit multiple writes are often performed in one go. This option is often ised on laptops when running on battery to reduce the number of spinups for the drive saving power.

Using RAM disk

To mount /tmp and /var/log in RAM. Add these lines to the end of /etc/fstab to mount them in tmpfs (temporary file system). Debian-based operating systems already mount /var/run and /var/lock to RAM-disk by default.

tmpfs /tmp     tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0

Save, then sudo mount -a and reboot for the changes to take effect. Running df, you should see a new line with /tmp, and /var/log mounted on tmpfs.

My current /etc/fstab file looks as follows, I used slightly different parameters than those recommended above so they matched those already being used for the /var/run and /var/lock mount points.

UUID=123****789 /         ext4   noatime,discard,commit=60,errors=remount-ro  0  1
tmpfs           /tmp      tmpfs  rw,nosuid,nodev,noexec,relatime              0  0
tmpfs           /var/log  tmpfs  rw,nosuid,nodev,noexec,relatime              0  0


Another long regularly changing log file I found was .xsession-errors in my home directory. I moved this into /var/log which is in RAM disk by editing /etc/X11/Xsession and changing the ERRFILE setting to:

ERRFILE=/var/log/.xsession-errors

Digital coin log files

The debug.log files in the digital coin apps such as Bitcoin, Litecoin and Namecoin reside in the user's data directory and are very active files which on an SSD are best in RAM. These files can be linked to the syslog which is in RAM (if the configuratons above have been done). Or even linked straight into /dev/null.

Creating log files on startup

Some services will fail to start if the log files or their directories don't exist. I added a few lines into their startup scripts in /etc/init.d in their "start" case to fix this (Note: make sure it's in the start case not the start function). The ones I had to do this for were as follows.

Nginx
if [ ! -d "/var/log/nginx" ]; then
   mkdir /var/log/nginx
fi


MariaDB
if [ ! -d "/var/log/mysql" ]; then
   mkdir /var/log/mysql
   touch /var/log/mysql/mariadb-bin.index
   chown -R mysql:mysql /var/log/mysql
fi

SSD links

Comentários