To swappiness or not to swappiness, that is the question...

Chat about Linux in general
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 6 months after creation.
User avatar
trytip
Level 14
Level 14
Posts: 5366
Joined: Tue Jul 05, 2016 1:20 pm

To swappiness or not to swappiness, that is the question...

Post by trytip »

[ off-topic discussion split from support request viewtopic.php?f=46&t=330146 and moved here ]
dave8671 wrote: Sun Sep 13, 2020 11:58 am Gotta fixing now I hope, do I need to update grub after the fstab fix?
i just find out swapiness for SSD is better set to 1 instead of 5 or 10
https://sites.google.com/site/guidetoop ... ring-a-ssd
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Image
pbear
Level 16
Level 16
Posts: 6569
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: Configing the SSD

Post by pbear »

trytip wrote: Sun Sep 13, 2020 12:04 pm
dave8671 wrote: Sun Sep 13, 2020 11:58 am Gotta fixing now I hope, do I need to update grub after the fstab fix?
i just find out swapiness for SSD is better set to 1 instead of 5 or 10
https://sites.google.com/site/guidetoop ... ring-a-ssd
That's nonsense. SSDs don't need to be coddled. They're now more durable than spinning drives.
All choking swappiness to the bare minimum does is hamstring the system if it needs to use swap.

For more on swappiness, see gm10's general discussion of the issue.
Last edited by pbear on Sun Sep 13, 2020 12:12 pm, edited 2 times in total.
User avatar
Pjotr
Level 24
Level 24
Posts: 20092
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Configing the SSD

Post by Pjotr »

pbear wrote: Sun Sep 13, 2020 12:07 pm
trytip wrote: Sun Sep 13, 2020 12:04 pm i just find out swapiness for SSD is better set to 1 instead of 5 or 10
https://sites.google.com/site/guidetoop ... ring-a-ssd
That's nonsense. SSDs don't need to be coddled. They're now more durable than spinning drives.
All choking swappiness to the bare minimum does is hamstring the system if it needs to use swap.

For more on swappiness, see gm10's general discussion of the issue.
As you can see in gm10's contribution on this issue, to which you refer, you see that his viewpoint on decreasing swappiness is ultimately this:
for the average user, I won't make any statements as to what is best for I honestly do not know what the average Linux user does on their computer.
(.....) Either way, the best advice to give is to simply add enough RAM to your device and thus avoid the question from even posing itself.
viewtopic.php?p=1699701#p1699701

In my personal experience, decreasing swappiness noticeably increases responsiveness. More or less as promised by the author of this article:
https://rudd-o.com/linux-and-free-softw ... o-fix-that

Now, what's wrong with taking some of the wear load off an SSD, whilst at the same time increasing overall system responsiveness? A win-win situation if there ever was one, if you ask me.
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.
LanceM

Re: Configing the SSD

Post by LanceM »

Now, what's wrong with taking some of the wear load off an SSD, whilst at the same time increasing overall system responsiveness? A win-win situation if there ever was one, if you ask me.
With all due respect, I ran several extended write tests to SSDs with swappiness set at default, 10, 5, and 1 for a week each with full use on SSD and monitored writes using Micron Storage Executive for Total Writes. There was no statistical difference in any setting. I'm just not convinced that swappiness or noatime make any real difference.
User avatar
Pjotr
Level 24
Level 24
Posts: 20092
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Configing the SSD

Post by Pjotr »

LanceM wrote: Sun Sep 13, 2020 2:37 pm
Now, what's wrong with taking some of the wear load off an SSD, whilst at the same time increasing overall system responsiveness? A win-win situation if there ever was one, if you ask me.
With all due respect, I ran several extended write tests to SSDs with swappiness set at default, 10, 5, and 1 for a week each with full use on SSD and monitored writes using Micron Storage Executive for Total Writes. There was no statistical difference in any setting. I'm just not convinced that swappiness or noatime make any real difference.
Yes, well, my statement should have been more qualified.... I meant to say that I've noticed increased system responsiveness because of reduced swappiness, on computers with relatively little RAM.
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.
LanceM

Re: Configing the SSD

Post by LanceM »

Yes, well, my statement should have been more qualified.... I meant to say that I've noticed increased system responsiveness because of reduced swappiness, on computers with relatively little RAM.
I should of added, that I purposely used a RAM starved system with just 2GB. As soon a swap started being used the systems slowed way down.. Even the mouse quit responding. Swappiness settings seemed to make no difference to that. This test was done on Cinnamon 19.3. With the newer kernels, in 20 there have been improvements in swap use. It doesn't engage nearly as soon, nor does it impact the system as much. Certainly one system and a few tests doesn't invalidate the entire swappiness setting, but makes me skeptical of it. One could try it and see. To just blindly change swappiness, irregardless of how much RAM is in the PC and not first monitor if swap is even being used, seems foolish to me. Enough RAM positively, eliminates the issue. 8GB for most users is adequate to have swap never kick in. It can be there for emergency overload if the need arises. If it does, I think default may well be the best setting.
User avatar
Pjotr
Level 24
Level 24
Posts: 20092
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Configing the SSD

Post by Pjotr »

LanceM wrote: Sun Sep 13, 2020 3:19 pm
Yes, well, my statement should have been more qualified.... I meant to say that I've noticed increased system responsiveness because of reduced swappiness, on computers with relatively little RAM.
I should of added, that I purposely used a RAM starved system with just 2GB. As soon a swap started being used the systems slowed way down.. Even the mouse quit responding. Swappiness settings seemed to make no difference to that.
That's peculiar, because a decreased swappiness should reduce the number of times that the swap kicks in, thus keeping your RAM starved system generally more responsive...
LanceM wrote: Sun Sep 13, 2020 3:19 pm This test was done on Cinnamon 19.3. With the newer kernels, in 20 there have been improvements in swap use. It doesn't engage nearly as soon, nor does it impact the system as much. Certainly one system and a few tests doesn't invalidate the entire swappiness setting, but makes me skeptical of it. One could try it and see. To just blindly change swappiness, irregardless of how much RAM is in the PC and not first monitor if swap is even being used, seems foolish to me. Enough RAM positively, eliminates the issue. 8GB for most users is adequate to have swap never kick in. It can be there for emergency overload if the need arises. If it does, I think default may well be the best setting.
Well, I do it on all of my computers as a matter of course. Been doing it for years: if I remember correctly, since 2009/2010 or something, around the time that I bought my first SSD. Regardless of RAM amount. Fire and forget. Never seen any negative effects because of it, in over a decade. :mrgreen:
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
Portreve
Level 13
Level 13
Posts: 4870
Joined: Mon Apr 18, 2011 12:03 am
Location: Within 20,004 km of YOU!
Contact:

Re: To swappiness or not to swappiness, that is the question...

Post by Portreve »

Book of Pjotr, Chapter 2, v. 5-7:
Now shalt thou set thy swappiness to 5, lest thy SSD be o'er-wrought with wear. Typeth thee xed admin:///etc/sysctl.conf in thy terminal and presseth [ENTER]. Then mayest thou scroll to the end of thine sysctl.conf file and add the following thereunto:
# Sharply reduce the inclination to swap
vm.swappiness=5
This is what I follow religiously in setting up fresh installs of LM.
Flying this flag in support of freedom 🇺🇦

Recommended keyboard layout: English (intl., with AltGR dead keys)

Podcasts: Linux Unplugged, Destination Linux

Also check out Thor Hartmannsson's Linux Tips YouTube Channel
User avatar
absque fenestris
Level 12
Level 12
Posts: 4110
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: To swappiness or not to swappiness, that is the question...

Post by absque fenestris »

Well, Portreve has just emphatically reminded me of the Book of Pjotr.

My goodness - I installed a new system without consulting the book ... :oops:
LanceM

Re: To swappiness or not to swappiness, that is the question...

Post by LanceM »

A reference, albeit not from Mt Sinai https://linuxhint.com/understanding_vm_swappiness/
LanceM

Re: To swappiness or not to swappiness, that is the question...

Post by LanceM »

Anyone seriously wanting to reduce writes to their SSDs should install profile-sync daemon. For browser writes it will reduce the writes to about half. It's easy to configure. With it, the option to use overlayfs is available and greatly enhances performance. It's in the Software Manager. Documentation:https://wiki.archlinux.org/index.php/pr ... ync-daemon

Code: Select all

lance@LM:~$ psd p
Profile-sync-daemon v6.34 on Linux Mint 20

 Systemd service is currently active.
 Systemd resync-timer is currently active.
 Overlayfs v23 is currently active.

Psd will manage the following per /home/lance/.config/psd/.psd.conf:

 browser/psname:  google-chrome/chrome
 owner/group id:  lance/1000
 sync target:     /home/lance/.config/google-chrome
 tmpfs dir:       /run/user/1000/lance-google-chrome
 profile size:    198M
 overlayfs size:  34M
 recovery dirs:   1 <- delete with the c option
pbear
Level 16
Level 16
Posts: 6569
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: To swappiness or not to swappiness, that is the question...

Post by pbear »

Notice the recommendation to minimize swappiness is based on a single article, which has no cites and gives no credentials for the author (identified only by nom de plume). Meanwhile, my research turned up plenty of users with as much apparent expertise arguing the other way. See, e.g., askubuntu, Linux & Unix, and Linux.com. The last quotes a kernel developer (Andrew Morton) who argues for using more swap, not less.

In any event, there's no reason to reduce swappiness even further to coddle SSDs.
User avatar
AZgl1800
Level 20
Level 20
Posts: 11173
Joined: Thu Dec 31, 2015 3:20 am
Location: Oklahoma where the wind comes Sweeping down the Plains
Contact:

Re: To swappiness or not to swappiness, that is the question...

Post by AZgl1800 »

a couple of years ago, I had to deal with Swapiness....

I solved the problem by tripling the amount of RAM in the 1st laptop, and when I ordered this current laptop, it came with 16gB RAM.

I have never felt it slow down unless the Internet got in the way.

In fact, when I installed 19.3 Cinnamon with the Defaults, it did not create a Swap partition at all.
LM21.3 Cinnamon ASUS FX705GM | Donate to Mint https://www.patreon.com/linux_mint
Image
LanceM

Re: To swappiness or not to swappiness, that is the question...

Post by LanceM »

Swappiness and noatime are two things that are hard to get out of people's heads. It's become ingrained and propagates like medusa. Reminds me of advising to cut snake bites with a razor. That myth has largely dissipated but those old kits are still available online. So I say put mindlessly tweaking swappines and adding noatime to the sword. Do our part in killing the myth. Maybe MythBusters should....
LanceM

Re: To swappiness or not to swappiness, that is the question...

Post by LanceM »

AZgl1500 wrote: Sun Sep 13, 2020 9:22 pm a couple of years ago, I had to deal with Swapiness....

I solved the problem by tripling the amount of RAM in the 1st laptop, and when I ordered this current laptop, it came with 16gB RAM.

I have never felt it slow down unless the Internet got in the way.

In fact, when I installed 19.3 Cinnamon with the Defaults, it did not create a Swap partition at all.
I'll bet it installed a swapfile. That's what does now instead of a partition.
User avatar
AZgl1800
Level 20
Level 20
Posts: 11173
Joined: Thu Dec 31, 2015 3:20 am
Location: Oklahoma where the wind comes Sweeping down the Plains
Contact:

Re: To swappiness or not to swappiness, that is the question...

Post by AZgl1800 »

LanceM wrote: Sun Sep 13, 2020 9:33 pm
AZgl1500 wrote: Sun Sep 13, 2020 9:22 pm a couple of years ago, I had to deal with Swapiness....

I solved the problem by tripling the amount of RAM in the 1st laptop, and when I ordered this current laptop, it came with 16gB RAM.

I have never felt it slow down unless the Internet got in the way.

In fact, when I installed 19.3 Cinnamon with the Defaults, it did not create a Swap partition at all.
I'll bet it installed a swapfile. That's what does now instead of a partition.
yup, it did

swapfile.png
LM21.3 Cinnamon ASUS FX705GM | Donate to Mint https://www.patreon.com/linux_mint
Image
User avatar
antikythera
Level 15
Level 15
Posts: 5721
Joined: Thu Jul 02, 2020 12:52 pm
Location: Cymru

Re: To swappiness or not to swappiness, that is the question...

Post by antikythera »

I still set swappiness and vfs_cache_pressure, it's a habit I have fallen into and it's not hobbling my systems. My systems are only hobbled by the idiot behind the keyboard deliberately loading too much stuff at times. The CPU bottlenecks a long time before the RAM because they are fairly low end. One is an Athlon 5350 4C 4T with single channel RAM controller and hardly any L2 cache, the other a Core i3-3110M 2C 4T mobile CPU with dual channel RAM (faster than the Athlon 5350). If I apply common sense, I never struggle during normal usage of either system for speed or resources.

swap is activated when necessary on them, I have checked by opening a ridiculous amount of chrome tabs, vlc and libreoffice at the same time to overload the RAM. It took a fair while with 16GB but was easier in the system with 8GB admittedly. I am thinking of upgrading the 8GB to 16GB and doing away with swap altogether.
Last edited by antikythera on Mon Sep 14, 2020 5:16 am, edited 1 time in total.
I’ll tell you a DNS joke but be advised, it could take up to 24 hours for everyone to get it.
User avatar
Pjotr
Level 24
Level 24
Posts: 20092
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: To swappiness or not to swappiness, that is the question...

Post by Pjotr »

It's an interesting topic, and well worth discussing it again. One should always be critical towards one's own engrained convictions: time passes and things change. And there is such a thing as progressive insight: what looked right yesterday, may well prove to be wrong today.

That said, let's take a look:
pbear wrote: Sun Sep 13, 2020 9:02 pm Notice the recommendation to minimize swappiness is based on a single article, which has no cites and gives no credentials for the author (identified only by nom de plume). Meanwhile, my research turned up plenty of users with as much apparent expertise arguing the other way. See, e.g., askubuntu,
Now that askubuntu item has this interesting opposing view in its thread:
https://askubuntu.com/a/475465
pbear wrote: Sun Sep 13, 2020 9:02 pm Linux & Unix, and Linux.com. The last quotes a kernel developer (Andrew Morton) who argues for using more swap, not less.
Note that neither of those articles is very conclusive either way.
pbear wrote: Sun Sep 13, 2020 9:02 pm In any event, there's no reason to reduce swappiness even further to coddle SSDs.
Maybe that's so for modern SSD's. But if you're aiming for extreme "mileage" and reliability, it makes sense to reduce wear and tear anyway, just to be on the safe side.

Overall, I'm more interested in "best practice" than in scientific double-blind peer-reviewed experiments. So in view of the differing opinions among the knowledgeable, it might be a good idea to move away a bit from the lower extremes of swappiness. Even though those lower extremes have never caused any problems for me, in over a decade.

Therefore I've decided to change my recommendation for swappiness to 20 in all cases (both for SSD's and for spinners). Not because I fear controversy (quite on the contrary: I love a good fight. :mrgreen: ). But because we're dealing with a technical performance compromise here, and shifting away a bit from the lower extremes might be a better technical compromise.
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
antikythera
Level 15
Level 15
Posts: 5721
Joined: Thu Jul 02, 2020 12:52 pm
Location: Cymru

Re: To swappiness or not to swappiness, that is the question...

Post by antikythera »

That's the issue, there's no right or wrong setting as such because there are many factors at play. Before even considering the CPU and RAM, or storage controller capabilities there's a silly amount of storage types, some examples - SSD (TLC, QLC), eMMC, M.2 (nvme PCI-E gen 3 or 4, or slower SSD style), HDD

Different sources state different recommended values, so I am sticking with what I know works for my systems for the time being. You could indeed soundly argue for not bothering with these settings changes at all with current generation SSD. BUT currently the best advice as far as I'm concerned is to experiment with the values and see what works best for your system. If performance is impacted whatever you put in, revert back to distribution defaults or simply leave it well alone in the first place if you don't know what you are doing.
I’ll tell you a DNS joke but be advised, it could take up to 24 hours for everyone to get it.
LanceM

Re: To swappiness or not to swappiness, that is the question...

Post by LanceM »

Maybe that's so for modern SSD's. But if you're aiming for extreme "mileage" and reliability, it makes sense to reduce wear and tear anyway, just to be on the safe side.
Then I suggest you promote the use of profile-sync daemon
Locked

Return to “Chat about Linux”