前段时间在看/proc/meminfo,计算内核态内存,用户态内存,还有X内存。
在看这些的时候发现个问题就是 MemAvailable 竟然大于 Buffers + Cached + MemFree,因为在我印象里一直认为Available会少于buff + cache + free的。
文件:fs/proc/meminfo.c
于是扒代码分析:
for_each_zone(zone)
wmark_low += zone->watermark[WMARK_LOW];
/*
* Estimate the amount of memory available for userspace allocations,
* without causing swapping.
*
* Free memory cannot be taken below the low watermark, before the
* system starts swapping.
*/
available = i.freeram - wmark_low;
/*
* Not all the page cache can be freed, otherwise the system will
* start swapping. Assume at least half of the page cache, or the
* low watermark worth of cache, needs to stay.
*/
pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
pagecache -= min(pagecache / 2, wmark_low);
available += pagecache;
/*
* Part of the reclaimable swap consists of items that are in use,
* and cannot be freed. Cap this

本文深入探讨Linux系统中/proc/meminfo文件显示的MemAvailable参数计算原理,揭示其大于Buffers+Cached+MemFree的原因。通过分析内核代码,解释了内存分配策略,包括低水位值的作用、可分配内存的限制条件,以及页缓存和可回收slab内存的考虑。
最低0.47元/天 解锁文章
788





