I am experiencing an issue where linux seems to be using swap instead of RAM. To me it looks like I've triggered a bug because:
- The swap seems to be used for storing data that is regularly used,
not hardly used.
- The entire PC seems very slow to respond to any
command (e.g. opening the start menu, switching windows, starting a
new terminal etc.)
- swap memory usage is 100% when I've got 28GB (twenty eight) of RAM left (4GB used)
- The swap is used for applications that I just launched (e.g. chrome, R-studio) because it goes up when I launch these apps and is freed when I close them.
Is there a way to force linux to stop using swap for new memory allocation? I've set the swappiness to 0.
EDIT:
Before I asked the question, I changed swappiness via sudo sysctl vm.swappiness=0
and I've made the change permanent in /etc/sysctl.conf
. This didn't make a difference. I haven't rebooted my PC because I've got jobs running but up time is just 3 days.
$ cat /proc/sys/vm/swappiness
0
$ uptime
09:08:54 up 3 days, 6 min, 1 user, load average: 1.90, 2.23, 2.45
$ uname -a
5.4.0-72-generic #80~18.04.1-Ubuntu SMP Mon Apr 12 23:26:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ free -m
total used free shared buff/cache available
Mem: 32022 1891 229 610 29901 29069
Swap: 2047 988 1059
EDIT2: I am running a SQL script against postgresql DB. The script is very long but made up of just a number of \copy(select ...)
statements which dump data to csvs. I would imagine it's not psql that is hammering the swap but the kernel which decides which memory to use?