You are not logged in.

#1 2025-07-06 16:15:35

xy1vro4
Member
Registered: 2025-07-06
Posts: 33

The system is Consuming the SWAP like it's No one Business

with vm.swappiness set to =1 it casualy eats eats it, while RAM is filled on less than 50%
I want to swap be used only in case of emergency, cuz my swap is based on ssd and i don't want to transfer it on hdd and i don't want to turn it off eather
what do i do wrong, does it looks like vm.swappiness does not work?
SNIMOK-EKRANA-OT-2025-07-06-18-43-29.png

and

SNIMOK-EKRANA-OT-2025-07-06-19-04-270eef81b133366f79.png

Offline

#2 2025-07-06 16:39:00

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,070

Re: The system is Consuming the SWAP like it's No one Business

vm.swappiness controls whether the system swap or drops file caches - it doesn't shift preferences between RAM and swap - that'd be insane and pointless.
Do you use zswap or a zram device as swap (or worse: both)?

One thing that might happen (since this is a static analysis of a specific moment in time), though is that you've some client genuinely eating lots of RAM, forcing the system to swap out, then the client terminates, the RAM frees again - but the memory that has been swapped out of course isn't read into RAM again until it's actually required.
=> you actually need to track RAM usage over time.

The file indexers are kinda prone to this behavior.

Offline

#3 2025-07-06 17:17:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: The system is Consuming the SWAP like it's No one Business

How often are you facing "emergencies" and in the case of such an emergency, is swapping really a benefit?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2025-07-06 17:21:52

xy1vro4
Member
Registered: 2025-07-06
Posts: 33

Re: The system is Consuming the SWAP like it's No one Business

seth wrote:

vm.swappiness controls whether the system swap or drops file caches - it doesn't shift preferences between RAM and swap - that'd be insane and pointless.
Do you use zswap or a zram device as swap (or worse: both)?

One thing that might happen (since this is a static analysis of a specific moment in time), though is that you've some client genuinely eating lots of RAM, forcing the system to swap out, then the client terminates, the RAM frees again - but the memory that has been swapped out of course isn't read into RAM again until it's actually required.
=> you actually need to track RAM usage over time.

The file indexers are kinda prone to this behavior.

Thank you for reply, yes looks like ZSWAP is Working and i don't sure about zram, but i think more likely no, Since it's not ON by defoult

is not ZSWAP our bro in that case, since he use system's calls to cache pages in swap and partly cache tham on Ram, so if i turn it off i will ended up with even more SWAP usage

i wonder if it's possible to ask ZSWAP to hold more pages in RAM insted of SWAP

Last edited by xy1vro4 (2025-07-06 17:42:40)

Offline

#5 2025-07-06 17:40:21

xy1vro4
Member
Registered: 2025-07-06
Posts: 33

Re: The system is Consuming the SWAP like it's No one Business

Trilby wrote:

How often are you facing "emergencies" and in the case of such an emergency, is swapping really a benefit?

Not very often, but not rare enough, like it shouldn't happen at all
Like once my system froze so much that it couldn't even kill some process to come back to life, I mean this
i want to system be able to recover it self from this situations, in that case i want to swap be used for
like it's not a problem to reastart few programs, but it's problem to restart fully

Last edited by xy1vro4 (2025-07-06 18:03:01)

Offline

#6 2025-07-06 18:04:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: The system is Consuming the SWAP like it's No one Business

xy1vro4 wrote:

Like once my system froze so much that it couldn't even kill some process to come back to life, I mean this

And in such a case, swap is *not* helpful - in fact it can make it take longer for such issues to sort out (i.e., if it is an "emergency" and the OOM killer will need to purge the problem, adding swap just makes this take longer but you get the same result).

EDIT: note I'm not weighing in here one way or the other on the value of swap - but rather I'm highlighting the incongruity between your stated goals and what you are doing.  Swap is not meant to be used just for emergencies, that's not what it's for.  If that's what you were looking for, you should just disable swap all together.  In contrast, if you want swap to be used to improve performance, you shouldn't be worried that swap is being used ... that's the goal.

Last edited by Trilby (2025-07-06 21:56:20)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2025-07-06 20:10:50

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,070

Re: The system is Consuming the SWAP like it's No one Business

https://wiki.archlinux.org/title/Improv … conditions
https://chrisdown.name/2018/01/02/in-de … -swap.html
Also, if you ended up with that swap pattern while vm.swappiness=1 you've been under memory and file cache pressure and would have otherwise lost processes for sure.
But in general Trilby is correct: if you're under so much pressure that the system starts thrashing and constantly is juggling swap and file cache, you're running OOM and the disk invocation slows that down.
See the above wiki link, but if that happens more frequently, you simply need more RAM (or close some browser tabs wink

You can configure the zswap behavior (and check whether it's active), https://wiki.archlinux.org/title/Zswap# … parameters but I doubt that's the problem here.
As mentioned you can end up w/ this pattern after intermittent memory pressure.
That aside, your "bro" can completely explode into your face when it decompresses into the swap, so it's not all glory - you can certainly still leave it enabled, but also nb. that it requires some physical swap as backend and that CAN NOT BE ZRAM, so maybe make sure that "swapon" lists some partition or swap file.

Offline

#8 2025-07-06 20:43:37

topcat01
Member
Registered: 2019-09-17
Posts: 282

Re: The system is Consuming the SWAP like it's No one Business

Some observations:

  1. I found that in case you encounter a RAM explosion, bumping vm.min_free_kbytes to double the default value makes a big difference. With the bumped value, my system is much more likely to recover (anecdotal).

  2. I use systemd-oomd and typically run all my programs from the command line using systemd-run or tmux panes (which have their own cgroup). When something blows up, oomd will kill only that process group. I use an aggressive setting for oomd described here.

  3. If you have enough RAM, using only zram as swap (instead of zswap) can give you the needed cushioning to recover, while not touching any disks. This is of course up to you. I get 2-4x memory compression, so it makes a big difference.

Offline

Board footer

Powered by FluxBB