Saturday, October 24, 2015

Preserving the life of your SSD (Linux)

Your new SSD drive has a limited number of write cycles that it will take before it fails.  This number is pretty high and it should last a long time but why waste these writes if you don't have too? The biggest thing you can do to limit the wear and tear on your SSD drive is changing how often Ubuntu writes to the SWAP PARTITION.  This is achieved by editing a single file, sysctl.conf.  The other thing you can do to help keep your SSD's performance up is occasionally running the FSTRIM command.  Here's how to do these two things.

(Note; SWAP is an important function of Ubuntu and if you have a small amount of memory (RAM) in your system you may want a larger SWAPPINESS number than I used.  I have 16gb of ram in my system.)


Limit SWAP PARTITION use (SWAPPINESS).

You will need to limit the use of the swap partition if it's located on your SSD (It was put there by default in Ubuntu). Don't disable it entirely, Ubuntu does need to be able to "swap".

Ubuntu uses a number between 0 and 100 to determine how often to "swap".  The default is 60.  The lower the number the less Ubuntu SWAPS. 60 is too high for an SSD, let's change it.

Open a Terminal Window and type the following pressing enter afterwards;

    cat /proc/sys/vm/swappiness

This will tell you your current SWAPPINESS setting (default is 60). We want to change it to 1.

So type the following into the Terminal Window and press enter.

     sudo gedit /etc/sysctl.conf

This will launch GEDIT with the sysctl.conf file open for editing.

Add the following line at the end of the sysctl.conf file;

    vm.swappiness=1

Save the file and close it.

That's it!  Ubuntu will now SWAP (write to your SSD SWAP Partition) much less now.  If you notice that your system's performance dropped noticeably after making this change just try a number a little higher or just put it back to 60.



How to execute FSTRIM manually.

The second thing we can do to help our SSD Drive out is manually running the FSTRIM command.  This lets your SSD Drive get rid of clutter and lets it keep it's fast speed.  You should run this command a couple of times a month or maybe once a week.

Open a Terminal Window and type;

     sudo fstrim -v /

Press Enter Key.
Type your password when prompted and Press Enter Key again.

This command take a few minutes to complete and it will look like the terminal froze up. It didn't, just wait it out.  When it's done it will tell you the amount of space it Trimmed.


MORE

Here is a link to more information and other people's thoughts on preserving the life and speed of your SSD.