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.
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.)
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 withTotal_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 thetune2fs -l
Lifetime writes output.) So multiple that number with 512 and you get the writes in byte, or for short: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.
All of this talk about wearing out SSDs is "guesswork". I had the same feelings, but started using them commercially. I have one of the fastest oracle clusters on the East Coast. 3 years ago, we instituted SSDs for our entire storage AND temporary file systems. We do billions of write operations/day to the SSDs. After 3 years, we still have not come anywhere near 10% burnout. If I can do that commercially, they will NEVER wear out in a residential situation. So, I implemented an SSD solution specifically for swap space on my Linux workstation and BAM!
So, your mileage my vary, but SSD is the way to go in every way.
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:
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
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.
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
Changing swappiness may not actually have an impact. We have played with it a lot in systems that are short on RAM and we are wanting to push as much as possible to the SSD and it has actually made little impact, the items remaining in memory (which means they are needed). This may be a moot point.
I liked the idea of checking the
smartctl
output, however, my code is a bit more compact. I have never understood why people just do not know thatawk
has thegrep
capability built into it.Though this is the code I use: