6

I am very new to Linux memory management. While reading some documents on the topic, I had some basic questions.

Below is my config:

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

My understanding is, if free memory falls below vm.min_free_kbytes, then the OS will reclaim memory.

  1. Is Memory reclaim a deletion of unwanted files 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 happen?

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

  4. What is the significance of vm.vfs_cache_pressure?

1 Answer 1

11
  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

2
  • Thank a lot for your answer, just one more question to get clarity if there is no swap partition, min_free_kbytes = 2G and the system Free memory is reached to 2GB is the data (Cache.buffer,..) will be deleted or the system will go to OOM condition? Feb 21, 2017 at 19:27
  • @MohamedAshraf the doc I linked is very succint, and says "Setting this too high will OOM your machine instantly". I think that the kernel will work as long as it can trash away data (practically, only the caches), and then will enter an infinite loop trying to reach the min_free_kbytes indicated, without succeeding. But I am not really sure. Feb 22, 2017 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.