I wanted to have an opinion from anybody about my production server swapiness and physical ram sharing into services.
This server configuration has OS 22.04 ubuntu with 128GB RAM. It is a dedicated server not a vps. It hosts a php application and run the following services:
- Nginx 1.26.2
- Varnish 7.5 run in socket
- Redis 7.4.1 run in socket
- PHP8.3 FPM
- Rabbitmq 3.13.7
- ElasticSearch 8.11.4
- Percona mysql 8.0.39-30
- Hitch 1.8
All above services have of course custom configurations which included the amount of memory should be used. For this server I have configure a swap file of 64GB. Of course I have given no priority to system to use this SWAP
NAME TYPE SIZE USED PRIO
/swapfile file 64G 2.8G -2
/dev/md0 partition 4G 0B -3
cat /proc/sys/vm/swappiness
10
and
/etc/sysctl.conf
vm.swappiness=10
vm.vfs_cache_pressure=90
vm.overcommit_memory = 1
RAM free -m
total used free shared buff/cache available
Mem: 128731 46517 7285 953 74928 79952
Swap: 69626 2882 66744
You will notice that I have around 2.8GB of swap used. As far as I know OS to use SWAP must have full RAM.
With this bash script:
for file in /proc/*/status; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
I see that nginx, php8.3, Elasticsearch, redis and hitch use SWAP
Also I see in RAM that there is around 7GB free. Also I see that buff/cache uses 75GB of RAM. Here come the questions:
- How I can prevent OS to use SWAP?
- Can someone explain what is buff/cache? Is this reserve RAM. Is this related with Varnish? How I control this section of RAM?