Optimize SSD's for Longer Lifespan

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
dark

Optimize SSD's for Longer Lifespan

Post by dark »

Step 0:
sudo apt install util-linux
Most distros has this package installed OOTB so you can skip this step.

Step 1:
sudo systemctl enable fstrim.timer
sudo systemctl start fstrim.timer
Configured OOTB in Linux Mint so you can skip this step.

Step 2:
xed admin:///etc/fstab
Add noatime mount option.
Noatime mount option fully disables writing file access times to SSD every time you read a file, this reduces the writes to SSD therefore greatly increasing lifespan of SSD’s.
Add noatime mount option to all partitions except swap partition.
Image

Step 3:
xed admin:///etc/sysctl.conf
Add vm.swappiness=10
So writing to swapfile/swap partition only occurs after RAM is filled 90% instead of default 60%. Good if you do lot of web browsing, video editing and gaming and do not want contents of RAM frequently written to swapfile/swap partition on SSD after RAM is filled only 60%.
Image

Step 4:
Enable write cache from Gnome Disks.
Image
User avatar
xenopeek
Level 25
Level 25
Posts: 29586
Joined: Wed Jul 06, 2011 3:58 am

Re: Optimize SSD's for Longer Lifespan

Post by xenopeek »

dark wrote: Thu Nov 08, 2018 7:21 am Step 2:
sudo xed /etc/fstab
Add noatime mount option.
Noatime mount option fully disables writing file access times to SSD every time you read a file, this reduces the writes to SSD therefore greatly increasing lifespan of SSD’s.
Add noatime mount option to all partitions except swap partition.
That's a great exaggeration. Linux Mint by default uses relatime, which only updates access time if the file is being modified (and thus the file information block would be rewritten anyway) or the previous access time is older than 1 day.

Adding noatime leads to an insignificant difference in lifespan.
Image
dark

Re: Optimize SSD's for Longer Lifespan

Post by dark »

I didn't know about Linux Mint using relatime by default.
User avatar
Pjotr
Level 24
Level 24
Posts: 20048
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Optimize SSD's for Longer Lifespan

Post by Pjotr »

Don't use sudo xed, but xed admin:// instead.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
xenopeek
Level 25
Level 25
Posts: 29586
Joined: Wed Jul 06, 2011 3:58 am

Re: Optimize SSD's for Longer Lifespan

Post by xenopeek »

Good catch. I've updated it in OP's post.
Image
gm10

Re: Optimize SSD's for Longer Lifespan

Post by gm10 »

dark wrote: Thu Nov 08, 2018 7:21 am Add vm.swappiness=10
So writing to swapfile/swap partition only occurs after RAM is filled 90% instead of default 60%. Good if you do lot of web browsing, video editing and gaming and do not want contents of RAM frequently written to swapfile/swap partition on SSD after RAM is filled only 60%.
That parameter does not define a free RAM percentage (check the kernel sources, that parameter is used as part of a number of formulas, but none of them are about what you claim). If you decrease this value you'll probably see less caching and thus have a good chance of more disk activity, both depending on your use case.
dark wrote: Thu Nov 08, 2018 7:21 am Enable write cache from Gnome Disks.
Write caching is enabled by default.
User avatar
Pjotr
Level 24
Level 24
Posts: 20048
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Optimize SSD's for Longer Lifespan

Post by Pjotr »

gm10 wrote: Thu Nov 08, 2018 11:27 am That parameter does not define a free RAM percentage (check the kernel sources, that parameter is used as part of a number of formulas, but none of them are about what you claim). If you decrease this value you'll probably see less caching and thus have a good chance of more disk activity, both depending on your use case.
This is a good article in the wiki of Arch Linux (which is almost always a great resource), about the effects of swappiness reduction:
https://wiki.archlinux.org/index.php/Swap#Swappiness

The article it refers to is worth reading as well:
http://rudd-o.com/en/linux-and-free-sof ... o-fix-that
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
gm10

Re: Optimize SSD's for Longer Lifespan

Post by gm10 »

Pjotr wrote: Thu Nov 08, 2018 1:05 pm The article it refers to is worth reading as well:
http://rudd-o.com/en/linux-and-free-sof ... o-fix-that
He wrote 11 years ago, when the kernel's paging strategy was different:
On a desktop computer, you want swappiness to be as close to zero as possible. The reason you want to do this (even though it might hurt actual performance) is because this will immunize your computer to memory shortages caused by temporary big file manipulations (think copying a big video file to another disk).
Do try this with a present day kernel. He even provides a test script. I think you'll find it doesn't behave the way he experienced it back then, I know it doesn't on my laptop at least. That aside very nice article.
Last edited by gm10 on Thu Nov 08, 2018 3:02 pm, edited 2 times in total.
User avatar
Pjotr
Level 24
Level 24
Posts: 20048
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Optimize SSD's for Longer Lifespan

Post by Pjotr »

gm10 wrote: Thu Nov 08, 2018 2:13 pm
Pjotr wrote: Thu Nov 08, 2018 1:05 pm The article it refers to is worth reading as well:
http://rudd-o.com/en/linux-and-free-sof ... o-fix-that
He wrote 11 years ago
Last modified five years ago, so that makes it less ancient....
gm10 wrote: Thu Nov 08, 2018 2:13 pm, when the kernel's paging strategy was different:

Code: Select all

On a desktop computer, you want swappiness to be as close to zero as possible. The reason you want to do this (even though it might hurt actual performance) is because this will immunize your computer to memory shortages caused by temporary big file manipulations (think copying a big video file to another disk). 
To try this with a present day kernel. He even provides a test script. I think you'll find it doesn't behave the way he experienced it back then, I know it doesn't on my laptop at least. That aside very nice article.
Can you perhaps give some links that elaborate on this change of the kernel's paging strategy?
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: Optimize SSD's for Longer Lifespan

Post by thx-1138 »

...at least on my own laptop, i do find that the default value of 60 makes it crawl from time to time (also, article is last modified June 2013).

My question though would be different:
exactly what do people do in their 'desktop' to somehow need to achieve a longer SSD lifespan?
Pretty much every 'scientific' & reliable article i've read about SSDs refers to...numerous decades of lifespan -
unless of course it borks out of the blue one morning, which can happen with any digital device.

I can understand concerns for such if someone runs a database with thousands of writes per hour,
or maybe if someone has turned his/her machine to a dedicated 24/7 torrents' seedbox with tons of HD rips... :)
But for common installations?...
gm10

Re: Optimize SSD's for Longer Lifespan

Post by gm10 »

Pjotr wrote: Thu Nov 08, 2018 2:21 pm Can you perhaps give some links that elaborate on this change of the kernel's paging strategy?
I tried to google something but it's surprisingly hard to find something on the evolution of this. Here's 2 write-ups about changes done back in the 2.6 series:
https://www.kernel.org/doc/gorman/html/ ... html#toc27
https://linux-mm.org/PageReplacementDesign
Also ancient but still more recent than 11 years ago.
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: Optimize SSD's for Longer Lifespan

Post by thx-1138 »

...the swappiness value has been debated way too frequently in those forums here -
which is also something i don't really understand as to why it should somehow be controversial, especially since...

Edit: also from Red Hat...a simplified explanation of how swappiness gets calculated...

...all in all, i believe that SSDs are configured pretty reasonably out-of-the-box for 'desktops',
and as for swappiness, it you experience slow-downs with 60, just set it to something lower, yet without overdoing such...
User avatar
Pjotr
Level 24
Level 24
Posts: 20048
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Optimize SSD's for Longer Lifespan

Post by Pjotr »

thx-1138 wrote: Thu Nov 08, 2018 2:56 pm ...the swappiness value has been debated way too frequently in those forums here -
which is also something i don't really understand as to why it should somehow be controversial, especially since...

Edit: also from Red Hat...a simplified explanation of how swappiness gets calculated...
Excellent information! Thanks.

More elaborate than the Arch wiki, yet simplified enough to be understandable for me. :mrgreen:

On my machines, I keep track of swap use by means of Conky:
https://sites.google.com/site/easylinux ... forxubuntu

I usually apply a swappiness of 10 for HDD's and 1 for SSD's. On one machine with an SSD and little RAM (2 GB) I even had to set swappiness to 0, in order to prevent frequent use of the swap....
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
scjet45
Level 4
Level 4
Posts: 334
Joined: Sat May 07, 2016 12:50 am
Location: Canada

Re: Optimize SSD's for Longer Lifespan

Post by scjet45 »

Pjotr wrote: Fri Nov 09, 2018 5:22 am
thx-1138 wrote: Thu Nov 08, 2018 2:56 pm ...the swappiness value has been debated way too frequently in those forums here -
which is also something i don't really understand as to why it should somehow be controversial, especially since...

Edit: also from Red Hat...a simplified explanation of how swappiness gets calculated...
Excellent information! Thanks.

More elaborate than the Arch wiki, yet simplified enough to be understandable for me. :mrgreen:

On my machines, I keep track of swap use by means of Conky:
https://sites.google.com/site/easylinux ... forxubuntu

I usually apply a swappiness of 10 for HDD's and 1 for SSD's. On one machine with an SSD and little RAM (2 GB) I even had to set swappiness to 0, in order to prevent frequent use of the swap....
hey Hi @Pjotr.
I noticed that on your older https://sites.google.com/site/easylinux ... forxubuntu I'm getting a 404 error nowadays. ?
Is this: https://easylinuxtipsproject.blogspot.com/p/1.html your new tutroial tipsntricks for LinuxMint?
Anyway, your older tips for LinuxMint on sites.google.com was a very handy site for me.
Just wanna say a big thanks for all that too, meaning, I hope you keep it up.
:)
MATE 21.3 | Lenovo Legion 5 17ACH6
User avatar
Pjotr
Level 24
Level 24
Posts: 20048
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Optimize SSD's for Longer Lifespan

Post by Pjotr »

scjet45 wrote: Mon Mar 11, 2019 4:31 pm hey Hi @Pjotr.
I noticed that on your older https://sites.google.com/site/easylinux ... forxubuntu I'm getting a 404 error nowadays. ?
Is this: https://easylinuxtipsproject.blogspot.com your new tutorial tipsntricks for LinuxMint?
Yes. :)

Everything has been moved to my new site, so no information has been lost.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
Pjotr
Level 24
Level 24
Posts: 20048
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Optimize SSD's for Longer Lifespan

Post by Pjotr »

Volvic wrote: Thu Mar 14, 2019 11:51 am Step 2 and Stuck
any help please
In your case, only add noatime to the root partition:

Code: Select all

/dev/mapper/mint--vg-root /               ext4    noatime,errors=remount-ro 0       1
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
hcentaur13

Re: Optimize SSD's for Longer Lifespan

Post by hcentaur13 »

Increase your RAM size to 8 or 16 GB and you'll need swap only as cheap extend of real RAM for the rare case that existent RAM needs to be extend a bit.

Current SSDs have in default less live time than the best existent server drives. They run with guarantee more than 5 years 24h 7d/week. Ony 3 or more years old SSD may have noteable livetime when they get constantly switching power on/off. Never by writing to it.
LanceM

Re: Optimize SSD's for Longer Lifespan

Post by LanceM »

The net result on Mint 19.1 with Ext4 with the 2 operations below, have resulted in ~70% reduction in browser writes to my SSD. From about 4.3GB/day to 1GB/day
Profile-sync-daemon and cache to RAM are the 2 simple changes.
The outline I've created here is a guide for people with some skills and not perfect notes.
http://manpages.ubuntu.com/manpages/cos ... psd.1.html
install profile-sync-daemon using software manager
In terminal without root privileges:
systemctl --user start psd.service
systemctl --user enable psd.service
This creates your ~/.config/psd/psd.conf and then edit it by showing hidden files and navigating to /home/username/.config/psd.conf
only edits needed for 70% reduction (my recommendation but options are available on the psd manpages):
change #BROWSERS="" to
BROWSERS="google-chrome" note: (default enables all browsers, i use chrome)
Restart computer and in terminal:
to check: psd p (it should say active except OVERLAYFS
for help psd help
to uninstall:
systemctl --user disable psd.service
restart computer
uninstall psd using software manager
restart computer and check psd p it should be gone
The creator of psd states sometimes changes due to updates cause changes to the default config file at /usr/share/psd/psd.conf
and would need to be diffed against the
($XDG_CONFIG_HOME/psd/psd.conf) available by navigating there via /home/username/.config/psd.conf
--------
some browsers use separate cache, like chromium and chrome. To save more writes to SSD, do the following:
all cache to ram
edit the /etc/fstab file and at the end put:
tmpfs /home/lance/.cache tmpfs noatime,nodev,nosuid,size=400M 0 0 note: (lance is my username and would need changed of course)
to uninstall, just remove the edit above and restart computer.
can be checked by sudo df -Th to see % usage of the 400Mb
Post Reply

Return to “Tutorials”