What is the "min_free_kbytes" parameter
Environment
- Red Hat Enterprise Linux
Issue
- What is
min_free_kbytesparameter? - How does
min_free_kbytesparameter impacts a server memory utilization? - How does
min_free_kbytesparameter and Swap space relate with each other with regards to memory pressure and memory reclamation?
Resolution
The vm.min_free_kbytes sysctl parameter determines the lowmem free minimum threshold value. It is the minimum amount of RAM that will be kept free and only the most critical kernel operations are allowed to allocate under this threshold. In other words, if your machine runs out of available memory, this parameter ensures that there's always at least some memory for the most critical operations.
Naturally, the default value of this parameter is calculated based on the total amount of memory present on the system, as well as other factors. For details you can inspect the calculation in mm/page_alloc.c source code file of the kernel version of your interest, for example in our This content is not included.Red Hat Code Browser.
Note: there may be also other factors adjusting the value, for example if you use huge pages - you can also check mm/huge_memory.c
Based on "min_free_kbytes" parameter, the values of "watermarks" for all the memory zones are calculated.
For example :
]$ cat /proc/zoneinfo | grep -A 4 Normal
Node 0, zone Normal
pages free 182388
min 16079 // pages_min watermark
low 23799 // pages_low watermark
high 31519 // pages_high watermark
These values depend on "min_free_kbytes" parameter.
The zone watermarks are used by kernel memory-management algorithms to determine the need for reclaim (but not limited to).
For example, if a memory allocation would leave the zone with less than page_low pages, then the algorithm performs additional routines (a so called slow_path) to check whether immediate compaction and/or reclamation is needed. Additional effect of this is waking up the kswapd kernel process for the adequate memory node, which (simply said) performs the same checks/routines in parallel until it ensures that free pages are again over page_high.
Please note that the details of page allocation and kswapd are quite more complicated and also subject to adjustments over time (different kernel versions). Hence they should be best inspected and understood by reading the actual source code of the adequate kernel version.
Appendix: Swap
The relation of this to swap space utilization is that "swapping" is decided as part of memory reclaim routines.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.