Tweaking SSD Performance on Ubuntu Linux

Print
Category: Hacks

I really love solid state drives. SSDs are blazing fast, ultra low power, ultra quiet, and generate almost no heat. And technically they should be great to use in a laptop because SSDs are not susceptible to mechanical failure.

The only issue with SSDs is that they can fail to to memory cell wear.

That said, in order to fully capitalize on the performance of a solid state drive in Linux one has to do some manual tweaks. In this regard the internet abounds with posts more or less of dubious reliability ranging from widely recommended practices to more esoteric ones.

Since there is such a huge amount of information on the web I decided to write this up mostly as a personal log of my experience using an SSD.

I run Ubuntu on my work laptop and so far the post How Do I optimize the OS for SSDs on AskUbuntu is a great starting point with lots of suggestions and commentary from various people.

The following has been my experience:

1. Just Plug & Play

At first, for about a year I simply plugged in the SSD, cloned my previous HDD to it and simply ran Ubuntu off of it. I noticed a significant increase in performance. And did not bother with any further tweaks or changes at the OS level.

2. Enable Auto TRIM support, and change the IO scheduler for the SSD

The next step I took was to modify the /etc/fstab configuration to make the following changes to all ext4 partitions off the SSD. Added the noatime, nodiratime, and discard flags for each partition.

/dev/sda2    /               ext4    noatime,nodiratime,errors=remount-ro 0       1
/dev/sda3    /home           ext4    noatime,nodiratime,defaults          0       2

Note: I can only speak for the ext4 file system. I don't know the effects of the flags on other file system types.

After the modifications to fstab the OS must be rebooted for the changes to take effect.

I've also modified the /etc/rc.local configuration to change the I/O scheduler for the SSD from the default cfq to the recommended noop:

# select the noop scheduler for the SSD drive
echo noop > /sys/block/sda/queue/scheduler

3. Manual TRIM

Since I didn't have automatic TRIM enabled, via the discard flag for almost a year I decided to perform a manual TRIM after enabling automatic TRIM support in the previous step.

sudo fstrim /
sudo fstrim /homeĀ 

So far, both steps 2 and 3 have had a dramatic effect on the performance of the drive. Almost as big an improvement as making the initial switch from HDD to SSD.

Design copyright (c) Miky Dinescu