Why linux has enough memory but swap is used

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

Before the problem is the use of memory, for example,

memory before

but after a long time, caching becomes clear, and the system starts using swap. memory later

I now have two questions.

  • Why does the system release caching? This makes the IO system higher than before.

  • Why the system still has enough memory, but swap is still in use.

Below is the top information: top

Update : this problem will come again.
enter image description here Since I sudo swapoff -a so the system does not use swap, the system works well.
Now the problem is why the system release page is cached ..?
And what is the situation when the system releases a cache page?

Update : I fixed this problem.
I got a response from Understanding Linux Kernel
The book says that if there is enough free memory, the page is stored in the cache for an indefinite period of time and then can be reused by other processes without access to the disk.

I think this means that the system will issue a cache if the cache page remains in the system for a long time.

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

thanks

Update

  • Is the reason linux replaces memory with swap space, even if the system has enough memory?

if we swap memory when a process detects that there is not enough memory, then it will take a long time for the process to get enough memory. It will have to cause page page recovery.

  1. the reason we set vm.swappiness = 0 will still be a swap.

There is a global_reaction in the backend. who do not check the value of swappiness

+6
source share
6 answers

Look at the running processes (for example: mysql, java, etc.)

If you set the memory limit too low for these processes, and sometimes they need more, the lost memory will not be deleted in the buffers, but during the exchange.

I think this may explain your problem.

+1
source

this is not a problem (swap)

when Linux is running, it has “put off” some of its running services in the swap section.

but if you start using these services, they will be returned to RAM.

0
source

You need to remember that reading from swap is slightly faster than reading from disk.

Assuming keeping things in a swap is good (doesn't mean your memory is full).

So, let's say you have 4 GB of memory, and you have 2 GB of free memory. Then you download application A, which is 2 GB, and you will have 4 GB full-time memory. Then you close app X and download app Y (1Gb). This means that half of the application X will be moved to swap, and the main memory will now contain Y and some "cache" for half X.

In this case, you will have the following scenario:

  • 4 GB of full memory
  • 2 Gb occupied by the system
  • 1 GB for application Y
  • 1 GB cache for X

Exchange * 1 Gb for X (which were removed to download application Y)

0
source

You can adjust the "swappiness" level to increase or decrease the dependence of the kernel on the swap space.

0
source

i.e. debian swaps rarely used data. I believe that this behavior is seen as optimization. This question directly corresponds to this one . You can set the swappiness coefficient:

 sudo sysctl vm.swappiness=10 
0
source
 echo 0 > /proc/sys/vm/swappiness 

Will make an exchange system only in case of emergency.

0
source

Source: https://habr.com/ru/post/974070/


All Articles