The world seen from the eyes of a penguin

Category: SSD

This is my memorandum every time I have to install the above distributions on a SSD.

SSD Trim

Firstly check if your SSD supports TRIM

sudo hdparm -I /dev/sda | grep "TRIM supported"

It is if you get something like

* Data Set Management TRIM supported (limit 8 blocks)

Since Ubuntu 14.04 (and all derivatives) TRIM has been enabled by default, unfortunately this will work only for Intel and Samsung SSDs because some cheap SSDs can even brick themselves when running TRIM.

This doesn’t mean TRIM should only be used with those brands, but to avoid running into issues, this is the default option for now. What we have to do now is to bypass the vendor check by editing the /etc/cron.weekly/fstrim file and adding the –no-model-check option to the last line:

sudo nano /etc/cron.weekly/fstrim

#!/bin/sh
# call fstrim-all to trim all mounted file systems which support it
set -e
# This only runs on Intel and Samsung SSDs by default, as some SSDs with faulty
# firmware may encounter data loss problems when running fstrim under high I/O
# load (e. g. https://launchpad.net/bugs/1259829). You can append the
# --no-model-check option here to disable the vendor check and run fstrim on
# all SSD drives.
exec fstrim-all --no-model-check

TRIM is setup by default to run once a week, in fact

$locate fstrim
/etc/cron.weekly/fstrim

To experiment the TRIM command manually:

sudo fstrim -v /

noatime and nodiratime

noatime and nodiratime are mount options for linux file system. noatime disables atime updates on file system, and nodiratime disables atime updates on directory system. By adding noatime and nodiratime will greatly reduce ssd load means performance gains.
From the source code if NOATIME is set, then NODIRATIME flag is never even checked, so we just need to disable noatime only.

Edit fstab file and add noatime to your ssd drives or partitions, after ext4, nodiratime is not needed:

Disable hibernation

Hibernation will put a lot of writes to your SSD which will shorten its life. We can disable these feature.

# nano /usr/share/polkit-1/actions/org.freedesktop.upower.policy

Look for

<action id="org.freedesktop.upower.hibernate">

and change

<allow_active>yes</allow_active>

to

<allow_active>no</allow_active>

Temporary files and logs

Files and directories store in tmpfs is temporary, tmpfs keeps everything in virtual memory (kernel internal caches), nothing will be saved on your hard drive or SSD. Once your system is restarted, everything in tmpfs will be gone. Normally linux system cache stores in /tmp directory. To reduce writes on SSD, we can mount /tmp to tmpfs.

Edit fstab file

nano /etc/fstab

Add at the end:

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

There is one potential issue, tmpfs tends to allocate lot of your RAM for the temporary file system. For instance, on my 6GB ultrabook it was allocated 2.9GB of RAM.

This could be annoying, we can specify a precise size limit:

tmpfs /tmp tmpfs defaults,noatime,size=200mb,mode=1777 0 0

tmpfs /tmp tmpfs defaults,noatime,size=1G,mode=1777 0 0

or expressing a percentage:

tmpfs /tmp tmpfs defaults,noatime,size=10%,mode=1777 0 0

Having the history of logs is not so important for me, we can also mount /var/log to tmpfs. Add this at the end:

tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0

Limit the content cache of Firefox

To limit the writes on SSD while surfing we can limit the web content cache.

Firefox panel: Edit => Preferences => Advanced
Tab Network

Cached Web Content: tick on Override automatic cache management anddecrease it from 350 to something lower, I usually set it to 50 MB but you can also set it to 0.

Limit the content cache of Chromium

Unfortunately Chromium doesn’t allow to change the cache policy from its settings, then we need to edit the default configuration:

sudo nano /etc/chromium-browser/default

and for a 10MB cache edit as follows:

# Default settings for chromium-browser. This file is sourced by /bin/sh from
# /usr/bin/chromium-browser
# Options to pass to chromium-browser
CHROMIUM_FLAGS="--disk-cache-size=10000000"

Instead, if you need the using of cache, you can simply move it to a different folder on a not SSD disk:

CHROMIUM_FLAGS="--disk-cache-dir=/media/not_ssd_disk"

Check the scheduler

This should not be an issue anymore, but check that the deadline scheduler is selected: