Swap usage when plenty free memory

Hello, I got bare metal Rocky Linux 8 server that has 1 TB RAM.
This server running as Postgresql Master node.
Although 1 tb ram, many process using swap space especially postgres processes.
When I check free memory it has almost x3 of swap space. I moved pages from swap to memory but after little time it occured again.
How to check why it insist on using swap?

os-release
NAME=“Rocky Linux”
VERSION=“8.7 (Green Obsidian)”
ID=“rocky”
ID_LIKE=“rhel centos fedora”
VERSION_ID=“8.7”
PLATFORM_ID=“platform:el8”
PRETTY_NAME=“Rocky Linux 8.7 (Green Obsidian)”
ANSI_COLOR=“0;32”
LOGO=“fedora-logo-icon”
CPE_NAME=“cpe:/o:rocky:rocky:8:GA”
HOME_URL=“https://rockylinux.org/
BUG_REPORT_URL=“https://bugs.rockylinux.org/
ROCKY_SUPPORT_PRODUCT=“Rocky-Linux-8”
ROCKY_SUPPORT_PRODUCT_VERSION=“8.7”
REDHAT_SUPPORT_PRODUCT=“Rocky Linux”
REDHAT_SUPPORT_PRODUCT_VERSION=“8.7”

kernel version
6.1.10-1.el8.elrepo.x86_64

swappiness
vm.swappiness = 0
vm.overcommit_memory = 2
vm.overcommit_ratio = 80

free -mh
total used free shared buff/cache available
Mem: 1.0Ti 291Gi 7.7Gi 832Mi 708Gi 709Gi
Swap: 4.0Gi 823Mi 3.2Gi

Does the Rocky kernel do the same, i.e. is this “feature” in all kernels or only in that upstream version?

What if you remove swap completely? Running out of RAM does not seem an immediate threat.
That is, are some processes adamant to explicitly use swap regardless of status of RAM?

I didn’t try it boot on default kernel version (kernel-4.18.0-425.3.1.el8.x86_64)
It is prod server.
Yes I should try in appropriate time.

That is, are some processes adamant to explicitly use swap regardless of status of RAM?
I dont think so because it is typical postgres process and just in this server using swap, I got many
postgres servers that swap is totally free

Try activating cgroups v2, see Premature swapping with swappiness=0 while there is still plenty of pagecache to be reclaimed - Red Hat Customer Portal.

1 Like