As solid state drives became more affordable, the TRIM command was introduced to facilitate “garbage collection” of deleted data, allowing the SSD to reset those “unused” blocks back to an “empty” state. This allows for better performance for many SSDs. So I was experiencing random slowdowns etc, so I decided to run a disk speed test, and I discovered this: as you can see the read speed is fine, but the write speed is really slow. The ssd is an Adata SU800 1TB, and it should be a lot faster than this. I dont know if this is a defect with my Mac.
- Trim Enabler 4 2 – Write Faster To Any Ssd Hard Drive
- Trim Enabler 4 2 – Write Faster To Any Ssd Drives
Below you'll find a complete how-to for optimizing your SSD for Linux Mint 20.1 and for Ubuntu 20.04. So that you'll be able to enjoy your SSD for many years!
Contents of this page:
General advice: avoid exaggeration
1. First a word of caution: don't exaggerate! There's a lot of exaggeration to be found on the web on this issue.On the one hand you have people who don't take any special measures for SSD's at all, and on the other hand you see people who take all kinds of extreme and complicated precautions. Neither side is behaving very sensibly.
This how-to is meant to be a 'best practice'. It'll show you how to achieve a very good result by applying just a few rather simple measures. With those, you'll be able to enjoy your SSD carefree, for years and years to come!
Taking into account the long warranty periods that the manufacturers are giving, probably for more than five years (10 years should be a reasonable expectation). Considerably longer than a spinning platter hard disk, anyway...
Below I'll start by mentioning the things I recommend to do. The things that I warn against, are described after that.
BIOS and UEFI: make sure it's set to AHCI
2. A Solid State Disk, or rather Drive (SSD), is usually only recognized properly by the BIOS or UEFI, when in the BIOS/UEFI the feature AHCI has been activated for SATA (instead of IDE). On modern computers AHCI is the default, so that's fine. But on older machines the default might be IDE.This feature may be hard to find in the BIOS/UEFI, because there's absolutely no standardization at all in menu structures for BIOS and UEFI (sigh....).
That's why I've made two screen shots of the BIOS of an older computer, in which you can see this particular feature. Hopefully it'll help you to find it in your own BIOS/UEFI.... The motherboard of that older computer is, by the way, an MSI H61MA-E35 (B3).
Note: doesn't the BIOS or UEFI of your computer offer the option to switch to AHCI? In relatively modern computers that's probably no problem: the BIOS/UEFI will then usually detect the SSD automatically, and automatically select the right BIOS settings for it.
First of all, in the BIOS of my computer I go to the tab Advanced, and there I expand the section Integrated Peripherals (click on the image below to enlarge it):
Then, under the header 'SATA Configuration', I change IDE into AHCI Mode. Namely for SATA Mode.
Then, under the header 'External SATA 6GB/s Configuration', I also change IDE into AHCI. Namely for External SATA 6gb/s Controller Mode.
See the image below (click on it to enlarge it):
Trim Enabler 4 2 – Write Faster To Any Ssd Hard Drive
Check for updated firmware
3. Check the website of the SSD manufacturer, whether there's an updated version available of the firmware for your SSD. If so, apply it.For most SSD's it doesn't matter that you're running Linux, because many manufacturers offer such firmware updates by means of an iso file with which you can create a bootable DVD, much like you can do with an iso file of Linux Mint or Ubuntu.
In the first year after purchase, repeat this check every month or so.
Avoid quick wear: reduce write actions
4. A Solid State Drive is worn down by write actions. Especially the oldest generations of SSD's were vulnerable in that aspect, but to a (much) lesser degree that's still the case for the newer SSD generations.Below you'll find some tips on keeping wear down to a reasonable minimum, by limiting the write actions. Within reason, because a modern SSD is already pretty wear-resistant by default.
When you apply my tips, a lifespan of more than 10 years should be a normal expectation for your SSD. Which is considerably longer than the average lifespan of an old-fashioned spinning platter disk.
Note: these directions are only meant for a Solid State Drive (SSD), not for an old-fashioned conventional spinning hard disk!
During installation: select EXT4
5. The best file system (formatting) for an SSD, is the usual default EXT4. So you don't have to choose anything different in this respect.The journaling that comes with EXT4 causes some write activity, but not very much. Plus journaling is a very important feature for system crash recovery, so you don't want to disable it.
Note: don't select the BTRFS file system! Mainly because it's not as mature as EXT4 yet, but also because it might (under certain circumstances) cause more write actions than EXT4 does.
Set the automatic TRIM job to daily
6. The cleaning action TRIM is recommended for the good performance of your SSD in the long run. Otherwise it might become slow after some time.That's even true for new SSD's: although new SSD's nowadays usually have some form of garbage collection integrated into their firmware, it's always better to execute a regular TRIM as well.
Note: very old SSD's from before 2010 usually don't support TRIM.
In Linux Mint and Ubuntu automatic TRIM is enabled by default, when you install them on an SSD. Namely by a weekly 'job'. But in many (most?) cases, once a week isn't frequent enough: waiting an entire week before recoverable disk space becomes usable again, is simply too long.
You can switch your system to automatic daily trimming as follows:
a. Copy/paste the following command line into the terminal, in order to create a new folder:
sudo mkdir -v /etc/systemd/system/fstrim.timer.d
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
b. Copy/paste the following command line into the terminal, in order to create a new file in that new folder:
sudo touch /etc/systemd/system/fstrim.timer.d/override.conf
Press Enter.
c. Copy/paste the following command line into the terminal, in order to edit the new file:
xed admin:///etc/systemd/system/fstrim.timer.d/override.conf
(Note: the three consecutive slashes aren't a typo, but intentional! For Ubuntu: type gedit instead of xed.)
Press Enter.
d. Now copy/paste this blue text into that empty text document:
[Timer]
OnCalendar=
OnCalendar=daily
Note: the double entry for OnCalendar is no mistake but intentional!
Save the modified file and close it.
e. Reboot your computer.
f. Confirm that you've successfully edited trim's configuration by executing this terminal command:
systemctl cat fstrim.timer
Your output should look approximately like this:
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
ConditionVirtualization=!container
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
# /etc/systemd/system/fstrim.timer.d/override.conf
[Timer]
OnCalendar=
OnCalendar=daily
Let's take a look at this output. The first part shows the default setting (weekly), the second part shows the overriding setting that you've applied. That overriding setting contains two elements: first the existing OnCalendar setting (weekly) is being deleted, and then a new OnCalendar setting is being applied (daily).
If you ever want to check whether fstrim has actually happened, and when it happened, you can use this terminal command:
journalctl | grep fstrim.service
If you're done with this step, you can continue with item 8.
How to undo (back to a weekly job)
6.1. Want to undo? It's easy to change the daily job back to a weekly job, namely as follows:a. Copy/paste the following command line into the terminal, in order to remove the overriding settings:
sudo rm -v /etc/systemd/system/fstrim.timer.d/override.conf
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
b. Reboot your computer.
How to execute TRIM manually
7. You can execute TRIM manually as well. You can use a single terminal command that will execute TRIM on all mounted partitions that support it:Launch a terminal window.
(You can launch a terminal window like this: *Click*)
Type (use copy/paste):
sudo fstrim -av
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
This operation may last for minutes; it then looks as if the terminal has frozen. That's not true, however; simply wait patiently....
Note (1): it's possible that manually executing fstrim with -av doesn't work. In that case, use this command:
sudo fstrim -v /
Note (2): on a few SSD models (specifically two models from Crucial), executing a manual fstrim command when there's high disk activity (I/O activity), might cause problems. So only apply it when there's not much activity going on. Preferably with all other applications closed.
Now proceed to the next item.
Limiting swap wear
8. With the action described below, you limit the use of the swap file or partition (the virtual memory on the SSD). Without disabling it entirely, because that would go too far: in case of very heavy RAM load, your Linux has to be able to 'swap' to the hard disk.Linux's inclination to use the swap, is determined by a setting called swappiness. The lower the setting number, the more system load is required before your Linux starts using the swap.
On a scale of 0-100, the default setting is 60. Which is much too high for normal desktop use; the optimal compromise is probably 20. For SSD's, the default of 60 also causes too many disk writes.
A detailed explanation can be found here (link dead? Then download this pdf file with the same content).
This is the how-to for decreasing the swappiness to a more reasonable level, namely 20:
a. First check your current swappiness setting. Type in the terminal (use copy/paste):
cat /proc/sys/vm/swappiness
Press Enter.
The result will probably be 60.
b. Now type in the terminal (use copy/paste):
xed admin:///etc/sysctl.conf
Press Enter. (for Ubuntu: type gedit instead of xed)
c. Add the following blue lines, at the very end of the existing text in that file (use copy/paste to avoid errors):
# Reduce the inclination to swap
vm.swappiness=20
d. Save the file and close it.
e. Reboot your computer. Then proceed to the next item.
Limiting the disk write actions of Firefox
9. You can limit the disk write actions of Firefox, by putting the Firefox network cache into the RAM and by disabling sessionstore. Like this:Putting the Firefox network cache into the RAM
9.1. By moving the Firefox network cache from your hard disk to the RAM, you diminish the amount of disk writes. This'll probably make your Firefox noticeably faster as well. The price you pay is small: it'll only 'cost' you 300 MB of your RAM.Note: don't do this when your computer has only 2 GB of RAM or less! Because with very little RAM, even 300 MB can't be missed.
Proceed like this:
a. Type in the URL bar of Firefox:
about:config
Press Enter.
b. Now you're being presented with a warning. Ignore it and click on the button 'I accept the risk!'.
c. Copy/paste the following into the filter bar (search bar):
browser.cache.disk.enable
Toggle its value to false by double-clicking it: this will disable 'cache to disk' entirely.
d. Now you're going to make sure that 'cache to RAM' is enabled (it is by default, but it may have been changed earlier). Copy/paste the following into the filter bar (search bar):
browser.cache.memory.enable
This should already be set to true; if not, toggle it to true by double-clicking it.
e. Then you're going to determine how much memory can be used as RAM cache. Copy/paste this into the filter bar (search bar):
browser.cache.memory.capacity
The current integer value will probably be -1, which automates the size of the RAM cache dependent on the amount of RAM. Set it to 307200 (the figure indicates KB, which equals 300 MB). That's usually enough for all amounts of RAM.
f. Close Firefox and launch it again. You're done! Check it like this:
Type in the URL bar:
about:cache
Press Enter.
By the way: you'll then also see a mention of an 'appcache' which is still present on the disk, but there's absolutely no need to move that (much less frequently used) cache to the RAM as well.
Note: This is a user preference. Repeat this hack in each user account.
Disabling sessionstore
9.2. Firefox has a session restore feature, which remembers what pages were opened if Firefox experiences an unexpected shutdown (read: crashes). This feature is neat, but causes many disk writes. Too many for an SSD. Disable it like this:a. Type in the URL bar of Firefox:
about:config
Press Enter.
b. Now you're being presented with a warning. Ignore it and click on the button 'I accept the risk!'.
c. Type in the filter bar: sessionstore
c. Double-click on the item called browser.sessionstore.interval. The default interval is 15000, which means 15 seconds. Add three zeros to the existing value, so that it becomes: 15000000 and click the OK button.
d. Close Firefox and launch it again. Now you've practically disabled the session restore feature.
Note (1): Leave the other cache and sessionstore settings as they are: usually, the less invasive a hack is, the better. Because this reduces the risk of unexpected unwanted side effects.
Note (2): This is a user preference. Repeat this hack in each user account.
Limiting the disk write actions of Chrome
10. The disk write actions of Google Chrome can be limited as follows.a. Click on the three dots (vertical line) in the upper right of the Chrome window - Settings.
Section Privacy and security - Cookies and site data
Preload pages for faster browsing and searching: disable it.
Close Chrome and launch it again.
This way, you've disabled the 'preload' feature, which can cause a lot of extra network traffic and also a lot of writes.
Now proceed to the next item.
Some SSD's: set the scheduler to NOOP
11. By default, Ubuntu and Linux Mint use the I/O scheduler CFQ for some SSD's. Which is good for conventional platter hard disks, but not optimal for SSD's. So if you have only SSD's to deal with, which have the CFQ setting, it's better to change that scheduler into NOOP. Because that's optimal for SSD performance.You can check your current scheduler as follows: use copy/paste to transfer the following blue command line to the terminal:
cat /sys/block/sda/queue/scheduler
(if your drive isn't sda, change the line accordingly)
Press Enter.
For some SSD's, the output will be:
[mq-deadline] none
In that case you don't need to do anything; the scheduler setting is already optimal for your device.
But for other SSD's the output will be:
noop deadline [cfq]
Which means: CFQ is active (because it's between brackets), but NOOP and Deadline are also supported. Change it as follows into NOOP, which optimizes SSD performance:
a. Type in the terminal (use copy/paste):
xed admin:///etc/default/grub
Press Enter. (for Ubuntu: type gedit instead of xed)
Find this line:
GRUB_CMDLINE_LINUX_DEFAULT='quiet splash'
And replace it by this line:
GRUB_CMDLINE_LINUX_DEFAULT='elevator=noop quiet splash'
b. Save the modified file and close it.
c. Now update Grub for this change. In the terminal (use copy/paste):
sudo update-grub
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
e. Reboot your computer.
f. Proceed to the next item.
Optional: set noatime
12. By setting 'noatime', you disable the 'access time stamp', that the operating system puts on a file whenever it's being read by the operating system. For an SSD 'noatime' might be better, because it reduces the disk writes somewhat.Although noatime doesn't make a big difference (which is why setting it has been labeled as optional), it has hardly any negative side effects: only in very rare use cases which almost nobody will ever encounter.
The easiest way to set noatime for your SSD, is this:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Then use copy/paste for transferring the following line into the terminal (don't try to type it: a typo can have serious consequences!):
sudo sed -i 's/ errors=remount-ro/ noatime,errors=remount-ro/' /etc/fstab
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
Note: Do you have a separate partition for /home? Then you need to execute this command as well (use copy/paste, don't type):
sudo sed -i 's/ defaults/ noatime,defaults/' /etc/fstab
Prevent fragmentation, and DO NOT defrag
13. For an SSD, fragmentation of the file system is a smaller problem than for ordinary rotating hard disks. But it's nevertheless still a problem, so it's useful to prevent fragmentation as much as possible on an SSD, too. You can achieve that by preserving a minimum of 20 % free space on each partition (item 4).Prevention is all the more important, as defragmenting is out of the question anyway: your SSD would wear rapidly, because of the many write actions it causes.
The reason that fragmentation is also a problem for an SSD, is this:
The mechanical seek time of an SSD is always 0, regardless of the fragmentation. That's a big difference with rotating hard disks, on which the seek time increases as fragmentation grows. This disappearance of mechanical seek time is a significant improvement.
But mechanical seek time only makes up a part of total access time, or I/O time, of any single input/output request made to the disk.
I/O time is the time a computer system takes to complete a request cycle. All the way from application, operating system and driver down to disk hardware, memory cells, and then back again.
Zero mechanical seek time certainly does not mean zero I/O time. No matter how fast an SSD is, its I/O time can never be zero. File system fragmentation increases I/O time in an SSD, even when the mechanical seek time is zero.
To put it another way: the performance degradation as a result of fragmentation is not caused by the storage device alone (whether there's a mechanical moving part or not), but it's also a problem concerning the system as a whole.
The task for the system becomes heavier, when there are more files to be chopped up and more pieces of files to be glued together. The heavier the task, the longer the processing time.
A good and elaborate explanation of this fact can be found in this pdf file.
Dual boot or Virtual Machine? Don't let Windows kill your SSD
14. Do you have a dual boot with Windows? Then don't let Windows kill your SSD by defragmenting it: disable scheduled automatic defragmentation.Defragmentation will kill your SSD in a very short time, because of the multitude of write actions that it causes. Windows should recognize an SSD by itself and then refrain from automatic defragmenting, but this SSD recognition has been known to fail in several cases. So make 100 % sure that Windows doesn't defragment your SSD automatically, by disabling that feature. Also in a Virtual Machine with Windows!
Within Linux you don't have this problem, because Linux filesystems hardly fragment in the first place and so don't need to be defragmented anyway.
Enjoy your SSD carefree for years and years
15. Now you'll be able to enjoy your SSD carefree!As already said in the start of this how-to: taking into account the long warranty periods that the manufacturers are giving, your SSD will probably last for more than five years (10 years should be a reasonable expectation).
Considerably longer than an ordinary platter hard disk generally lasts, anyway...
For the sake of completeness I mention below some (unfortunately) popular misconceptions about tuning SSD's:
Five pitfalls concerning SSD's
Unnecessary: alignment
16.1. A common misunderstanding is, that the partitions on the SSD should be properly aligned first. That used to be true many years ago, but no longer.In all versions of Ubuntu, Linux Mint and Debian, all tools automatically align filesystems and partitions to the optimal 4096 byte page size. So there's no need to do anything for alignment on an SSD.
Unnecessary: overprovisioning
16.2. Over-provisioning (with or without a dash) is an outdated technique that was widely used to improve the performance and life span of an SSD. I won't explain it here, but it boils down to not formatting a considerable part of the SSD, which then remains unallocated space (unused capacity).That outdated method took a sizeable slice out of the total storage capacity, which made nobody happy....
However, in the newer generations of SSD's (let's say since about 2014) the technology and firmware have improved so much, that such huge losses of storage capacity aren't needed any longer. Modern SSD's usually have some built-in unallocated space for overprovisioning anyway, which isn't accessible to the user.
So overprovisioning shouldn't be necessary anymore.
Strongly discouraged: TRIM by rc.local
16.3. You can also add the TRIM command to /etc/rc.local. Then this command will be executed automatically on system boot. Years ago, this was a good solution that hardly slowed the boot process down.However, things have changed: nowadays there's a boot process called systemd. For systemd it may cause a huge boot delay (minutes!) when you put the fstrim command in /etc/rc.local. So that's why I strongly discourage this method.
Strongly discouraged: TRIM by discard
16.4. Unfortunately, another widely used method for automatic TRIM is to add the option discard to the partition lines in /etc/fstab. This is a heavily exaggerated measure with a high performance toll, and therefore not a good method!The disadvantage of the discard method is namely, that it might regularly cause the system to slow down. Because it forces the system to apply TRIM instantly on every individual file deletion
Trim Enabler 4 2 – Write Faster To Any Ssd Drives
, which is resource-intensive, exaggerated and quite unnecessary. That's why I strongly discourage this method.Strongly discouraged: hibernation
16.5. Hibernation (suspend-to-disk) causes a huge amount of write actions, which is bad for an SSD. In Linux Mint and Ubuntu, it's disabled by default. Don't enable it!Want more tips?
17. Do you want more tips and tweaks? There's a lot more of them on this website!For example:
Speed up your Linux Mint!
Clean your Linux Mint safely
Avoid 10 fatal mistakes
To the content of this website applies a Creative Commons license.
Back to the home page
Disclaimer