How to tweak and optimize SSD for Ubuntu, Linux Mint

I have been using Intel 520 SSD180GB on my Dell Inspiron 11z-1121 laptop for a while and get great speed. However, if you want to tweak and optimize your SSD for Ubuntu, Linux Mint, Debian or any linux distribution to make your SSD run even faster and live longer, here how I do my ubuntu ssd tweak.

Note: this article will help both SSD and mechanical hard drive performance. If you want to improve and tweak your Ubuntu, Linux Mint, Fedora, Centos or any linux distribution, this article will help you.

SSD benefits

  • Faster than traditional HDD, about 2-3 times faster than SATA2 7200 RPM HDD
  • No moving parts
  • Lower heat during operating
  • Uses less power
  • Higher reliability

Update your SSD firmware

SSD manufactures (Intel, Samsung, SanDisk, Plextor, Corsair, Crucial…) often public new firmwares for their SSD to improve
improve performance, reliability, and system compatibility, fix technical issues, bugs). Check your SSD’s manufacture often to make sure you have the latest firmware for your SSD. *** Always backup before you do anything ***

Use EXT4 file system

Most modern new linux distributions default file system is EXT4. EXT4 gives you good speed and reliable for your SSD, EXT4 also supports TRIM. EXT4 is matured for SSD usage since linux kernel 2.6.28. If you have older linux distributions, you may have an option to choose EXT4 as file system, but newer linux distributions will install with EXT4 as default so you don’t need to worry about.

Enable TRIM

TRIM (Trim command let an OS know which SSD blocks are not being used and can be cleared)

Back up fstab first in case something wrong happen.

# cp /etc/fstab ~/fstab.bk

Edit fstab file

# nano /etc/fstab

Add discard to your ssd drives or partitions, after ext4

UUID=bef10b86-494d-41c6-aa46-af72cfba90fd / ext4 discard,errors=remount-ro 0 1

Adding noatime and nodiratime

noatime and nodiratime are mount options in linux for linux file system. noatime disables atime updates on file system, and nodiratime will disables atime updates on directory system. By adding noatime and nodiratime will greatly reduce ssd load means performance gains.

Edit fstab file

# nano /etc/fstab

Add noatime,nodiratime to your ssd drives or partitions, after ext4

UUID=bef10b86-494d-41c6-aa46-af72cfba90fd / ext4 discard,noatime,nodiratime,errors=remount-ro 0 1

Disable hibernation

Hibernate and suspend sometimes don’t work depends on the hardware you have for your system. Sometimes they make your system crash and unstable. Plus hibernation will put a lot of writes to your SSD which will shorten your SSD life.

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

Look for

<allow_active>yes</allow_active>

Change from “yes” to “no”, there are two, one for hibernation, and another one for suspend. If you have to disable them both, make sure to replace them both from yes to no.

<allow_active>no</allow_active>

Tmpfs

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, you can mount /tmp to tmpfs.

Edit fstab file

# nano /etc/fstab

Add the line to the end of fstab file

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

If logs aren’t important for you (laptop or desktop), you can also mount /var/log to tmpfs. Add the line to the end of fstab file

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

Preload

Preload is a Linux software developed by Behdad Esfahbod. Preload learns programs that users use often, records statics using Markov chains, analyzes, and predicts what programs will be most used. Preload then will load those programs, binaries, and dependencies into memory or ram. By having programs already in RAM or memory, it will take less time when you actually start that program or programs.

To install preload on Ubuntu, Linux Mint or debian based distributions

# apt-get update && apt-get install preload

To install preload on Fedora, Centos or Redhat based distributions

# yum install preload

Swap and Swapiness

Swappiness is a part of Linux kernel that let you control how much swap (virtual memory) file is being used. Swappiness values can be changed from 0 to 100. The higher swappiness values the more Linux kernel will try to use swap space, the lower swappiness values means linux kernel will useless or try not to use swap space depends on our setting. The default swappiness value from linux kernel is 60, if your system have plenty have RAM, you should avoid using swap space which writes and reads will be on your SSD or hard drive. For system with 4 GB or more RAM, I would suggest to reduce the usage of swap by changing swappiness settings to between 10 even 0.

To check your swappiness setting on your system, you should see the value of 60 as default.

$ cat /proc/sys/vm/swappiness

The value is up to you to decide. Here is my suggestion

  • 2 GB = 30
  • 4 GB = 10
  • 6 GB or more = 0

To change swappiness setting:

$ su -
# nano /etc/sysctl.conf

And add this line into sysctl.conf file.

vm.swappiness = 10

About the Author: Linux Tips

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.