1

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:

  1. The swap seems to be used for storing data that is regularly used, not hardly used.
  2. The entire PC seems very slow to respond to any command (e.g. opening the start menu, switching windows, starting a new terminal etc.)
  3. swap memory usage is 100% when I've got 28GB (twenty eight) of RAM left (4GB used)
  4. 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?

s5s
  • 111

1 Answers1

1

After you set swappiness to zero, you can try:

sudo swapoff -a && sudo swapon -a 

to transfer the swap space to memory without rebooting the computer.

stdexit
  • 11
  • I think this seems to have done something that helps. Will update in a bit. – s5s Dec 14 '21 at 10:40
  • sudo swapoff -a did it - made swap unavailable so whatever was using it stopped using it. – s5s Dec 14 '21 at 10:45