简体   繁体   中英

What is memory reclaim in linux

I am very new to Linux memory management concept while reading some memory management related document I had some basic doubt please clarify me.

considering below is my config

vm.swappiness=10
vm.vfs_cache_pressure=140
vm.min_free_kbytes=2013265 

My understanding if free memory is gone less than vm.min_free_kbytes OS will reclaim the memory.

1- Is Memory reclaim is a deletion of unwanted file or copying to Swap memory from RAM?

2- If it's copying to Swap memory from RAM, then if I am not using SWAP memory what will be happened?

3- Is swappiness is always greater than the vm.min_free_kbytes?

4-What the significants of vm.vfs_cache_pressure ?

Thank You..!!

  1. Memory reclaim is the mechanism of creating more free RAM pages, by throwing somewhere else the data residing in them. It has nothing to do with files. When more RAM is needed, data is dropped from RAM (trashed away, if it can be refetched) or copied to the swap file (so the data will be refetchable).

  2. If there is not a swap file, but some data should be saved to the (non existent) swap area, then an out-of-memory error happens. Typically, this is notified to the process which is trying to get the memory (via alloc() and similar) - the alloc() fails and returns NULL. The process can choose what to do, or even crash. If the memory is needed by the kernel itself (normally quite rare), a PANIC happens and the system locks completely.

  3. swappiness is, in percentage, the tendency of the kernel to use the swap, even if not strictly needed, in order to have plenty of ram ready for memory requests. Simply put, a 100% swappiness means the kernel tries to always swap, a swappiness of 0 means the kernel tries to not do swap (there are some special values however). min_free_kbytes indicates real kilobytes, it is not a percentage, and it is the minimum amount that should always be free in order to let the kernel to work well. Even starting a memory reclaim could require some more ram to do the job: it would be catastrophic if, to get some memory, you need just a little memory but you don't have it! :-)

  4. vfs_cache_pressure is again a percentage. It indicates how much the kernel tries to get rid of (memory) cache used for the file system (vfs=virtual file system). The cache for the filesystem is quite a good candidate to throw away, because it keeps information easily readable from the disk. Unfortunately, if the computer needs frequently to use the file system, it has to read, and read again, and read again always the same data. Caching is a big performance boost. Of course, if a system does little disk I/O, then this cache is the best candidate to throw away when memory hungry.

All this things are succintly explained here: https://www.kernel.org/doc/Documentation/sysctl/vm.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM