Why does Proxmox use swap when I have ~170 GiB of RAM available?

alpha754293

Member
Jan 8, 2023
94
18
8
Capture.PNG

Referring to the screenshot about - my dual Xeon server has 256 GB of DDR4-2400 ECC Reg. RAM installed.

I have about 10 VMs running right now, and it shows that it has about 170 GiB of RAM available.

I have set ZFS to only use upto 32 GiB of RAM for ZFS cache.

May I enquire as to why Proxmox will use swap when I have that much free RAM available, as reported by the system?

I am looking to learn and to be educated in regards to how and/or when Proxmox will decide to use swap, rather than RAM.

Thank you, in advance, for educating me as I'm still new to Proxmox.
 
Did you modify, when KSM will kick in? If not, I guess you had a total memory usage of at least 80% on some point before, because KSM kicks in at 80% per default and your "KSM sharing" shows a value greater than 0 (meaning it kicked in).
Set your graphs from "Hour" to "Day" or "Week" and check the memory usage.
Maybe at that point, your swap also started to be used.

As said, only a guess...
 
Did you modify, when KSM will kick in? If not, I guess you had a total memory usage of at least 80% on some point before, because KSM kicks in at 80% per default and your "KSM sharing" shows a value greater than 0 (meaning it kicked in).
Set your graphs from "Hour" to "Day" or "Week" and check the memory usage.
Maybe at that point, your swap also started to be used.

As said, only a guess...
If I am going to be honest -- I have no idea what KSM is.

I have yet to google that so that I can read up more about it.

Thus, per that -- unless there is some other default that is causing it to kick in sooner, I haven't touched the default setting, whatever that may be.

Here is what the memory graph looks like for the "Week (average)":

Capture.PNG


And here is what the memory graph looks like for "Week (maximum)":
Capture.PNG


You will see that there is a bit of a gap in the data, and that was because I might have accidentally turned off the system earlier this afternoon, for a couple of hours, and didn't realise it. (I was remotely monitoring and controlling the server with my laptop, and then had to quickly close my laptop to tend to my kids, so I might have clicked the "shutdown" button by accident when I was trying to log out.)


There was a moment, about two weeks ago though, where the maximum memory usage peaked at 191.59 GiB, but even then, that would still only be ~76% out of the 251.78 GiB that's available.

Plus, on top of that, I would have also figured that the reboot (I've rebooted the system a few times since then) -- I would've figured that the previous maximum shouldn't have had an impact where it would cause the swap usage to spike like that, when there's ample free RAM for the system and its VMs to use.

Your help is greatly appreciated.

Thank you.
 
I'll drop this link here: https://chrisdown.name/2018/01/02/in-defence-of-swap.html

If you have a lot of RAM you could also think about disabling it. On the running system with swapoff -a. To make it permanent, comment out the line for swap in the /etc/fstab file.

Thank you.

Yeah, I tried that and it might have been, at least potentially, partially responsible for why my Plex Media Server docker container, in my Ubuntu VM, died and/or threw an error later, such that I needed to reboot the Ubuntu VM at minimum, but I might have rebooted the host server, just as a precaution (cuz I don't know for sure, what cause the Plex Media Server docker container to throw an error). I can't say for certain, but I can't necessarily rule it out neither.

So here's a stupid question then -- instead of using my SSD boot disk for swap, can I create a slightly larger RAM drive and use that for swap?

(i.e. the system right now, looks like it defaulted to 8 GiB for swap. Can I create a 10 GiB RAM drive and use that as swap instead? And if so, how would I go about actually implementing something like that?)

Code:
# cat /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/pve/root / ext4 errors=remount-ro 0 1
UUID=83F0-A354 /boot/efi vfat defaults 0 1
/dev/pve/swap none swap sw 0 0
proc /proc proc defaults 0 0

Can I do something like:

Code:
# mkdir -p /tmp/swap
# mount -t tmpfs -o size=10G /tmp/swap
# mount -t swap -o size=8G /tmp/swap

(I'm pretty sure those commands are wrong. It doesn't look right to me, but I am not sure what the right commands are/would be.)

Your help is greatly appreciated.

Thank you.

There is some information about it in the Proxmox manual and on the Proxmox Wiki.
Thank you. Yeah, that would make sense then as I have a bunch of Windows VMs running.
 
Last edited:
Can I create a 10 GiB RAM drive and use that as swap instead?
Maybe but 10GB of RAM is much more useful than almost any amount of swap. If you are worried about the red line, then just set vm.swappiness to 0 to only swap when out of memory. I don't understand what possible problem more swap and therefore less memory will help solving instead of making worse. If Plex needs more memory, give it more memory instead of fake memory in the form of swap space.
 
Maybe but 10GB of RAM is much more useful than almost any amount of swap. If you are worried about the red line, then just set vm.swappiness to 0 to only swap when out of memory. I don't understand what possible problem more swap and therefore less memory will help solving instead of making worse. If Plex needs more memory, give it more memory instead of fake memory in the form of swap space.
The problem that I am observing in regards to this, is the interaction (and memory, thus swap management) between PVE vs. Linux VMs.

In the Proxmox web UI, for my Ubuntu VM that's hosting the Plex Media Server docker container, I gave it 32 GiB of RAM, and the web UI reports that 30.67 GiB of that is used (95.84%).

But if I log into the Ubuntu VM, according to top, it shows that out of the 31.358 GiB total RAM, only 1.135 GiB is used, and the rest is cached.

This is why the Proxmox web UI thinks that the Ubuntu VM is a "memory hog" because Linux uses available RAM as cache.

And that, in turn, causes Proxmox to think that it needs swap.

But if I run sudo docker stats, it shows that the Plex Media Server container, right now, is only using about 8.41 GiB out of a 31.36 GiB limit.

Thus, in neither case, is the Ubuntu VM nor the Plex Media Server docker container, remotely close to running out of RAM.

But Proxmox, because of how Proxmox (Debian 11) <--> Ubuntu (VM) interacts with each other -- makes Proxmox thinks that it needs swap.

find out first what is using the swap

https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/

here is a good walkthru
Thank you.

Yeah, I ran that as well.

Before I accidentally rebooted the system yesterday, where it was showing the high swap usage, using smem -akt, I was able to show that that VM was using about 3.4 GiB of swap.

Thank you.
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!