SSD

This article Solid State Drives) on Linux.]]

It presumes the user has obtained knowledge of setting up, partitioning, and formatting mechanical hard drives.

Rootfs
The   option on a rootfs mount should not be used.

is the TRIM command that tells the SSD to do its magic. Having discard running constantly could potentially cause performance degradation on older SSDs. Modern SSDs use discard by default. Rather the following command can be used manually or be setup as a cron job (see below) to run twice a day, which should suffice for the rootfs:

Mount point
Situations with a low amount of disk write occurring on an SSD can use the  mount option in. In a high-write situation, such as having a database on an SSD, it is better to use TRIM commands rather than the  mount option.

Partitioning
See Handbook.

LVM
LVM aligns to MiB boundaries and allows discards by default. No special configuration is required.

In order to TRIM all unused space in the VG use the utility:

Alternatively, there is a discard option in which makes LVM discard entire LV on lvremove, lvreduce, pvmove and other actions that free physical extents (PE) in a VG. However, enabling it will immediately render the system unable to undo any changes to the LV layout.

LUKS
For TRIM to work on encrypted LUKS devices, they have to be opened with the  option.

When root-device exists on LUKS, enabling TRIM depends on the Initramfs implementation. When using genkernel for creating your initramfs, pass the following kernel option:

When using dracut for creating the initramfs, pass the following kernel option:

To evaluate if TRIM is enabled on a LUKS device, you can check if the output of the following command contains the string :

Formatting
If you can find your erase block size, you can add some extended attributes that may help performance. For software raid, you really should know the erase block size. Consider this information when making your purchase. Regardless of whether you're using RAID or not, setting extended values is known to be beneficial. https://raid.wiki.kernel.org/index.php/RAID_setup#ext2.2C_ext3.2C_and_ext4_.282011.29

http://blog.nuclex-games.com/2009/12/aligning-an-ssd-on-linux/

The modern FAQ found on the Arch wiki too:

https://wiki.archlinux.org/index.php/SSD

Without knowing the erase block size

 * 1) Formatting the rootfs partition /dev/sda3:
 * 2) Using 4096 byte blocks by default aligns the SSD for writes (see [defaults] section of /etc/mke2fs.conf and also
 * 3) man mkfs.ext4 about "-b block-size" and "-T usage-type[,...]" inside it):

With knowing the erase block size | this info can be outdated

 * 1) Formatting the rootfs partition /dev/sda3:
 * 2) Using 4096 byte blocks aligns the SSD for writes;
 * 3) Using ERASE_BLOCK_SIZE / 4 as the stride and stripe width size;
 * 4) In this example, OCZ Vertex drives have 512 kibbibyte -
 * 5) Erase Block size, therefore stride/stripe-width = 512/4 = 128:

known erase block sizes

 * crucial m500 240G; stride and stripe width is 2048KB


 * SanDisk z400s; stride an stripe width is 4096KB

blkdiscard
If you are formatting a previously used device and your preferred does not support bulk discards when creating the filesystem, you can use  (from  or later) before creating the filesystem.

Mounting
Given the considerations above, either add something similar to this:

Or:

When choosing the latter, see the cron section below to automate TRIM on the drive.

Once can been modified, run the following command to have the drive mounted:

In the same way, the  mount option can be added to the swap line in fstab too. The following example shows SSD disk swap can be parallelized with SATA disk swap:

Once the swap has been configured in fstab, run the following command to make swap available:

Periodic fstrim jobs
There are multiple ways how to setup a periodic unused block discarding process.

cron
Run from cron twice a day to automatically perform "discard":

#Mins Hours  Days   Months  Day of the week   command 15    1,13   *      *       *                 /sbin/fstrim -v /

fstrimDaemon
If your computer turned off when cron scheduled its job, would not be called at all. You can install fstrimDaemon to solve this problem.

SSDcronTRIM
There is also a semi-automatic cron job available on GitHub called SSDcronTRIM which has the following features:


 * Distribution independent script (developed on a Gentoo system).
 * The script decides every time depending on the disk usage how often (monthly, weekly, daily, hourly) each partition has to be trimmed.
 * Recognizes if it should install itself into, or any other defined directory and if it should make an entry into.
 * Checks if the kernel meets the requirements, the filesystem is able to and if the SSD supports trimming.

systemd timer
When running a system with systemd version 212 or newer, a persistent systemd timer can be created that will run every 12 hours.

Two systemd unit files need to be created in the directory:

Service called  which actually executes the :

Timer which wakes up the  service every 12 hours:

Make sure the permissions are correct:

Tell systemd to reload its unit files, then enable it:

It is now possible to see if it has been run and when the next time it will be ran by using list-timers:

This will run fstrim twice a day, and also run it if it was missed. The command can be used to make sure the timer runs successfully.

Reducing amount of writes
The flash-based SSDs have a limited write lifetime - the number of writes performed. Thus when using a SSD, administrators generally want to reduce the amount of writes.

Portage TMPDIR on tmpfs
When building packages via Portage it is possible to perform the operations on tmpfs and get the tmpfs' benefits. See Portage TMPDIR on tmpfs guide.

Temporal files on tmpfs
It is possible to mount desired mount points as tmpfs. Since tmpfs stores files in volatile memory all the I/O operations directed to the given mount points are not performed on the solid state disk. This reduces the amount of writes and also improves performance.

This is an example of both and  being mounted as tmpfs:

XDG cache on tmpfs
When running a Gentoo desktop, many programs, using X Window System (Chromium, Firefox, Skype, etc.) are making frequent disk I/O every few seconds to cache.

The cache directory location usually complies to XDG Base Directory Specification, namely to the XDG_CACHE_HOME environment variable. The default cache location is, which is usually mounted on a hard drive and could be moved to tmpfs.

To remap the cache directory location create file :

Web browser profile/s and cache on tmpfs
The web browser profile/s, cache, etc. can be relocated to tmpfs. The corresponding I/O associated with using the browser gets redirected from the SSD drive to tmpfs' volatile memory, resulting in reduced wear to the physical drive and also improving browser speed and responsiveness.

You can relocate the browser components mentioned above with the utility :

Next add the users whose browser/s profile/s will get symlinked to a tmpfs or another mountpoint in the variable :

Finally, close all the browsers, start and enable the daemon.

On systemd:

On OpenRC:

Now it is possible to view all symlinks by printing the status of the started daemon:

More info about Profile-Sync-Daemon can be found on Arch's wiki.