Memory on a 2 GB VPS
Read the right column
In the output of free -m the free column is
almost always small, and that is fine: the kernel uses spare memory for the
page cache. The number that matters is available, an estimate of
how much can be handed to programs without swapping.
Who is using it
ps -eo rss,comm --sort=-rss | head
If something was killed for lack of memory, the kernel says so:
journalctl -k | grep -i 'out of memory'
A small swap file
Swap will not make a small machine fast, but it gives the kernel somewhere to put memory that was touched once at startup and never again:
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
Swappiness
The default of 60 lets the kernel swap out idle programs rather eagerly. On a server where the working set fits in RAM, a lower value keeps them resident:
echo 'vm.swappiness=10' > /etc/sysctl.d/60-swappiness.conf
sysctl --system