Enable TRIM On SSD (Solid-State Drives) In Ubuntu For Better Performance
TRIM allows the OS to “inform a solid-state drive (SDD) which blocks of data are no longer considered in use and can be wiped internally“. Without using TRIM, the SSD speed decreases after a while so if you have a solid-state drive that supports TRIM, you should enable it so your SSD remains fast over time.
This isn’t easy to benchmark because the performance decreases over time so you’d neet to check the SSD speed constantly for a few months to see exactly how the SSD is affected when TRIM is not enabled. But if your SSD read / write speed decreases a lot over time and you haven’t enabled TRIM, this may be way.
Some articles mention using online discard – enabling TRIM by adding the “discard” option to /etc/fstab -, but there are many who say this isn’t a good idea for most solid-state drives and you’ll get a pretty significant performance hit when trying to delete a large number of small files. So below I’ll let you know how to use both of these methods: online discard (not recommended) and the recommended way: using fstrim and a cron (anacron) job.
Note: the instructions below have been tested in Ubuntu, but they may (most probably) work with other Linux distributions as well.
Before enabling TRIM, you must make sure:
you’re using the Linux Kernel 2.6.33 or neweryour SSD supports TRIMthe partition(s) are EXT4 or BTRFS*
* Since not many people are using BTRFS, this post will only cover enabling TRIM on EXT4 partitions.
If you’re unsure if your SSD supports TRIM, you can run the following command:sudo hdparm -I /dev/sda | grep “TRIM supported”
Where “/dev/sda” is the solid-state drive (it may be /dev/sdb, /dev/sdc, etc. for you), and the command should return something like this: “Data Set Management TRIM supported (limit 8 blocks)” (if there’s no output, your SSD doesn’t support TRIM).