Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why linux has enough memory but swap is used

I have a server run an erlang application, something like riak..

Before the problem, the memory usage like this

memory before

but after a long time, the cached is clear and system begin use swap. memory later

now I have two question..

  1. Why the system release the cached? This cause the problem that the system's IO is higher than before

  2. Why the system still has enough memory, but swap is still used..

Below is the top information: top

Update: this problem come again..
enter image description here Since I have run command sudo swapoff -a so the system don't use swap, the system runs well.
Now the problem is why system release page cached..?
And what the situation is that the system will release pgae cache?

Update: I have fixed this problem..
I got answer from the book Understanding Linux Kernel
The book say that if there is enough free memory, the page is kept in the cache for an indefinite period of time and can then be reused by other processes without accessing the disk.

I think this means that the system will release the cache if the page cache has stay in the system for a long time.

After I read the linux source, I will update it. Why the system will release page cached even it has enough memory?

Thanks

update

  1. the reason why linux swap the memory to swap area even the system have enough memory?

if we swap the memory when a process find there is not enough memory, then it will need a long time for the process to get enough memory. It will need to call page frame reclaim.

  1. the reason why we set vm.swappiness=0, there will still have swap.

There is a global_reclaim in the backend. which don't check the swappiness value

like image 317
baotiao Avatar asked Aug 20 '14 07:08

baotiao


2 Answers

Have a look to your processes running (ex: mysql, java etc...)

If you set a memory limit too low for theses processes and sometimes they need more, the memory missing is not taken onto the buffers but on swap.

I think this could explain your problem.

like image 74
Bertrand Cebador Avatar answered Sep 29 '22 17:09

Bertrand Cebador


i.e. debian is swapping really seldom used data. I think this behavior is considered as an optimization. This question directly corresponds to this one. You can set the swappiness factor:

sudo sysctl vm.swappiness=10
like image 37
PlagTag Avatar answered Sep 29 '22 18:09

PlagTag