How To Optimize Linux For SSDs
Whatsapp Pinterest
Advertisement

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 PowerTOP Will Maximize Your Linux Laptop's Battery Life PowerTOP Will Maximize Your Linux Laptop's Battery Life On Linux laptops, one of the most common complaints is that the battery life isn't that great. You can find out what settings are best for your system using PowerTOP. Read More 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 Should You Get A Solid State Drive (SSD)? [Opinion] Should You Get A Solid State Drive (SSD)? [Opinion] If you've kept up with some of the latest news about new computer parts, you may have heard about SSDs, or solid state drives. They are designed to replace your clunky, slow hard drive and... Read More .

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
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
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
When using an SSD, it’s also a very good idea to not have a SWAP partition What Is a Linux SWAP Partition, And What Does It Do? What Is a Linux SWAP Partition, And What Does It Do? Most Linux installations recommend that you include a SWAP partition. This may seem odd to Windows users – what is this partition for? Read More 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

Explore more about: Hard Drive, Solid State Drive.

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Neil Darlow
    July 20, 2018 at 8:54 pm

    I would use a SSD to complement an HDD. Good candidates for the SSD would be /boot for faster kernel and dynamic module loading and /usr for faster access to binaries and dynamic libraries.

    Both of these filesystems are mostly readonly unless they are being subjected to updates. The remaining filesystems I would put onto HDD on the basis that they are subject to more frequent writes and might be used for creating snapshots of non-retrievable content.

  2. Anonymous
    June 30, 2018 at 8:09 pm

    Having no SWAP causes some applications to not start, others applications fails at some point; it is too risky not have SWAP at all.

    My recomendation is to have a small SWAP (less than 1/2 of RAM) and ensure you have enough RAM for all applications so SWAP get not used except for thoose applications that requieres it.

    For example on an 8GiB RAM i define a SWAP partition over a LVM2 stripped partition over two SSD (1GiB on each, so 2GiB SWAP). And i have the system monitor open to see how much SWAP the system uses along time (as a graph), then test one by one all APPs i want to use and check how much RAM and if SWAP get used.

    Only with a few APPs SWAP is used while free RAM is never ever less than the half.

    Oh, yes SWAP is used with more free RAM than half of total RAM, but only when some applications are used (some of WINDOWS under wine, some Linux native ones).

    The trick with SSD is to allways have at least 60% of it free at all times, so their life is extended to more than 250 years with a 10GiB written per day 366 days per year. Also better to use LVM2 striped over two SSDs, that makes live to go over five hundred years.

    No RAID level avoids BackUPs, allways clone the system periodically (after updates), so better use RAID 0 kind (striping) to improve speed. To all people saying using striping is risky because if one disk fails all gets lost, i say: nothing is lost because you must have a recent BackUP, only last things not BackUPed. Do not have fair to use stripping, more if you use SSD, on rotational disks (on old Operating Systems) if one disk do not serve data on-time, it causes a fail, modern operating systems do a re-try, so that is no more a problem on stripping, such false fails do not cause a real fail, only an extra delay for the re-try. That kind of falsr-fails where the main reason to 'hate' stripping on the past, nowadays it is no more a problem.

    SSD striping actoss multiply SSD makes them to work longer without failing, because two main reasons: you divide the data written by the number of SSD you use and they are written during less time (unless you use an application that extress them)... the reasons SSD got damaged are two, heat and erases (that are needed only when written to a block that has been used and not previously erased), if you let time between writes you reduce heat al lot, stripping is a good way to increase time between writes. If you can put N SSD so the total speed is higher than maximun of the BUS, the bottleneck will be the BUS so the SSD will have to wait bettwen writes, that allows it to not heat; the bad part is the extra cost.

    For example, if max bus speed is 1GiB/s and each SSD is able of 550MiB/s it is enough with only 2 SSD, but if SSD only writes at 500MiB it is better to use three.

    The SSD speed for calculating is not the sequiential one, is the speed it gives on your normal day operations.

    Resuming:
    Use a small SWAP partition, but less than 1/2 of total RAM.
    Have enough RAM to not use more than 60% of it, so SWAP get not used except for APPs that otherwise would fail.
    Stripe over multiple cheaper SSD is better than only one SSD.
    Ensure SSD total speed is more than BUS speed, so they can cool bettwen operations (bottle neck br BUS, not the SSDs)

    If you can use eigth cheap SSD of 32GiB on stripping, it is much better than just one of 256GiB.

    Dividing writes along multiple SSD is faster and if BUS speed is less than SSD total speed it causes a time between writes where SSDs must wait for BUS, that let SSD to lower temperature (main reason SSD get damaged is heat).

  3. azrielle
    February 5, 2017 at 6:47 pm

    You don't have to eliminate a swap file to eliminate its use except near catastrophically, e.g. almost never. Just reduce Linux default "swappiness" from 60 to 6. What that means is that swap will only start being utilized when 40% of RAM has been used, by default, which made sense back in the days of 64MB of RAM, circa 1999, but not now. By reducing it to 6, fully 94% of RAM must be in use before the swap file kicks in. Here is how to do it:

    Here's how you adjust swappiness and activate write behind caching in Linux:
    TO FIND SWAPPINESS:
    cat /proc/sys/vm/swappiness
    TO SET SWAPPINESS (if >= 2 GB RAM):

    sudo leafpad /etc/sysctl.conf

    Add line: vm.swappiness = 6
    TO SET WRITE CACHING:

    Open Disks.
    (Package name: gnome-disk-utility. Command: gnome-disks.)
    (sudo apt-get install gnome-disk-utility)

    Click 'Drive Settings' in menu.

    Set 'Write Cache' to On.

    Restart computer.

  4. David
    July 12, 2014 at 8:43 pm

    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.

    • kashu
      April 27, 2016 at 11:17 pm

      Great! I totally agree with you.

  5. Johnnie
    July 9, 2014 at 7:37 am

    @ 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.

  6. kayla
    July 5, 2014 at 2:17 am

    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.

  7. Eddie G. O'Connor Jr.
    June 29, 2014 at 1:46 am

    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!

  8. Donald Dogshit
    June 28, 2014 at 8:28 am

    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.

    • dragonmouth
      January 16, 2015 at 10:30 pm

      It is very edifying that you have such rich and profligate colleagues. However, not everyone is so blessed. I can get a 1TB HD for around $50. A similar sized SSD runs between $350-$400. I am sure there are a lot of people out there that do not want to be regularly replacing SSDs at those prices.

  9. Michael Jones
    June 27, 2014 at 6:05 pm

    noop

  10. Donald Dogshit
    June 27, 2014 at 2:27 pm

    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
      June 27, 2014 at 11:34 pm

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

  11. Will
    June 27, 2014 at 2:10 pm

    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.

  12. Ant
    June 27, 2014 at 2:06 am

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

  13. Kriston
    June 26, 2014 at 4:23 pm

    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
      June 27, 2014 at 3:31 am

      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.

  14. John
    June 26, 2014 at 2:48 pm

    > 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.

    • dragonmouth
      December 16, 2014 at 3:23 pm

      "Kidding, but I would leave these files on the SSD, because I can write/read faster on my SSD than on my non-SSD."
      Ha, ha, ha. If that is what you believe then you should put /swap on your SSD also.

      Do you think you can differentiate between a write time of a nanosecond and that of a millisecond? The idea is to reduce the number of writes to the SSD, not the write time, the duration of which a human being cannot readily ascertain.

  15. Anders Jackson
    June 24, 2014 at 11:57 pm

    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?

  16. dragonmouth
    June 24, 2014 at 7:23 pm

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

    • dirk dierickx
      June 25, 2014 at 6:50 am

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

  17. Ed
    June 24, 2014 at 3:30 pm

    "... 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.