Understanding MemAvailable and min_free_kbytes in Linux: Why free -m Shows Different Values and How to Adjust for OceanBase Installation
The article explains why the free command reports more memory than the available column, describes how the kernel calculates MemAvailable using min_free_kbytes and watermarks, and provides practical guidance on tuning min_free_kbytes to meet OceanBase's memory requirements.
Background : When installing OceanBase, the installer requires at least 8 GB of available memory. The author observed that free -m reported 9 GB free, yet the installation failed because the “available” value was only 6.3 GB.
Explanation of the discrepancy : The “available” column reflects MemAvailable , which is not simply the sum of free memory and buffers/cache; it is also influenced by the kernel parameter min_free_kbytes .
min_free_kbytes
The kernel uses a kswapd daemon to reclaim memory based on three watermarks: watermark[min] , watermark[low] , and watermark[high] . When MemFree falls below watermark[low] , kswapd starts reclaiming pages until watermark[high] is reached. If memory pressure continues below watermark[min] , the kernel performs direct reclaim, which can block applications. The size of watermark[min] equals the value of min_free_kbytes , while the other watermarks are calculated as:
watermark[low] = watermark[min] × 5/4
watermark[high] = watermark[min] × 3/2
MemAvailable
Memory below watermark[min] is reserved for the kernel and is excluded from MemAvailable . The kernel computes MemAvailable as:
MemAvailable = MemFree - watermark[LOW] + (PageCache - min(PageCache / 2, watermark[LOW]))
Checking the current setting:
[root@observer2 ~]# cat /proc/sys/vm/min_free_kbytes
2097152OceanBase requires min_free_kbytes of 2 GB. In a test environment the author reduced it to 64 MB, after which MemAvailable satisfied the installer’s requirement.
Recommendations for min_free_kbytes
The default calculation of min_free_kbytes is not linear; typical values range from 128 KB to 64 MB, and can be larger on systems with huge pages. Setting the parameter too low may cause the system to run out of usable memory and trigger costly direct reclaim, while setting it too high inflates all three watermarks, leading to frequent reclamation and lower overall memory utilization.
Therefore, reserving roughly 2 GB of memory for the kernel is a reasonable balance for OceanBase deployments.
References
Linux kernel commit
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.