How To Optimize Linux For SSDs

Get the most out of your SSD in Linux – here’s what you need to know.

Linux is pretty great out-of-the-box, there are still some items that require a little bit of manual optimization to get them going as smoothly as possible. Controlling power consumption is the most common one, but optimizing your system for SSDs is another important one. And it’s important to do so, because well-maintained SSDs are a joy to have.

To get the best performance and least wear-and-tear on your solid state drive, try these optimizations for your Linux system.

Update Your Distribution

While I don’t think this will be an issue for most people, it’s still worth mentioning. In order to take advantage of the latest optimizations in applications, kernel, filesystem, and much more, it’s best to run the latest version of your favorite distribution. If even if you’re on older but still-supported releases (such as Ubuntu 12.04), it’s best to upgrade to the latest version (such as 14.04) as there have been a ton of changes that make the operating system much more SSD-friendly.

Update SSD Firmware

It’s also a good idea to upgrade the firmware on your SSD. The instructions on how to do this is different for each vendor, so you’ll need to look up instructions for your specific SSD. Be aware that some (but not all) don’t allow the firmware to be updated via Linux; instead, you’ll need to use a specific bootable environment (similar to a Linux live environment) or a Windows utility to do the job.

Use ext4

linux ssd ext4   How To Optimize Linux For SSDs
When you’re freshly installing a Linux system, it’s best to use the ext4 filesystem. It’s the most used, and most stable, filesystem available that supports TRIM (which still needs to be enabled – more on that below).

This shouldn’t be much of a problem: most distributions default to ext4.

Mount Options At Boot

linux ssd fstab   How To Optimize Linux For SSDs
Every time you boot your Linux system, it must mount the various drives in your computer in order to use them. There are various mount options you can use, depending on your hardware and your needs, and some are appropriate to use with SSDs.

To make these changes, open up your terminal and run the command sudo nano /etc/fstab. Next, find the partition(s) in your SSD(s) that are listed in this file. Partitions here are normally listed by UUID, which is more precise than the /dev/sdXY identification system. If you have multiple partitions, you can use the command blkid /dev/sdXY to find the UUID, replacing X with a-z and Y with 1-9.

Then, add the following mount options: discard and noatime. Discard allows the SSD’s TRIM function to be used – this improves performance and longevity. The other option, noatime, tells the filesystem to not keep track of last accessed times – just last modified times. This can reduce wear and tear on your SSD, because there are many files that you access while you use your computer but there are far fewer files that you’ll end up modifying. The file should look similar to the screenshot above.

If you find that some programs are misbehaving with the noatime option (as last accessed times will be before last modified times, which is normally impossible), you can replace noatime with relatime. This updates the last accessed time with the same value as the last modified time, all in the same write operation.

Don’t Use SWAP

linux ssd noswap   How To Optimize Linux For SSDs
When using an SSD, it’s also a very good idea to not have a SWAP partition on it (unless you have a serious reason to do so).

The constant reads and writes SWAP partitions do add significant wear-and-tear to the SSD. If you really would like to have a SWAP partition, it’d be better to place it on a secondary, non-SSD hard drive if at all possible. I know it’s tempting to put a SWAP partition on an SSD – it would be the best-performing SWAP partition you’ll ever have – but this speed comes at a major cost.

A lot of people suggest that you can still add a SWAP partition but disable hibernation, since that causes extreme amounts of reads and writes. But since it’s rare that you’ll use a SWAP partition, as you probably have more than enough RAM, it’ll just take up space and potentially cause wear-and-tear. Also, not including a SWAP partition to begin with is an easy way to disable hibernation

Conclusion

These tips should get you well on your way to a much more optimized SSD experience on Linux. And your SSD will thank you by lasting a few years longer than it would without these optimizations. If you feel lucky, you can research even more SSD-related optimizations that may not be for the faint of heart. It’s up to you, but these tips do the most amount of good for your SSD. Most other tweaks are only nitpicks that provide a minimal difference.

What SSD optimizations can you recommend? What’s your opinion on how SWAP should be handled? Let us know in the comments!

Image Credits: Robert Via Flickr

17 Comments - Write a Comment

Reply

Ed

“… the Linux kernel handles such real-time TRIM commands in a slow, unoptimized way. Enabling TRIM similar to how Windows does — that is, using the “discard” option — results in the system actually becoming slower than if TRIM were not used at all. Ubuntu and other Linux distributions don’t enable “discard” by default for your file systems, and you shouldn’t either.”

Source:
http://www.howtogeek.com/176978/ubuntu-doesnt-trim-ssds-by-default-why-not-and-how-to-enable-it-yourself/

Granted, the above quote is for a Dec 2013 article, but I believe even in Ubuntu 14.04, a weekly cron job for fstrim is used instead of the discard option. I believe my Xubuntu 14.04 install runs a weekly cron job using fstrim. Even Android starting with version 4.3 is using a a task to run fstrim on occasion.

Am I wrong?

Please clarify and thanks for reminding us to enable Trim in Linux.

Reply

dragonmouth

How about putting /var, /tmp and frequently written-to files on a non-SSD drive?

dirk dierickx

/tmp shouldn’t be on any drive, use tmpfs!

Reply

Anders Jackson

How about check the number of writes and how many writes the device support and see if it actually a ordinary HD will survive that time?

Reply

John

> How about putting /var, /tmp and frequently written-to files on a non-SSD drive?
How about putting everything on a non-SSD drive?
This way the SSD-drive will last longer, and be faster if you check again if it is still empty .
:-)
Kidding, but I would leave these files on the SSD, because I can write/read faster on my SSD than on my non-SSD.

Reply

Kriston

SSD longevity is no longer an issue. The industry shot themselves in the foot making a big deal over “wear leveling” in years past. Any SSD bought in the last five years will far outlive the life of any spinning hard drive no matter how heavily it is used and no matter what settings you have.

Dragonborn

Very well said Kriston. I believe exactly the same. All these optimization/long living tips, were good until 2010 maybe. Additionally, the prices are down compared some years ago thus, buying a new SSD is not a big concern anymore.

Reply

Ant

What if the computer only has a SSD and no HDD?

Reply

Will

You could use ZRAM to avoid putting the swap space on your SSD. ZRAM creates a compressed swap space in RAM, at the cost of CPU cycle and some RAM. The ZRAM module is stable on linux kernel 3.14 onwards.

Reply

Donald Dogshit

If the machine needs to write to swap, it does so because it’s low (or damn near out of) physical memory. Using ZRAM would be insanely counterintuitive on a low(ish) memory system, since it ould only compound the problem. You’re setting aside some space in an already constrained resource.

It would – of course – function as described in a high memory system.

BUT

Not to be a troll or unnecessaily controversial, but In high/ultra high memory systems it’s questionable if a swap partition is even necessary any longer.

Ron

Are all (or even many) laptops considered “high/ultra high memory systems”?

Reply

Michael Jones

noop

Reply

Donald Dogshit

No, but it’s not uncommon to find 8GB memory in many current laptops, and up to 16GB in some. I’d argue that at 8GB it’s questionable whether or not /swap is really necessary. At 16GB, it’s not. A careful; “what will I use this to do?” thought exercise would help determine if eliminating the swap partition is a good idea or not. If the user intends to do a shedload of Photoshop or CAD *shudder* then…errr…even at the cost of the sacrifice of some SSD life…deploy /swap.

Lastly, It’s only fair to include the view that IF there’s a serious amount of memory, then /swap will only rarely be used, & only in weird circumstances. Deploy /swap *anyway* as a matter of good practice. Honestly, what bothers me a little more than /swap is /var/log and here’s why; it *does* get used – a lot, and the writes are TINY – exactly what’s bad for SSD’s.

IF the laptop design accommodates using the DVD drive bay as an extra H/D bay, then the purist solution would be to locate /var & /swap on spinning rust thus rendering this part of the SSD discussion moot.

Lastly, and concerning laptops, I quote a colleague of mine, who – after reading this article and the comment thread – tartly observed; “So what? at the speed SSD prices are dropping, the reduction is lifespan resulting from long term heavy use of /swap and /var/log, if the SSD dies prematurely, replace it with no more regret (or hit on the wallet) than you would a spinning H/D. If you’re *that* concerned, then invest in an enterprise class SSD, many of which will write PB’s of data for years before using up all writeable blocks.” Another colleague, leaning towards the same side of the argument, remarked that even consumer-grade SSD’s with decent ratings/specs will – under “normal” usage – last for the lifetime of the laptop itself.

So yeah, here’s a fairly decent range of views from the purist to the pragmatist. I trust that the above contributes to the discussion.

Reply

Eddie G. O’Connor Jr.

The whole point of SSD drives was the “no mechanical parts” thus the wear & tear the industry speaks of is strictly in reads/writes and the amount of and speed of reads and writes a SSD can have will always be larger than any spinning drive. SO at this point in time trying to “optimize” it is almost a wasted effort, granted there might be a time in the future where an SSD which has been in service for quite some time might need optimizing to squeeze just a little more life out of it, but these things are so robust that it probably won’t be in our lifetimes…..I’m just sayin’ LoL!

Reply

kayla

If your MLM has been running you ragged, consider the video aspect of it. You can use Modulates or another site to ramp up your video.

Reply

Johnnie

@ Eddie
The intention of this article is not to optimize an SSD for performance but rather lifespan of the drive. Even some of the slowest SSDs can out perform a standard HDD.

Reply

David

There are a number of bad ideas in this article, based on common myths and misunderstandings.

First, never use the “discard” option. Online TRIM is a bad idea. This is not because the Linux kernel’s implementation is poor – it is that the specifications of the TRIM disk command are idiotic. I don’t want to go into details here – look them up if you want. But the result is that “discard” makes metadata operations far slower. It is much better to do an offline “fstrim” on occasion (I believe many distros will do that by default) – or if you have a reasonably modern SSD that is fairly good quality, just ignore TRIM altogether and let the SSD’s garbage collection and overprovisioning handle everything.

You will /never/ wear out your SSD – modern devices can be written to continuously for years without wearing out. So put /var, swap, etc., on the SSD without worrying.

The most efficient choice for /tmp is tmpfs. If you want to store a lot of files in /tmp, keep it tmpfs and make sure you have plenty of swap. It is faster (and less wear on your SSD) to have files in tmpfs spilled out into swap than putting them on a normal filesystem.

ext4 is a good filesystem, but not because of “discard”. btrfs is also a solid choice these days for people looking for more features.

Your comment