Swappiness is set to 10 and the swap usage is still high (imgur.com)
from penquin@lemm.ee to linux@lemmy.ml on 04 Dec 16:58
https://lemm.ee/post/49001043

Not sure why that is, but I have 32 GB of RAM and I would like my system to utilize it as much as possible, but as you can see in the screenshot, the system is only using 5.66 GB of the physical RAM, but swap is still being used in a high number. Is this normal? Should I lower the swappiness to lower than 10? Should I let it be? Thanks
<img alt="Here is the screenshot" src="https://lemmy.ml/api/v3/image_proxy?url=https%3A%2F%2Fimgur.com%2FXyNIQHI">

#linux

threaded - newest

bjoern_tantau@swg-empire.de on 04 Dec 17:05 next collapse

Do you have zram set up?

Telorand@reddthat.com on 04 Dec 19:32 next collapse

Surprised I had to scroll so far to find this comment. I would be concerned about SSD longevity if my swap was doing that, but zram kind of negates that problem.

penquin@lemm.ee on 04 Dec 21:17 collapse

I’ve always thought that zram was a Fedora thing. Lol.
I don’t have it setup, no.

eldavi@lemmy.ml on 04 Dec 17:07 next collapse

swap is usually significantly slower than ram; are you certain that you wan to use that instead?

BearOfaTime@lemm.ee on 04 Dec 17:09 next collapse

I think you misread, OP is saying the system is using to little ram and too much swap.

eldavi@lemmy.ml on 04 Dec 17:34 collapse

that makes much more sense; thanks for the correction.

penquin@lemm.ee on 04 Dec 21:16 collapse

The other way around. I want the system to use all of my RAM. I paid good money for it, might as well use it all. Unused RAM is wasted RAM, right?

eldavi@lemmy.ml on 04 Dec 22:09 next collapse

i see it as more a capability that i don’t always need beyond the minimum; but if you feel about it like this, you can also disable swap all together.

phubarr@lemmy.world on 05 Dec 03:57 collapse

Have you ever tried just not having swap? Maybe don’t have a swap partition and see what results you get. I think there’s even a command that turns your swap completely off, too. Google “swapoff”. Good luck my friend.

catloaf@lemm.ee on 04 Dec 17:20 next collapse

You should set it back to whatever it was. It shows 5.6 GB in active use and 19 GB used for cache. You’re already using all your RAM, just not actively. You don’t sit on 100% of the chairs in your house at once either. 3 GB swap used is very low usage, which is expected when you’re not actively using a lot of memory.

Don’t mess with things you don’t understand, especially when you don’t have an actual problem. You’re going to end up breaking things. (Which, to be fair, is one way to learn, but at the cost of breakage.)

Luci@lemmy.ca on 04 Dec 17:23 next collapse

Don’t mess with things you don’t understand.

Don’t listen to this advice. Messing with things you don’t understand is how you learn your OS. Mess with it, break it, then RTFM and fix it. That’s how ya learn!!

thingsiplay@beehaw.org on 04 Dec 17:30 next collapse

Learning by doing, but make backups.

gi1242@lemmy.world on 04 Dec 17:45 next collapse

you should especially do this on Friday 5:00pm in production, right before going on an international vacation with bad Internet.

Luci@lemmy.ca on 04 Dec 20:22 next collapse

This!

penquin@lemm.ee on 04 Dec 21:12 next collapse

😂 I love this.

TexasDrunk@lemmy.world on 04 Dec 23:31 next collapse

I’ve had to explain to three different people that they’re not getting a production window on Christmas Eve. I’m the only person in the office from the day after Christmas until January 2.

AnUnusualRelic@lemmy.world on 05 Dec 15:08 collapse

Just before a big presentation is also one of the best times. You have a few minutes to waste, why not spend then optimising stuff?

fuckwit_mcbumcrumble@lemmy.dbzer0.com on 04 Dec 17:45 next collapse

That’s great if you treat your computer as a toy. But if you actually need it to do work then that’s terrible advice.

Destroy a virtual machine first, not your actual computer.

penquin@lemm.ee on 04 Dec 21:15 collapse

I have a whole machine that I don’t touch for stuff like this to get my actual work done on. This one is for learning and fucking shit up. Lol

catloaf@lemm.ee on 04 Dec 17:54 next collapse

Or just RTFM first and learn without breaking stuff.

pearsaltchocolatebar@discuss.online on 04 Dec 18:12 next collapse

That’s not any fun

qprimed@lemmy.ml on 04 Dec 18:58 collapse

pretty much. learning things without a corresponding “oh… shit.” moment, just never quite stick with you the same way.

penquin@lemm.ee on 04 Dec 21:14 collapse

This is 100% it. The sleepless nights I’ve spent hunting for solutions after nuking everything, taught me a great deal. It was even so much fun, too.

naeap@sopuli.xyz on 04 Dec 19:22 next collapse

Nah, without breaking stuff, you never really learn

Hands-on experience is important.

Edit: obviously don’t do this with production machines, but I thought that was given…

Luci@lemmy.ca on 04 Dec 20:22 next collapse

No fun. Nothing learned.

thingsiplay@beehaw.org on 04 Dec 21:41 collapse

Pain is the best teacher.

penquin@lemm.ee on 04 Dec 21:12 next collapse

Nah, homie, fucking shit up then spending your whole evening looking for solutions is what makes it so much fun. lol

Luci@lemmy.ca on 04 Dec 22:31 collapse

If your googling is about to take you to the arch wiki, you’re having a good night!

luciferofastora@lemmy.zip on 05 Dec 06:24 collapse

tinkers with pulseaudio
“Why does my audio not work?”
tinkers more
“Okay I think it kinda works now?”
it breaks again
“fml”

I found the docs for pulseaudio and particularly for pipewire to be rather hard to use, personally. RTFM works if the manual is readable, but in these cases, the learning curve was very steep for me (and I still don’t know that I properly understood what’s going on, but it’s working, so I’ve stopped tinkering for now).

Luci@lemmy.ca on 05 Dec 14:02 collapse

You’re not really RTFM unless you’re digging into source code comments

pearsaltchocolatebar@discuss.online on 04 Dec 18:12 next collapse

You’re not going to cause any permanent damage to your system messing around with system settings.

penquin@lemm.ee on 04 Dec 21:11 next collapse

While I appreciate your comment, I disagree on the last part. Fucking shit up is what got me into IT to make a decent living and take care of my family. All the fucking shit up is at home on my personal PC of course 😂

extremeboredom@lemmy.world on 04 Dec 23:46 next collapse

Your comment was great, until the last part. That’s terrible advice. DO mess with things you don’t understand, until you understand them!

ReversalHatchery@beehaw.org on 05 Dec 01:30 collapse

3 GB swap usage is usually very unpleasant in my experience when the swap is on a HDD. and no thabks, I won’t move the swap to the SSD to kill it earlier

19 GB cache is worthless after you have just moved a lot of files, large in total size. very few useful things remain in there, while your program will get swapped out unnecessarily

TankieTanuki@hexbear.net on 04 Dec 17:28 next collapse

There is a common misconception that swappiness affects the memory threshold or prevents using swap space, but it only affects the preference for freeing up file pages over swap. See: this article for a more detailed explanation or the kernel source code where it is used.

wiki.archlinux.org/title/Swap#Swappiness

penquin@lemm.ee on 04 Dec 20:58 collapse

I love those links. Thank you.

mexicancartel@lemmy.dbzer0.com on 04 Dec 17:28 next collapse

It is probably normal. Don’t decrease your swappiness too much.

I think it happened the following way:

See the “cached” ram is taking 19 gigs. Theese cached ram improves performance by keeping frequently used system files on ram. So the actual occupied amount of ram would be 5+19 ≈ 25gb. Thoose system files might be used more than other app’s ram so that they have higher priority to be in ram. So at the time you opened certain other applications, the total ram usage including cached might be a little over the availiable ram and likely got swapped. The once swapped thing won’t be cleared immediately or with any much priority. I often see swapped contents remain even after closing a bunch of apps which gave empty space in ram.

So its just normal but is it using swap without once opening enough apps to fill the availiable space with used+cached? If so I would also be concerned

penquin@lemm.ee on 04 Dec 20:01 collapse

Damn. I actually didn’t even pay attention to the cached part, nor have I ever even known what it was for. Makes sense now. Thank you.

thingsiplay@beehaw.org on 04 Dec 17:43 next collapse

I also have a 32gb RAM (30.5 GiB) and a swappiness value of 10. My entire swap is full and my RAM is only filled up to about 3.8 GiB. However my swap is just 512mb small (its not a typo, it’s half a GB). You should not worry too much, even if the swap is in use, because those parts are probably like “parked” ram area that is not in use for a while now and waiting “to be waken up”. And the performance penalty is not that big, if the swap is on a fast NVME SSD. In old days on old slow spinning hard drives, the penalty for using swap was huge (plus the Kernel and rest of operating system was not fine tuned as today).

Some related commands to check:

grep -H swappiness /etc/sysctl.d/*.conf

swapon --show

free

cat /proc/meminfo

Here is an interesting article: chrisdown.name/2018/01/…/in-defence-of-swap.html

penquin@lemm.ee on 04 Dec 20:00 collapse

Thank you. I like those commands.

Frederic@beehaw.org on 04 Dec 17:46 next collapse

Strange, I also have 32GB of RAM, my swapiness is 15, and my swap is always at 0 bytes used…

kevincox@lemmy.ml on 04 Dec 19:16 next collapse

The use case will change everything. OP is likely using much more memory than you are (especially disk cache usage) so the kernel decided to swap out some data. Maybe you aren’t using as much so it has no need.

penquin@lemm.ee on 04 Dec 20:00 next collapse

I do have many things running and the CPU is working hard for sure. I didn’t even notice the cached part of RAM. So glad I just upgraded from 16 yesterday. Lol

Frederic@beehaw.org on 05 Dec 12:39 collapse

I mostly compile, it goes up to 20-24GB of RAM used, rest is cache, swap may get a few MB if I compile in debug, but that’s it…

secret300@lemmy.sdf.org on 04 Dec 22:55 collapse

I feel you. My swappiness is whatever is default in fedora and it’ll use like 20 gigs of RAM before anything goes into swap

sgtlion@hexbear.net on 04 Dec 17:53 next collapse

This is normal. This is a topic with a lot of complexities if you drill down into the details and history, but the tl;dr is certain system processes and other programs will preferably write data to swap because it’s so infrequently needed, and avoids massive slowdown if swap is needed, eg RAM filling, hibernation.

If you’re absolutely sure you’ll never exceed 32gb of RAM usage, you can turn the swap off. But you’re unlikely to notice a performance boost, Linux does (largely) know what it’s doing, moreso than you or I.

The TankieTanuki link is a good place to start to learn more if you really want to tweak it.

kevincox@lemmy.ml on 04 Dec 19:15 next collapse

To put it another way you want to be using all of your RAM and swap. It becomes a problem if you are frequently reading from Swap. (Writing isn’t usually as much of an issue as they may be proactive writes in case more memory needs to be filled up).

Basically a perfect OS would use RAM + Swap such that the least disk reads need to be issued. This can mean swapping out some idle anonymous memory so that the space can be used as disk cache for some hotter data.

In this screenshot the OS decided that it was better to swap out 3GiB of something to use that space for the disk cache (“Cached” ). It is likely right about this decision (but is not always).

3 GiB does seem a bit high. But if you have lots of processes running that are using memory but are mostly idle it could definitely happen. For example in my case I often have lots of Language Servers running in my IDE, but many of them are for projects that I am not actively looking at so they are just waiting for something to happen. These often take lots of memory and it may make sense to swap these out until they are used again.

penquin@lemm.ee on 04 Dec 19:58 collapse

I’ll leave it alone. Thank you so much. I just wanted clarification

sgtlion@hexbear.net on 05 Dec 08:41 collapse

For sure, and it’s a chill question. Unlike the other comment, I totally celebrate your fucking about with settings you don’t understand, it’s great. I’ve practically made a career of it myself :D

TimeSquirrel@kbin.melroy.org on 04 Dec 19:19 next collapse

Let it be. The people designing the OS most likely know better than you or anyone else in this thread. I know the urge to "tweak" things is strong, but some defaults are defaults for a good reason.

penquin@lemm.ee on 04 Dec 19:58 next collapse

Pssshhh. I taught Torvalds how to code, how dare you. 😂

WhyAUsername_1@lemmy.world on 05 Dec 03:24 collapse

So it was @penquin all along!

penquin@lemm.ee on 05 Dec 04:15 collapse

Shut up, private.

thingsiplay@beehaw.org on 04 Dec 21:39 collapse

Defaults are not always the best setting for a specific user or system. Defaults are often fail safe settings that should work on most systems out of the box. That does not mean other settings aren’t better on your system. Often you can tweak settings to get better results, that are best on YOUR machine and setup.

But only, if you know what you are doing, or if you want to learn about it.

Rogue@feddit.uk on 04 Dec 22:23 next collapse

But only, if you know what you are doing, or if you want to learn about it.

This is the crux of it though. Sure you can tweak your system but the average users doesn’t know what they are doing or where to learn more.

I’m not even convinced OP knows what problem they’re trying to solve

porous_grey_matter@lemmy.ml on 05 Dec 21:39 collapse

This reminds me of the (probably apocryphal) Mozart quote where a student asked him to teach them how to write a symphony, and was told “start with something more simple and short, for one instrument”. The student complained “but you have been writing symphonies since you were a child!”. The reply: “yes, but I didn’t have to ask how”.

The application of this idea here is that for someone to know the requirements for their system to the degree that they can really be sure that the most typical suggestions are not sufficient for them, they probably have to understand how the kernel handles swap and RAM to an extent that they don’t really need to ask this question.

People are very ready to assume that their system is way out of the ordinary, but it probably isn’t.

mactan@lemmy.ml on 04 Dec 19:30 next collapse

if you really feel the need to fuss with it then replace with swap on zram

pineapple@lemmy.ml on 04 Dec 22:13 next collapse

how do you change swappiness?

ReversalHatchery@beehaw.org on 05 Dec 01:26 next collapse

through a kernel parameter, or permanently through sysctl

penquin@lemm.ee on 05 Dec 02:03 collapse

sudo nano /etc/sysctl.d/99-swappiness.conf
then add this line inside
vm.swappiness=10
Change the 10 any number you want

RedWeasel@lemmy.world on 05 Dec 01:28 next collapse

You probably just had a program(s) use a lot of ram and that pushed some processes to swap. When the system needs it, it will be moved back. I’d +1 on setting up zram. Can be setup easily on most distros.

patatahooligan@lemmy.world on 05 Dec 14:33 next collapse

Yes, this is normal and it’s a good thing (unless you’ve come across a bug). I don’t know exactly what app the screenshot is showing, but I’m guessing that the caching shown is referring to the filesystem cache. The kernel is keeping a cache of files you are likely to access again so that it doesn’t have to read them from storage again. So what you’re seeing here is that some memory contents were moved to swap to make room for filesystem cache. This is because the kernel believes you’re more likely to access those files again rather than the memory contents. If it’s right, then this a performance improvement despite the fear surrounding swap usage.

Setting a low non-zero swappiness value is telling the kernel that memory contents have priority over filesystem cache for remaining in RAM, or conversely that file cache is more likely to be evicted from the RAM. A value of 100 would mean that they have equal priority. So that memory content must have been very stale to be evicted despite having a significantly higher priority to reside in RAM.

So:

  • don’t worry about swap usage unless you’re experiencing actual performance issues
  • for ssd’s the value should be close to 100
  • for hdd’s it should be low
  • if you’re using both on your system, the default value of 60 is probably a decent approximation of the optimal value

Source: chrisdown.name/2018/01/…/in-defence-of-swap.html

mvirts@lemmy.world on 05 Dec 15:31 next collapse

I’ve been trying to run a stable system with never overcommit and no swap . It’s impossible. this is the thing that may make me a kernel developer once I retire.

I’ve settled for tons of swap with never overcommit but I still can’t do normal things sometimes.

The downside to swap is wearing out your disk and latency when swapping, it’s good to have swap usage before ram is gone to let the system have more ram available for random allocations. My goal is to never need the oom killer, but it seems like many apps (chrome and FF mostly) basically require overcommit to function.

Right now my system has 30% ram used and is still keeping 700MB is swap. I would recommend to try benchmarking your settings but I don’t do that myself so I don’t know what to use 😅.

You can try disabling swap with swapoff, then your system is definitely maximizing your ram use, just be prepared for the oom killer to wreck your session.

merthyr1831@lemmy.ml on 05 Dec 16:14 next collapse

www.linuxatemyram.com

flashgnash@lemm.ee on 07 Dec 11:16 collapse

That looks a lot like task manager, what tool is that?

penquin@lemm.ee on 07 Dec 18:35 collapse

Mission center. It’s a gnome app. I used KDE plasma, but prefer this app over the plasma one.