4

Linux 3.14: 终于能方便地看到真正的系统可用内存了

 2 years ago
source link: https://blog.lilydjwg.me/2014/4/14/linux-3-14-memavailable-in-meminfo.44814.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux 3.14: 终于能方便地看到真正的系统可用内存了

本文来自依云's Blog,转载请注明。

直接取/proc/meminfo中的「MemAvailable」项即可:

awk '$1 == "MemAvailable:" { print $2 * 1024 }' /proc/meminfo | filesize

filesize 是我自己写的将字节数转成人可读形式的脚本。

使用free命令的版本:

free | awk 'NR == 3 { print $4 * 1024 }' | filesize

并不准确,因为已缓存(Cached)内存并不一定是可以释放的,比如我用的 tmpfs 里的数据也算进去了。详见内核的这个提交。「free命令的算法在十年前还不错」,这不就是我大学课程教授的知识所处的时代么? :-D

发送到 Kindle


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK