Storage: Optimize SSDs with fstrim

By | January 10, 2017

Using SSD drives is no longer an exception, they are used in home systems but also in server systems to hold at least the OS, or other resources that need more speed than space.
As any other storage disk a SSD can become fragmented as successive write/delete operations will try to use the available storage. This is very bad for SSDs compared to classic spin disks, the degradation in performance is much more noticeable.
The following is a simple procedure to do an automatic clean-up of a SSD in RHEL/Fedora

STEP 1: Install fstrim
There is a ready available tool in Linux (fstrim) that trims a SSD:

From fstrim man page:

fstrim is used on a mounted filesystem to discard (or “trim”) blocks
which are not in use by the filesystem. This is useful for solid-
state drives (SSDs) and thinly-provisioned storage.
By default, fstrim will discard all unused blocks in the filesystem.
Options may be used to modify this behavior based on range or size,
as explained below.

The mountpoint argument is the pathname of the directory where the
filesystem is mounted.

Running fstrim frequently, or even using mount -o discard, might
negatively affect the lifetime of poor-quality SSD devices. For most
desktop and server systems a sufficient trimming frequency is once a
week. Note that not all devices support a queued trim, so each trim
command incurs a performance penalty on whatever else might be trying
to use the disk at the time.

The fstrim command is installed by installing “util-linux” package:

STEP 2: Set an automatic cron job to be executed once per week

Create a file having the following content:

Copy the into /etc/cron.weekly