System swap exaggerated.

frankz

Active Member
Nov 16, 2020
364
24
38
Hi everyone, in the cluster I have a way that uses an exaggerated swap although the available memory is enough. I have checked with various tools such as htop etc but everything seems fine.
swap.png
 
  • Like
Reactions: cdarsac
Hi,
Linux doesn't only use swap when the RAM is full, see here for a short how and why.
 
  • Like
Reactions: cdarsac
Hi,
Linux doesn't only use swap when the RAM is full, see here for a short how and why.
Thanks Fabian, I knew linux doesn't use swap memory only when the total memory is full. Maybe I was wrong to set the question, that is I was wondering how mail is the only node of the three that uses this swap, since the others are configured like this. Thanks comunqiue for your reply
 
Maybe simply because of differences in the workload on the nodes (even if they are relatively similar I wouldn't exclude the possibility). Is the cat /proc/sys/vm/swappiness value the same on all nodes?
 
Maybe simply because of differences in the workload on the nodes (even if they are relatively similar I wouldn't exclude the possibility). Is the cat /proc/sys/vm/swappiness value the same on all nodes?
Yes the value is equal or 60.
 
However, I still have a swap almost in saturation on one node only, to test I spsotato an lxc that has set a swap of 2 GB. Is it possible that this is generated by a lxc? I attach image.
 

Attachments

  • Schermata 2021-06-07 alle 06.38.26.png
    Schermata 2021-06-07 alle 06.38.26.png
    49.3 KB · Views: 9
Thank you for asking the question, because I have exactly the same behavior. :)
Hi I wanted to confirm that suspending the LXC machine in another node the problem is the same. Furthermore, Zabbix, which I use to monitor the nodes as well, signals me a low-space alert, due to the swap consumption. I think this needs to be reviewed for good, as the backup of the LXC VM also fails.
 
Not sure if this is the case here, but: when one Linux system does more I/O than another Linux system, it more often makes a choice between not using additional memory for cache and swapping out memory than has not been used for some time. Swap is only reduced when the memory on disk is actually requested by software and moved back into RAM. Therefore, swap keeps growing when the swapped-out memory is not actively used. Maybe that's the difference between your two systems.

If a system is constantly reading from swap (and writing other parts of memory to swap), I would consider it a problem because the additional disk I/O when using memory will slow down the system a lot. However, if swap is filled up over time and almost never ever read/reduced, I would not call this a problem. Apparently some software allocated memory that is hardly ever actually used and it is a good thing that it is not taking up high-speed RAM.

As I said, I'm not sure this it the case for your particular setup, but a monitor that complains about swap being full, while there is no actual (heavy) swap I/O going on, does not understand how Linux uses swap. [EDIT: Some typos an a bit of clarification.]
 
Last edited:
Not sure if this is the case here, but: when one Linux system does more I/O than another Linux system, it more often makes a choice between not using additional memory for cache and swapping out memory than has not been used for some time. Swap is only reduced when the memory on disk is actually requested by software and moved back into RAM. Therefore, swap keeps growing when the swapped-out memory is not actively used. Maybe that's the difference between your two systems.

If a system is constantly reading from swap (and writing other parts of memory to swap), I would consider it a problem because the additional disk I/O when using memory will slow down the system a lot. However, if swap is filled up over time and almost never ever read/reduced, I would not call this a problem. Apparently some software allocated memory that is hardly ever actually used and it is a good thing that it is not taking up high-speed RAM.

As I said, I'm not sure this it the case for your particular setup, but a monitor that complains about swap being full, while there is no actual (heavy) swap I/O going on, does not understand how Linux uses swap. [EDIT: Some typos an a bit of clarification.]
First of all thanks for posting. Considering what was written above, I purposely wanted to move the VM (LXC) to another node and the swap of the nod increases in volume. Technically I assume from the parameters of the VM that the swap declared in the properties is not virtualized but shared with the node, so if it were, it is clear that the node itself is involved in the available space. assuming you have several lxcs that make use of a minimum of 1024 Gb of memory and 2048 Gb of swap, the node would be saturated. Not true for all VM machines, but I use zoneminder in LXC and it eats up a lot of memory .... other lxc like centos 8, ubuntu 21 or other are moderate.
Schermata 2021-07-03 alle 22.05.43.png
 
All containers share the same swap space with each other and the Proxmox host. Just as they all share the same physical memory. Please note that setting Memory (MiB) to M and Swap (MiB) to S for a container limits the use of the swap space to (S+M) MiB. Of course, it can be less if the swap has less space available (because of the shared nature). This also means that setting the Swap (MiB) to 0 can still result in the use of swap space because the limit is then M MiB. In your case, CT110 can use up to 3.50 GiB of swap space and also 1.50 GiB of actual memory.

To clearly answer you original questions in post #1: Writing and filing the shared swap space is usually a good thing. That's probably why you see a lot of swap usage but everything seems fine. It's reading memory back from swap space (all the time while also writing) that tends to cause slow downs, as I tried to explain in post #12.
 
  • Like
Reactions: frankz

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!