Philipp's Computing Blog

Success is about speed and efficiency

SSD optimizations on Linux

  • Use the mount option relatime (or noatime if you are brave) for the SSD partitions in /etc/fstab.
  • Replace several directories (those, the system writes to frequently) with a tmpfs file system as shown below.
  • Disable Firefox caching by setting browser.cache.disk.enable to false in about:config.
    Alternatively create the entry browser.cache.disk.parent_directory and set it to /tmp.
  • Tell grub2 to boot the kernel without optimisation for regular HDDs by adding elevator=noop to the GRUB_CMDLINE_LINUX_DEFAULT= parameter in /etc/default/grub. Afterwards run sudo update-grub2.
    If you want to use the elevator deadline (not noop) you may enable the fifo_batch for sda: echo 1 > /sys/block/sda/queue/iosched/fifo_batch
  • Try write-back caching instead of write-through by running hdparm -W1 /dev/sda. If this succeeds add it to /etc/rc.local.
  • Disable hibernation (writes large amounts of data to the SSD): See above.

Append this to /etc/fstab in order to replace /tmp, /var/tmp and /var/log with ramdisk folders:

# mount /tmp to ram (tmpfs)  
tmpfs   /tmp   tmpfs   nodev,nosuid,noexec,relatime,mode=1777,size=15%    0    0
tmpfs    /var/tmp    tmpfs    defaults,size=5%    0  0
tmpfs    /var/log    tmpfs    defaults,size=5%    0  0

But you also need to recreate some folders (in order for some programs to be happy). So add the following script in your /etc/rc.local just above exit 0:

#!/bin/sh
# you may want to add more folders to be checked/created to this list:
for dir in apparmor apt ConsoleKit cups dist-upgrade fsck gdm installer news ntpstats samba speech-dispatcher unattended-upgrades; do
  if [ ! -e /var/log/$dir ] ; then
    mkdir /var/log/$dir
  fi
done

To disable hibernation completely, tell Policy Kit hibernation is forbidden for all users:

cat << EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/02-disable-hibernation.pkla
  [Disable hibernate/suspend for all groups]
  Identity=unix-group:*
  Action=org.freedesktop.upower.hibernate
  ResultActive=no
  ResultInactive=no
  ResultAny=no
EOF

resources