Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I encountered this article which includes the following suggestion:

Swap and swappiness

I kept my swap partition on the old HDD. Swap on the SSD would be faster, but would also shorten the SSD’s life.

My system has plenty of memory, so I also reduced the swappiness value to 0 to tell Ubuntu to only swap when absolutely necessary. I did this by adding the line vm.swappiness=0 to /etc/sysctl.conf.

Is it true that setting swappiness to zero will increase the life of my SSD? I can't find references to this elsewhere.

share|improve this question

4 Answers 4

Reducing the swappiness to 0 means that the OS will only start using the SSD for swap when there is no more available free RAM.

Theoretically this can increase the SSD's lifetime because the SSD will suffer less writes. It depends whether it is practically increases the SSD's lifetime:

  • Linux rarely use the swap (especially compared to windows) even with higher swappiness values too, so this setting likely won't change the swapping behaviour on systems with plenty of RAM compared to RAM usage. If you are short on RAM then swapping can happen quite frequently with the default value of 60, in this case decreasing swappiness will likely have a significant impact on the SSD's write cycle limit.

  • The SSD's write endurance is still pretty high for a simple consumer usage, at least for MLC based SSDs. They say that the current MLC based SSD's can tolerate ca. 3000-5000 write cycles before they wore out. Calculating with the 3000 limit that means that a 128 GB SSD with a daily 10 GB writes will work happily for ca. 38000 days, that means ca. 100 years. If you have a bigger SSD of course that will wore out much later. So it is very unlikely that your SSD will die because of the cells wearing out. (Of course if you use your SSD in a corporate/server environment then the daily writes are much higher, but in corporate environments usually SLC based SSD's are used.)

  • This write cycle limit is so high that the SSD manufacturers (at first SAMSUNG) started to manufacture TLC based SSD's for consumers, which can only tolerate ca. 1000 write cycles, but are cheaper. These companies say that even these SSD's write cycle limit will last longer than the time the product is expected to be used. (It is unlikely that in 2024 we will be still using our 128 GB SSD's) Although if you have a TLC based SSD and you write quite frequently to that drive, e.g 50GB/day, than decreasing the swappiness value will likely have a significant effect on your SSD's life length.
  • Here is a giant thread where enthusiasts tested the SSD's endurance by constantly writing to them. Although their test method is probably not totally correct, their results are quite impressive and soothing.

So to sum up: In theory yes, decreasing the swappiness will result in longer SSD lifespan, in practice it will likely not. But if you have a TLC based SSD and you are short on RAM and you generally write frequently to the SSD then it can have a practical effect too.

I have an MLC based, 128 GB SSD and I mostly use my system for office/browsing and I have plenty of RAM compared to my RAM usage so my SSD is not under heavy write load (although my machine is on 24/7). But because I don't need swapping at all and it is so easy to lower the swappiness I did for myself set swappiness to 0 when I installed my SSDs, because why not do it? (Actually I set swappiness to 0 on all of my machines, even on machines which only have HDDs.)

You can check how much write has your SSD suffered during it's life with smartctl, look for the line with Total_LBAs_Written, this will show you how much 512b sectors have been written to the SSD. (Yes I know that the SSDs have physically 4K blocks, not 512b, but SMART still says: Sector Size: 512 bytes logical/physical and with 512 blocks I get results which are comparable to the tune2fs -l Lifetime writes output.) So multiple that number with 512 and you get the writes in byte, or for short:

sudo smartctl -a /dev/sda | grep Total_LBAs_Written | awk '{print $10*512/1024/1024/1024 " GiB"}'

will print out in GiBs for /dev/sda. (Just change the device name to your SSD's name.) My 128 GB SSD has suffered ca. 800 GB writes in a little more than one year, that means only 7 write cycles used from the 3000.

share|improve this answer

Yes. You do need to change swappiness to increase SSD life.

Swappiness lets you control how much swap file is being used. Swappiness values can be changed from 0 to 100. The higher swappiness values the more the kernel will try to use swap space, the lower swappiness values means the kernel will use less or no swap space depending on our setting.

The default swappiness value from is 60, if you have plenty have RAM, you should avoid using swap space which writes and reads to your SSD, but to an HDD. For system with 4 GB or more RAM, try to reduce the usage of swap by changing swappiness settings to between 10 even 0, with the swap file being on an HDD.

Running a swap space is very disk I/O intensive, and that’s actually bad for an SSD. An SSD can only handle so many writes before it goes bad and you’re forced to buy another drive. So, if at all possible, move your swap space to a secondary, spinning drive…away from the SSD.

A Solid State Drive is worn down relatively quickly by write actions. Especially the oldest generations of SSD's were vulnerable in that aspect, but to a lesser degree that's still the case for the newer generations.

You can either make a new partition on a new disk, or just make a swap file instead; making a new partition will almost always result in much better performance.

If you don’t have an alternate drive to move to, you can alter a setting that will only enable swap when your physical RAM is 100% full, which will decrease the load on your swapfile, and help your SSD. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

echo 0 > /proc/sys/vm/swappiness

SSD wear and tear has to do with write cycles

A Solid State Drive is worn down relatively quickly by write actions. Especially the oldest generations of SSD's were vulnerable in that aspect, but to a lesser degree that's still the case for the newer generations.

Use Trim

TRIM is an advantage that you use with SSDs. It runs in software and communicates with the SSD controller, telling it which ‘blocks’ are no longer needed by the filesystem and can be safely cleaned and overwritten. This won’t really result in an improvement of performance, but will rather lengthen the life of your SSD.

Sources:Linux SSD Tweaks & How-to for optimizing your SSD

share|improve this answer
    
I would like to know what is wrong? The OP asked if he needs to change his swappiness to increase SSD life, and the answer is yes he does need to change swappiness. –  Mitch Jan 12 at 17:46
    
I understand that the latest versions of Ubuntu automatically use TRIM for SSDs. –  Paddy Landau Jan 14 at 19:06

Is it true that setting swappiness to zero will increase the life of my SSD?

It would cause that Linux move memory blocks less frequently to the swap partition. Writing to the swap normally uses write cycles if your swap is in the SSD. Remember that the swap is only used when needed and if you have enough RAM you may be better without it (unless you want hibernation, but that's another issue).

The effects of this actions may vary, but doing it just to save some write cycles in the SSD is doing it wrong. Modern SSD's (about from 2012 onwards) have tons of write cycles, and the performance might be reduced for your applications when you are almost using up all your RAM. You use more write cycles during installation of programs than due swap. Remember, again, that swap is only used when is needed by default.

If you are worried about your SSD write cycles used for swap you may remove/deactivate the swap altogether if you have enough RAM and only activate a temporary swap in a HDD instead of messing with the swapiness. That would be the best route.

share|improve this answer

I would high recommend you to change swappiness setting to lower value, the best is "0" if you have enough memory/ram for your system 4 GB of ram or more. Even though swappiness at 10 with high ram system, i barely see ubuntu put anything on swap partition since mostly everything are on ram already.

I did a little bit google search and i found this page http://namhuy.net/1563/how-to-tweak-and-optimize-ssd-for-ubuntu-linux-mint.html

might help you to tweak and optimize SSD for your Ubuntu system run more efficiently and keep your ssd live longer

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.