Swap almost full

LukeZX

Member
Feb 9, 2021
8
0
6
41
Hello,
The available swap space on one of the servers is almost all in use (7GB used out of 8GB), even though it has plenty of memory available (50GB used out of 188GB).
I would like help with two questions:
1 - How can I reduce the use of swap, even having several containers using swap?
2 - What would be the procedure to decrease the size of lvm-thin (362GB available) and add this space in swap?
For example... decrease lvm-thin to 200GB and use the 162GB available + the 8GB already used as swap, leaving a total of 170GB of swap.

Code:
# pvs
  PV         VG  Fmt  Attr PSize    PFree
  /dev/sda3  pve lvm2 a--  <464.23g 15.99g

# vgs
  VG  #PV #LV #SN Attr   VSize    VFree
  pve   1   3   0 wz--n- <464.23g 15.99g

# lvs -a
  LV              VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data            pve twi-a-tz-- 337.34g             0.00   0.50
  [data_tdata]    pve Twi-ao---- 337.34g
  [data_tmeta]    pve ewi-ao----  <3.45g
  [lvol0_pmspare] pve ewi-------  <3.45g
  root            pve -wi-ao----  96.00g
  swap            pve -wi-ao----   8.00g

# lsblk
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0                7:0    0    15G  0 loop
loop1                7:1    0    20G  0 loop
loop2                7:2    0     8G  0 loop
loop3                7:3    0    20G  0 loop
loop4                7:4    0    20G  0 loop
loop5                7:5    0    16G  0 loop
loop6                7:6    0    40G  0 loop
loop7                7:7    0    20G  0 loop
loop8                7:8    0    20G  0 loop
loop9                7:9    0    20G  0 loop
loop10               7:10   0    30G  0 loop
loop11               7:11   0   100G  0 loop
loop12               7:12   0    50G  0 loop
loop13               7:13   0    20G  0 loop
loop14               7:14   0    12G  0 loop
loop15               7:15   0    10G  0 loop
loop17               7:17   0    20G  0 loop
loop19               7:19   0    10G  0 loop
loop20               7:20   0    10G  0 loop
sda                  8:0    0 464.7G  0 disk
├─sda1               8:1    0  1007K  0 part
├─sda2               8:2    0   512M  0 part
└─sda3               8:3    0 464.2G  0 part
  ├─pve-swap       253:0    0     8G  0 lvm  [SWAP]
  ├─pve-root       253:1    0    96G  0 lvm  /
  ├─pve-data_tmeta 253:2    0   3.5G  0 lvm
  │ └─pve-data     253:4    0 337.4G  0 lvm
  └─pve-data_tdata 253:3    0 337.4G  0 lvm
    └─pve-data     253:4    0 337.4G  0 lvm
sr0                 11:0    1  1024M  0 rom

Thanks!
 
2 - What would be the procedure to decrease the size of lvm-thin (362GB available) and add this space in swap?
For example... decrease lvm-thin to 200GB and use the 162GB available + the 8GB already used as swap, leaving a total of 170GB of swap.
As far as I know you can't shrink a LVM-Thin pool. you will have to backup your guests, destroy that thin pool, recreate it with less space and restore your guests.

1 - How can I reduce the use of swap, even having several containers using swap?
You can edit the swappiness in /etc/sysctl.conf. The smaller the swappiness, the less it will try to swap out RAM. With "vm.swappiness=0" it won't use the swap, unless you are really running out of RAM to prevent OOM conditions.
 
Last edited:
It should also be pointed out that swap use by itself is not necessarily a problem. Only if there is a performance impact should you do anything about it. Having a bunch of unused stuff sit in swap may actually be preferable to having it in memory.
 
  • Like
Reactions: leesteken
As far as I know you can't shrink a LVM-Thin pool. you will have to backup your guests, destroy that thin pool, recreate it with less space and restore your guests.
As for deleting the thin pool, there is no problem because the VMs are on another server. I would like to know the correct procedure/commands to do this. Both the thin pool and the swap part.

You can edit the swappiness in /etc/sysctl.conf. The smaller the swappiness, the less it will try to swap out RAM. With "vm.swappiness=0" it won't use the swap, unless you are really running out of RAM to prevent OOM conditions.
I put the "vm.swapiness=20", but it doesn't seem to have any effect.
 
It should also be pointed out that swap use by itself is not necessarily a problem. Only if there is a performance impact should you do anything about it. Having a bunch of unused stuff sit in swap may actually be preferable to having it in memory.
Yes, I was reading about that. My fear is running out of available swap on the server, and starting to crash the VMs and the server.
 
Yes, I was reading about that. My fear is running out of available swap on the server, and starting to crash the VMs and the server.
Why do you think that would happen when you have a lot of free memory? Running out of available swap by itself is not a real problem. What is a problem is constantly having to move things in and out of swap due to a lack of memory. If you're not in that situation maybe find other things to worry about.
 
I put the "vm.swapiness=20", but it doesn't seem to have any effect.
Did you reboot fter changing this?

As for deleting the thin pool, there is no problem because the VMs are on another server. I would like to know the correct procedure/commands to do this. Both the thin pool and the swap part.
Something like this:

Destroy Thin pool:
lvremove /dev/pve/data

Create 100G Thin pool:
lvcreate -L 100G --thinpool data pve

But I would backup the disk with clonezilla first so you can restore the whle disks in case something goes wrong.
 
Did you reboot fter changing this?
I ran the command "sysctl -w vm.swappiness=20", but I didn't reboot it. Even with this command, do I need to restart the server?

Something like this:

Destroy Thin pool:
lvremove /dev/pve/data

Create 100G Thin pool:
lvcreate -L 100G --thinpool data pve

But I would backup the disk with clonezilla first so you can restore the whle disks in case something goes wrong.
I will try the commands on a test server. Thanks!
 
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!