Linux – Swap being used when RAM is almost half free

linuxmemoryswap

Today I noticed that I found the following thing:

enter image description here

As you can see the RAM is almost half-free and the usage of swap space is very high. From my textbook knowledge, I used to think that Linux OS tries to make best usage of RAM and when it gets short of RAM, it will move some of the least used pages from RAM to Swap space.

Can someone please explain me if my theoretical knowledge is incorrect and explain me how in the world of linux it actually works.

Best Answer

While it is true that kernel uses swap even if there may be memory left, using more than two thirds of it may be an indicator that historically the server may have been running out of memory and that is why it started swapping. I would correlate swap usage with memory usage in the sar reports to deduce whether the system has enough ram. I would also check dmesg or the logs to determine if the server has in fact ran out of memory, and the oom-killer kicked in.